Last active
April 5, 2022 20:38
-
-
Save tseho/a52d616f2575d6418417253b92e1b3a5 to your computer and use it in GitHub Desktop.
circleci + docker-compose + layers cache
This file contains hidden or 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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
really smart, if you want you can also skip installing docker-compose starting from image
docker/compose