Skip to content

Instantly share code, notes, and snippets.

@bryantrobbins
Last active November 14, 2016 06:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bryantrobbins/b9aaeb1c6feef42b08e0 to your computer and use it in GitHub Desktop.
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
#!/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
#!/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 "}"
{
"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