Skip to content

Instantly share code, notes, and snippets.

@Richard-Mathie
Last active October 15, 2018 16:55
Show Gist options
  • Save Richard-Mathie/20fb260134e14ed2a97fcda320db8931 to your computer and use it in GitHub Desktop.
Save Richard-Mathie/20fb260134e14ed2a97fcda320db8931 to your computer and use it in GitHub Desktop.
CircleCI Docker Caching
version: 2.1
default_working_dir: &working_container
working_directory: /app
docker:
- image: docker:18.06.1-ce-git
default_steps:
steps:
- setup_remote_docker
- restore_cache: &restore_cache
keys:
- v1-{{ .Branch }}
paths:
- /caches/app.tar
- run: &load_cache
name: Load Docker image layer cache
command: |
set +o pipefail
docker load -i /caches/app.tar | true
docker images
jobs:
build:
<<: *working_container
steps:
- checkout
- setup_remote_docker
- restore_cache: *restore_cache
- run: *load_cache
- run:
name: Build application Docker image
command: |
docker build -t myapp-build --cache-from=myapp-build --tag myapp-build --target build .
docker build --cache-from=myapp --cache-from=myapp-build -t myapp .
- run: &save_layers
name: Save Docker image layer cache
command: |
mkdir -p /caches
docker save -o /caches/app.tar myapp myapp-build
- save_cache: &save_cache
key: v1-{{ .Branch }}-{{ epoch }}
paths:
- /caches/app.tar
- .venv
test1:
<<: *working_container
steps:
- setup_remote_docker
- restore_cache: *restore_cache
- run: *load_cache
- run:
name: Run tests
command: |
docker run myapp test
workflows:
version: 2
build-and-test:
jobs:
- build:
- test1:
requires:
- build
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment