Last active
November 14, 2016 06:03
-
-
Save bryantrobbins/b9aaeb1c6feef42b08e0 to your computer and use it in GitHub Desktop.
Running a packer build which pushes an nginx-based image of a static website AWS ECR
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -v | |
# Add your app build steps here | |
# Assume that these steps produce a "dist" folder at this level | |
# Prepare packer variables | |
repoName=$1 | |
imageVersion=$2 | |
chmod 700 fetch.sh | |
./fetch.sh $repoName $imageVersion > variables.json | |
# Build docker image with packer | |
packer="/usr/local/bin/packer" | |
$packer build -var-file=variables.json frontend.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Get login details | |
login=`aws ecr --region us-east-1 get-login` | |
# Set variables | |
repoName=$1 | |
imageVersion=$2 | |
set $login | |
repoPrefix=$9 | |
repoPrefix=${repoPrefix:8} | |
# Write values to stdout | |
echo "{" | |
echo " \"image_version\": \"$imageVersion\"," | |
echo " \"aws_ecs_password\": \"$6\"," | |
echo " \"aws_ecs_server\": \"$9\"," | |
echo " \"aws_ecs_repo\": \"$repoPrefix/$repoName\"" | |
echo "}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"variables": { | |
"aws_ecs_repo": "", | |
"aws_ecs_password": "", | |
"aws_ecs_server": "", | |
"image_version": "" | |
}, | |
"builders": [ | |
{ | |
"type": "docker", | |
"image": "nginx", | |
"commit": "true" | |
} | |
], | |
"provisioners": [ | |
{ | |
"type": "file", | |
"source": "dist/", | |
"destination": "/usr/share/nginx/html" | |
} | |
], | |
"post-processors": [ | |
[ | |
{ | |
"type": "docker-tag", | |
"repository": "{{user `aws_ecs_repo`}}", | |
"tag": "{{user `image_version`}}", | |
"force": true | |
}, | |
{ | |
"type": "docker-push", | |
"login": true, | |
"login_email": "none", | |
"login_username": "AWS", | |
"login_password": "{{user `aws_ecs_password`}}", | |
"login_server": "{{user `aws_ecs_server`}}" | |
} | |
] | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment