-
Notifications
You must be signed in to change notification settings - Fork 25
65 lines (58 loc) · 2.06 KB
/
cache.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
name: cache
permissions: {}
on:
pull_request:
types:
- closed
defaults:
run:
shell: bash
env:
DOCKER_FILE_DIRECTORY: environments
DOCKER_COMPOSE_DIRECTORY: environments/ci
COMPOSE_DOCKER_CLI_BUILD: 1
DOCKER_BUILDKIT: 1
USE_CACHE: true
jobs:
create-cache:
if: github.event.pull_request.merged == true
name: ${{ matrix.os }} / ${{ matrix.python-version }}
runs-on: ${{ matrix.image }}
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
os: [ubuntu]
python-version: ["3.10", "3.11", "3.12"]
include:
- os: ubuntu
image: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- name: Check version info
run: pwd && docker compose version && docker --version
# Provide a builder instance with docker buildx.
- name: Set up Docker Buildx
if: env.USE_CACHE == 'true'
uses: docker/setup-buildx-action@v3
# Specify a cache directory for build cache, and reuse past build cache as long as there are no changes to the environment files.
- name: Cache Docker layers
if: env.USE_CACHE == 'true'
id: build-cache
uses: actions/cache@v4
with:
path: ${{ runner.temp }}/${{ matrix.python-version }}
key: buildx-${{ hashFiles(format('{0}/Dockerfile', env.DOCKER_FILE_DIRECTORY), format('{0}/docker-compose.yaml', env.DOCKER_COMPOSE_DIRECTORY), 'poetry.lock') }}
# If build cache is not found, build the Docker image to create a new cache.
- name: Build docker image with cache using buildx
if: steps.build-cache.outputs.cache-hit != 'true' && env.USE_CACHE == 'true'
uses: docker/bake-action@v6
with:
files: "${{ env.DOCKER_COMPOSE_DIRECTORY }}/docker-compose.yaml"
workdir: ${{ env.DOCKER_COMPOSE_DIRECTORY }}
load: true
set: |
core.args.PYTHON_VERSION=${{ matrix.python-version }}
core.cache-to=type=local,dest=${{ runner.temp }}/${{ matrix.python-version }}