-
Notifications
You must be signed in to change notification settings - Fork 81
executable file
·230 lines (195 loc) · 7.74 KB
/
docker.yml
File metadata and controls
executable file
·230 lines (195 loc) · 7.74 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
name: CI-Docker
on:
push:
branches:
- master
- main
tags:
- v*
paths-ignore:
- '**.md'
- '**.rst'
workflow_dispatch: {}
repository_dispatch:
types:
- run_build
jobs:
build:
strategy:
matrix:
platform:
- runs-on: ubuntu-latest
container-platform: linux/amd64
- runs-on: ubuntu-24.04-arm
container-platform: linux/arm64
runs-on: ${{ matrix.platform.runs-on }}
timeout-minutes: 180
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Prepare
run: |
platform=${{ matrix.platform.container-platform }}
printf 'PLATFORM_PAIR=%s\n' "${platform//\//-}" >> $GITHUB_ENV
- name: Login to Github Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract DOCKER_TAG using tag name
if: startsWith(github.ref, 'refs/tags/')
run: |
printf 'DOCKER_TAG=%s\n' "${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV
- name: Use default DOCKER_TAG
if: startsWith(github.ref, 'refs/tags/') != true
run: |
printf 'DOCKER_TAG=%s\n' "latest" >> $GITHUB_ENV
- name: Prepare additional environment variables from repo
run: if test -f ./config/ci-docker-env.ini; then cat ./config/ci-docker-env.ini | sed -e 's/$REPOSITORY_OWNER/'"${{ github.repository_owner }}"'/g;s/$DOCKER_TAG/'"${{ env.DOCKER_TAG }}"'/g' >> $GITHUB_ENV; fi
- name: Extract DOCKER_TAG using tag name
if: env.BUILD_ARGS_LIST != null
run: |
printf 'BUILD_ARGS_LIST_NEWLINES<<EOF\n%s\nEOF\n' "${{ env.BUILD_ARGS_LIST }}" | tr ' ' $'\n' >> $GITHUB_ENV
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and Push to container registry
id: build
uses: docker/build-push-action@v6
with:
platforms: ${{ matrix.platform.container-platform }}
labels: ${{ steps.meta.outputs.labels }}
tags: ghcr.io/${{ github.repository }}
outputs: type=image,push-by-digest=true,name-canonical=true,push=true
build-args: ${{ env.BUILD_ARGS_LIST_NEWLINES }}
- name: Export digest
run: |
mkdir -p ${{ runner.temp }}/digests
digest="${{ steps.build.outputs.digest }}"
touch "${{ runner.temp }}/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ env.PLATFORM_PAIR }}
path: ${{ runner.temp }}/digests/*
if-no-files-found: error
retention-days: 1
merge:
needs:
- build
runs-on: ubuntu-latest
timeout-minutes: 20
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
outputs:
dest-repo: ${{ steps.dest-repo.outputs.DEST_REPO }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Ubuntu packages
run: |
sudo apt-get -y update
sudo apt-get -y -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' install jq
- name: Download digests
uses: actions/download-artifact@v4
with:
path: ${{ runner.temp }}/digests
pattern: digests-*
merge-multiple: true
- name: Login to DockerHub
uses: docker/login-action@v3
if: env.DOCKER_USERNAME != null
with:
username: ${{ env.DOCKER_USERNAME }}
password: ${{ env.DOCKER_PASSWORD }}
- name: Login to Github Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract DOCKER_TAG using tag name
if: startsWith(github.ref, 'refs/tags/')
run: |
printf 'DOCKER_TAG=%s\n' "${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV
- name: Use default DOCKER_TAG
if: startsWith(github.ref, 'refs/tags/') != true
run: |
printf 'DOCKER_TAG=%s\n' "latest" >> $GITHUB_ENV
- name: Set docker tag list to include DockerHub if credentials available
if: env.DOCKER_USERNAME != null
run: |
printf 'DOCKER_CONTAINER_LIST<<EOF\n%s\nEOF\n' "ghcr.io/${{ github.repository }}"$'\n'"${{ github.repository }}" >> $GITHUB_ENV
- name: Set docker tag list to not include DockerHub if credentials not available
if: env.DOCKER_USERNAME == null
run: |
printf 'DOCKER_CONTAINER_LIST<<EOF\n%s\nEOF\n' "ghcr.io/${{ github.repository }}" >> $GITHUB_ENV
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.DOCKER_CONTAINER_LIST }}
tags: |
type=raw,value=${{ env.DOCKER_TAG }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Create manifest list and push
working-directory: ${{ runner.temp }}/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") $(printf 'ghcr.io/${{ github.repository }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ghcr.io/${{ github.repository }}:${{ steps.meta.outputs.version }}
- name: Gather information for repository dispatch
id: dest-repo
run: if test -f ./config/repository-dispatch.ini; then cat ./config/repository-dispatch.ini >> $GITHUB_OUTPUT; fi
perform-repository-dispatch:
needs:
- merge
runs-on: ubuntu-latest
container:
image: ubuntu:20.04
options: "--user 0"
timeout-minutes: 20
env:
DISPATCH_TOKEN: ${{ secrets.DISPATCH_TOKEN }}
strategy:
matrix:
dest-repo: ${{ fromJson(needs.merge.outputs.dest-repo) }}
steps:
- name: Gather environment variables (normal)
if: github.event_name != 'repository_dispatch'
run: |
printf 'PAYLOAD_REPO_PARENT_NAME=%s\n' "${{ github.repository }}" >> $GITHUB_ENV
printf 'PAYLOAD_REPO_PARENT_SHA=%s\n' "${{ github.sha }}" >> $GITHUB_ENV
- name: Gather environment variables (dispatch)
if: github.event_name == 'repository_dispatch'
run: |
printf 'PAYLOAD_REPO_PARENT_NAME=%s\n' "${{ github.event.client_payload.parent_name }}" >> $GITHUB_ENV
printf 'PAYLOAD_REPO_PARENT_SHA=%s\n' "${{ github.event.client_payload.parent_sha }}" >> $GITHUB_ENV
- name: Send Compile action
run: |
export DISPATCH_ACTION="$(printf 'run_build\n')"
printf 'NEW_DISPATCH_ACTION=%s\n' "$DISPATCH_ACTION" >> $GITHUB_ENV
- name: Repository Dispatch to ${{ matrix.dest-repo }}
uses: peter-evans/repository-dispatch@v3
if: env.DISPATCH_TOKEN != null && !contains(matrix.dest-repo, '/')
with:
repository: ${{ github.repository_owner }}/${{ matrix.dest-repo }}
token: ${{ secrets.DISPATCH_TOKEN }}
event-type: ${{ env.NEW_DISPATCH_ACTION }}
client-payload: '{"ref": "${{ github.ref }}", "parent_name": "${{ env.PAYLOAD_REPO_PARENT_NAME }}", "parent_sha": "${{ env.PAYLOAD_REPO_PARENT_SHA }}"}'
- name: Repository Dispatch to specific ${{ matrix.dest-repo }}
uses: peter-evans/repository-dispatch@v3
if: env.DISPATCH_TOKEN != null && contains(matrix.dest-repo, '/')
with:
repository: ${{ matrix.dest-repo }}
token: ${{ secrets.DISPATCH_TOKEN }}
event-type: ${{ env.NEW_DISPATCH_ACTION }}
client-payload: '{"ref": "${{ github.ref }}", "parent_name": "${{ env.PAYLOAD_REPO_PARENT_NAME }}", "parent_sha": "${{ env.PAYLOAD_REPO_PARENT_SHA }}"}'