Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
# Version tag needs to be dependent on all the files that will affect
# the generated image. Currently, only the dockerfile and Python
# requirements.
VERSION_TAG="$( sha1sum Dockerfile requirements/*.txt | sha1sum | cut -d' ' -f1 )"
echo "Image version: ${VERSION_TAG}"
echo "Commit SHA1: ${CIRCLE_SHA1}"
echo "Image name: ${IMAGE_FULL_NAME}"
# Cache dir must match the one configured in circle.yml
CACHE_DIR="$( readlink -f ~/docker-images )"
echo "=====> Locating image archive: ${IMAGE_ARCHIVE}"
mkdir -p "$CACHE_DIR"
# If we already have an image built on the same dependencies, just
# re-use it.
if [[ -e "$IMAGE_ARCHIVE" ]]; then
echo "-----> Loading existing image archive"
docker load -i "$IMAGE_ARCHIVE"
echo "=====> Building image: ${IMAGE_FULL_NAME}"
docker build -t "$IMAGE_FULL_NAME" .
# Tag the image as being the correct one for this commit.
# This is used in circle.yml to pick the correct image.
echo "=====> Tagging image with commit SHA1: ${CIRCLE_SHA1}"
docker tag "$IMAGE_FULL_NAME" myorg/myapp:"$CIRCLE_SHA1"
# Save to cache for later reuse
echo "=====> Saving image to cache: ${IMAGE_ARCHIVE}"
echo "=====> All done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment