Skip to content

Instantly share code, notes, and snippets.

@tseho
Last active April 5, 2022 20:38
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tseho/a52d616f2575d6418417253b92e1b3a5 to your computer and use it in GitHub Desktop.
Save tseho/a52d616f2575d6418417253b92e1b3a5 to your computer and use it in GitHub Desktop.
circleci + docker-compose + layers cache
version: 2
jobs:
build:
docker:
- image: docker:17.06.0-ce-git
steps:
- checkout
- setup_remote_docker
- run:
name: Install Docker Compose
command: |
apk add --no-cache 'py2-pip'
pip install 'docker-compose==1.16.1'
- restore_cache:
keys:
- v1-docker-{{ .Branch }}
- run:
name: Load Docker layers cache
command: |
set +o pipefail
docker load -i ~/docker-layers.tar | true
- run:
name: Build Docker images
command: docker-compose -p $CIRCLE_PROJECT_REPONAME build
- run:
name: Save Docker layers cache
command: |
DOCKER_IMAGES=$(docker images --format "{{.Repository}}" --filter=reference="${CIRCLE_PROJECT_REPONAME}_*")
DOCKER_LAYERS=$(for image in $DOCKER_IMAGES; do docker history $image -q | grep -v missing; done)
docker save -o ~/docker-layers.tar $DOCKER_LAYERS
- save_cache:
key: v1-docker-{{ .Branch }}-{{ epoch }}
paths:
- ~/docker-layers.tar
@remorses
Copy link

remorses commented Mar 9, 2019

really smart, if you want you can also skip installing docker-compose starting from image docker/compose

@mjhea0
Copy link

mjhea0 commented Mar 14, 2019

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