Skip to content

Instantly share code, notes, and snippets.

@ashokfernandez
Created March 10, 2015 11:52
Show Gist options
  • Save ashokfernandez/c3e0edc728520834e5e1 to your computer and use it in GitHub Desktop.
Save ashokfernandez/c3e0edc728520834e5e1 to your computer and use it in GitHub Desktop.
Build and tag docker repo for deployment
#!/bin/bash
# Builds and pushed docker image of a git repo, tagging the git repo and docker image with the
# same tag. Make sure you are logged into docker and that boot2docker is running if you're on
# OSX or Windows
# Check that a version tag was given
if [ $# -eq 0 ]
then
echo "No version tag supplied, please enter a version tag as the first parameter of this script"
exit 1
fi
# Save the git repo as it is and tag it with the version number
echo "***** COMMITING TO GIT REPO"
git add .
git commit -m "Production Version $1"
echo "***** TAGGING LATEST COMMIT AS $1"
git tag $1
# Build and push to docker hub
echo "***** BUILDING DOCKER IMAGE (with tag $1)"
docker build -t <docker_username>/<docker_repo_name>:$1 .
echo "***** PUSHING DOCKER IMAGE"
docker push <docker_username>/<docker_repo_name>
@ashokfernandez
Copy link
Author

Run this script with a version tag e.g ./deploy.sh v0.1.3

Make sure you change <docker_username> to your docker username and <docker_repo_name> to the name of your repo on docker.

This is particularly useful for deploying docker images to Elastic Beanstalk on AWS. After running this script with your version tag, add the version tag to your Dockerrun.aws.json file like so

"AWSEBDockerrunVersion": "1",
 "Image": {
     "Name" : "<docker_username>/<docker_repo_name>:<version_tag>",
     "Update" : "true"
 }

Upload this to the Elastic Beanstalk console and and type in the same version tag, then all your Elastic Beanstalk versions will be tied to the docker images and git commits with the same version tag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment