-
Notifications
You must be signed in to change notification settings - Fork 0
210 lines (174 loc) · 6.65 KB
/
Copy pathdocker.yml
File metadata and controls
210 lines (174 loc) · 6.65 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
name: Docker
on:
push:
branches:
- main
tags:
- 'v*'
pull_request:
workflow_dispatch:
inputs:
mode:
description: Manual run mode
type: choice
required: true
default: build-only
options:
- build-only
- publish-test
permissions:
contents: read
env:
DOCKER_BUILD_RECORD_UPLOAD: 'false'
concurrency:
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.pull_request.number) || github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
image_pr:
name: image-pr
if: github.event_name == 'pull_request'
runs-on: ${{ vars.RUNS_ON_AMD64 || vars.RUNS_ON || 'ubuntu-latest' }}
timeout-minutes: 10
steps:
- &checkout
name: Checkout
uses: actions/checkout@v6
- &setup-buildx
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- &resolve-build-date
name: Resolve build date
id: build-date
run: echo "build_date=$(date -u '+%Y-%m-%dT%H:%M:%SZ')" >> "$GITHUB_OUTPUT"
- &resolve-image-name
name: Resolve image name
id: image
shell: bash
run: printf 'name=ghcr.io/%s\n' "${GITHUB_REPOSITORY,,}" >> "$GITHUB_OUTPUT"
- &docker-metadata
name: Docker metadata
id: meta
uses: docker/metadata-action@v6
with:
images: ${{ steps.image.outputs.name }}
tags: |
type=raw,value=edge,enable=${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
type=raw,value=ci-manual-test,enable=${{ github.event_name == 'workflow_dispatch' && github.event.inputs.mode == 'publish-test' }}
type=ref,event=tag,enable=${{ github.event_name == 'push' }}
type=ref,event=pr,enable=${{ github.event_name == 'pull_request' }}
- name: Build image
uses: docker/build-push-action@v7
with:
context: .
platforms: linux/amd64
push: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha,scope=synaps3-image-amd64
build-args: |
VERSION=${{ github.ref_type == 'tag' && github.ref_name || 'edge' }}
COMMIT=${{ github.sha }}
BUILD_DATE=${{ steps.build-date.outputs.build_date }}
image_amd64:
name: image-amd64
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
runs-on: ${{ vars.RUNS_ON_AMD64 || vars.RUNS_ON || 'ubuntu-latest' }}
timeout-minutes: 10
permissions:
contents: read
packages: write
outputs:
digest: ${{ steps.build.outputs.digest }}
steps:
- *checkout
- *setup-buildx
- &login-ghcr
name: Log in to GHCR
if: github.event_name == 'push' || github.event.inputs.mode == 'publish-test'
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- *resolve-build-date
- *resolve-image-name
- *docker-metadata
- name: Build image
id: build
uses: docker/build-push-action@v7
with:
context: .
platforms: linux/amd64
labels: ${{ steps.meta.outputs.labels }}
outputs: ${{ (github.event_name == 'push' || github.event.inputs.mode == 'publish-test') && format('type=image,name={0},push-by-digest=true,name-canonical=true,push=true', steps.image.outputs.name) || '' }}
cache-from: type=gha,scope=synaps3-image-amd64
cache-to: ${{ (github.event_name == 'push' || github.event.inputs.mode == 'publish-test') && 'type=gha,scope=synaps3-image-amd64,mode=max,ignore-error=true' || '' }}
build-args: |
VERSION=${{ github.event_name == 'workflow_dispatch' && 'ci-manual-test' || github.ref_type == 'tag' && github.ref_name || 'edge' }}
COMMIT=${{ github.sha }}
BUILD_DATE=${{ steps.build-date.outputs.build_date }}
image_arm64:
name: image-arm64
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
runs-on: ${{ vars.RUNS_ON_ARM64 || 'ubuntu-24.04-arm' }}
timeout-minutes: 10
permissions:
contents: read
packages: write
outputs:
digest: ${{ steps.build.outputs.digest }}
steps:
- *checkout
- *setup-buildx
- *login-ghcr
- *resolve-build-date
- *resolve-image-name
- *docker-metadata
- name: Build image
id: build
uses: docker/build-push-action@v7
with:
context: .
platforms: linux/arm64
labels: ${{ steps.meta.outputs.labels }}
outputs: ${{ (github.event_name == 'push' || github.event.inputs.mode == 'publish-test') && format('type=image,name={0},push-by-digest=true,name-canonical=true,push=true', steps.image.outputs.name) || '' }}
cache-from: type=gha,scope=synaps3-image-arm64
cache-to: ${{ (github.event_name == 'push' || github.event.inputs.mode == 'publish-test') && 'type=gha,scope=synaps3-image-arm64,mode=max,ignore-error=true' || '' }}
build-args: |
VERSION=${{ github.event_name == 'workflow_dispatch' && 'ci-manual-test' || github.ref_type == 'tag' && github.ref_name || 'edge' }}
COMMIT=${{ github.sha }}
BUILD_DATE=${{ steps.build-date.outputs.build_date }}
image_manifest:
name: image-manifest
if: github.event_name == 'push' || github.event.inputs.mode == 'publish-test'
needs:
- image_amd64
- image_arm64
runs-on: ${{ vars.RUNS_ON_AMD64 || vars.RUNS_ON || 'ubuntu-latest' }}
timeout-minutes: 10
permissions:
contents: read
packages: write
steps:
- *setup-buildx
- *login-ghcr
- *resolve-image-name
- *docker-metadata
- name: Create manifest
shell: bash
env:
DOCKER_METADATA_TAGS: ${{ steps.meta.outputs.tags }}
run: |
tag_args=()
while IFS= read -r tag; do
[ -n "$tag" ] && tag_args+=("-t" "$tag")
done <<< "$DOCKER_METADATA_TAGS"
if [ "${#tag_args[@]}" -eq 0 ]; then
echo "No Docker tags resolved"
exit 1
fi
docker buildx imagetools create "${tag_args[@]}" \
"${{ steps.image.outputs.name }}@${{ needs.image_amd64.outputs.digest }}" \
"${{ steps.image.outputs.name }}@${{ needs.image_arm64.outputs.digest }}"
- name: Inspect manifest
run: docker buildx imagetools inspect ${{ steps.image.outputs.name }}:${{ steps.meta.outputs.version }}