-
Notifications
You must be signed in to change notification settings - Fork 177
167 lines (162 loc) · 5.15 KB
/
docker-images.yml
File metadata and controls
167 lines (162 loc) · 5.15 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
name: docker-images
on:
push:
branches:
- master
- docker-test
pull_request:
branches:
- master
- docker-test
workflow_dispatch:
jobs:
multi:
strategy:
fail-fast: false
matrix:
image:
- ftpsync
- nix-channels
- rubygems-mirror
- rustup-mirror
# - shadowmire
- tsumugu
- tunasync-scripts
# - freighter
os:
- ubuntu-latest
- ubuntu-24.04-arm
include:
- image: tunasync-scripts
dockerfile_dir: .
runs-on: ${{ matrix.os }}
steps:
-
name: Determine dockerfile dir
id: docker_file_dir
env:
DF: ${{ matrix.dockerfile_dir }}
IMG: ${{ matrix.image }}
run: |
if [ -z "${DF}" ]; then
DF="dockerfiles/${IMG}"
fi
echo "docker_file_dir=${DF}" >> $GITHUB_OUTPUT
-
name: Checkout
uses: actions/checkout@v5
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Cache Docker layers
uses: actions/cache@v4
if: github.event_name == 'push'
with:
path: /tmp/.buildx-cache
key: ${{ matrix.os }}-buildx-${{ matrix.image }}-${{ github.sha }}
restore-keys: |
${{ matrix.os }}-buildx-${{ matrix.image }}-${{ matrix.os }}-
${{ matrix.os }}-buildx-${{ matrix.image }}-
-
name: Cache Docker layers
uses: actions/cache@v4
if: github.event_name == 'pull_request'
with:
path: /tmp/.buildx-cache
key: ${{ matrix.os }}-pr-${{ github.event.pull_request.head.user.login }}-buildx-${{ matrix.image }}-${{ github.sha }}
restore-keys: |
${{ matrix.os }}-pr-${{ github.event.pull_request.head.user.login }}-buildx-${{ matrix.image }}-
${{ matrix.os }}-buildx-${{ matrix.image }}-
${{ matrix.os }}-buildx-${{ matrix.image }}-
-
name: Cache Docker layers
if: github.event_name != 'push' && github.event_name != 'pull_request'
run: |
echo "I do not know how to setup cache"
exit -1
-
name: Login to DockerHub
uses: docker/login-action@v3
if: github.event_name == 'push'
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Build and push
uses: docker/build-push-action@v6
id: docker_build
with:
context: .
file: ${{ steps.docker_file_dir.outputs.docker_file_dir }}/Dockerfile
push: ${{ github.event_name == 'push' }}
tags: tunathu/${{ matrix.image }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
outputs: ${{ github.event_name == 'push' && 'type=image,push-by-digest=true,name-canonical=true,push=true' || 'type=image' }}
-
name: Export digest
run: |
mkdir -p ${{ runner.temp }}/digests/${{ matrix.image }}
digest="${{ steps.docker_build.outputs.digest }}"
touch "${{ runner.temp }}/digests/${{ matrix.image }}/${digest#sha256:}"
-
name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ matrix.image }}-${{ runner.arch }}
path: ${{ runner.temp }}/digests/*
if-no-files-found: error
retention-days: 1
merge:
runs-on: ubuntu-latest
needs:
- multi
if: always() && github.event_name == 'push'
steps:
-
name: Determine docker tag
id: docker_tag
env:
TAG_NAME: ${{ github.ref }}
run: |
if [ "${TAG_NAME##*/}" = "master" ]; then
tag=latest
else
tag=build-test
fi
echo "docker_tag=${tag}" >> $GITHUB_OUTPUT
-
name: Download digests
uses: actions/download-artifact@v4
with:
path: ${{ runner.temp }}/digests
pattern: digests-*
merge-multiple: true
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Create manifest list and push
working-directory: ${{ runner.temp }}/digests
run: |
for i in *; do
docker buildx imagetools create -t "tunathu/$i:${{ steps.docker_tag.outputs.docker_tag }}" \
$(printf "tunathu/$i@sha256:%s " $(ls $i))
done
- name: Inspect images
working-directory: ${{ runner.temp }}/digests
run: |
for i in *; do
DOCKER_IMG="tunathu/$i:${{ steps.docker_tag.outputs.docker_tag }}"
echo "## $DOCKER_IMG" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
docker buildx imagetools inspect "$DOCKER_IMG" | tee -a $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
done