-
Notifications
You must be signed in to change notification settings - Fork 49
76 lines (73 loc) · 2.88 KB
/
cache-docker-images.yml
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
66
67
68
69
70
71
72
73
74
75
76
name: Cache Docker Images CI
on:
workflow_call:
secrets:
DOCKERHUB_USERNAME:
required: false
DOCKERHUB_TOKEN:
required: false
jobs:
check-dockerhub-secrets-present:
runs-on: [self-hosted, ubuntu-20.04, X64, small]
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
name: Check if DockerHub secrets are present
outputs:
secrets_present: ${{ steps.check-secrets-present-step.outputs.DOCKERHUB_SECRET_PRESENT }}
steps:
- id: check-secrets-present-step
run: |
echo DOCKERHUB_SECRET_PRESENT=${{ env.DOCKERHUB_USERNAME != '' && env.DOCKERHUB_TOKEN != '' }} >> $GITHUB_OUTPUT
changes:
needs: [ check-dockerhub-secrets-present ]
if: ${{ always() && needs.check-dockerhub-secrets-present.outputs.secrets_present == 'true' }}
runs-on: [self-hosted, ubuntu-20.04, X64, small]
name: Filter commit changes
outputs:
cache_images: ${{ steps.filter.outputs.cache_images }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Filter commit changes
uses: dorny/paths-filter@v3
id: filter
with:
base: ${{ github.ref }}
list-files: "json"
filters: |
cache_images:
- 'docker/compose.yml'
- 'docker/compose-local-dev.overrides.yml'
- 'docker/compose-local-dev-traces-v2.overrides.yml'
pull-and-cache-images:
needs: [ check-dockerhub-secrets-present, changes ]
if: ${{ always() && needs.check-dockerhub-secrets-present.outputs.secrets_present == 'true' && needs.changes.outputs.cache_images == 'true' }}
runs-on: [self-hosted, ubuntu-20.04, X64, small]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Pull docker images from compose
continue-on-error: true
run: |
docker compose -f docker/compose.yml -f docker/compose-local-dev-traces-v2.overrides.yml --profile l1 --profile l2 pull
- name: Save Docker images
run: |
mkdir -p ~/docker-images
images=$(docker compose -f docker/compose.yml -f docker/compose-local-dev-traces-v2.overrides.yml --profile l1 --profile l2 config | grep "image:" | awk '{print $2}')
for image in $images; do
imageFileName=$(echo $image | sed -e 's|.*/||' -e 's|:|-|' -e 's/\./_/g')
echo $image - ${imageFileName}
docker save $image > ~/docker-images/${imageFileName}.tar
done
- name: Cache common docker images
continue-on-error: true
uses: actions/cache/[email protected]
with:
path: ~/docker-images
key: cached-images