-
Notifications
You must be signed in to change notification settings - Fork 13
61 lines (59 loc) · 2.08 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
name: Cache Docker Images CI
on:
workflow_call:
secrets:
DOCKERHUB_USERNAME:
required: true
DOCKERHUB_TOKEN:
required: true
jobs:
changes:
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@v3
- name: Filter commit changes
uses: dorny/paths-filter@v2
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: [ changes ]
if: ${{ always() && needs.changes.outputs.cache-images == 'true' }}
runs-on: [self-hosted, ubuntu-20.04, X64, small]
steps:
- name: Checkout
uses: actions/checkout@v3
- 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