-
Notifications
You must be signed in to change notification settings - Fork 24
221 lines (200 loc) Β· 9.06 KB
/
Copy pathdocker-build-upload.yml
File metadata and controls
221 lines (200 loc) Β· 9.06 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
---
name: Build Docker image and upload
on:
pull_request:
branches:
- main
push:
branches:
- main
tags:
- v*
workflow_dispatch:
env:
FORCE_COLOR: 1
IMAGE_NAME: aiidalab/qe
BUILDKIT_PROGRESS: plain
# Only cancel in-progress jobs for the same ref
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build-amd:
# Run for push events on main or v* tags OR PRs,
# but skip PRs coming from a release branch (e.g. release/v25.04.0)
if: |
(github.event_name == 'push' && (
startsWith(github.ref, 'refs/heads/main') ||
startsWith(github.ref, 'refs/tags/v')
))
||
(github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.fork == false &&
!startsWith(github.head_ref, 'release/'))
runs-on: ubuntu-latest
outputs:
base_tags_ghcr: ${{ steps.meta_ghcr.outputs.tags }}
base_tags_dockerhub: ${{ steps.meta_dockerhub.outputs.tags }}
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- name: Login to GitHub Container Registry π
if: ${{ !github.event.pull_request.head.repo.fork }}
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to DockerHub π
if: ${{ !github.event.pull_request.head.repo.fork }}
uses: docker/login-action@v2
with:
registry: docker.io
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker meta (GHCR) π
id: meta_ghcr
uses: docker/metadata-action@v5
with:
images: |
name=ghcr.io/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=pr
type=edge,enable={{is_default_branch}}
type=raw,value={{tag}},enable=${{ startsWith(github.ref, 'refs/tags/v') }}
- name: Docker meta (DockerHub) π
id: meta_dockerhub
uses: docker/metadata-action@v5
with:
images: docker.io/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=pr
type=edge,enable={{is_default_branch}}
type=raw,value={{tag}},enable=${{ startsWith(github.ref, 'refs/tags/v') }}
- name: Build and push AMD image
id: build_upload_amd
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64
push: ${{ ! (github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork) }}
load: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork }}
# Append "-amd" to the dynamically generated tags
tags: |
${{ steps.meta_ghcr.outputs.tags }}-amd,
${{ steps.meta_dockerhub.outputs.tags }}-amd
cache-to: type=gha,scope=${{ github.workflow }},mode=min
cache-from: type=gha,scope=${{ github.workflow }}
build-arm:
if: |
(github.event_name == 'push' && (
startsWith(github.ref, 'refs/heads/main') ||
startsWith(github.ref, 'refs/tags/v')
))
||
(github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.fork == false &&
!startsWith(github.head_ref, 'release/'))
runs-on: ubuntu-24.04-arm
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- name: Login to GitHub Container Registry π
if: ${{ !github.event.pull_request.head.repo.fork }}
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to DockerHub π
if: ${{ !github.event.pull_request.head.repo.fork }}
uses: docker/login-action@v2
with:
registry: docker.io
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker meta (GHCR) π
id: meta_ghcr
uses: docker/metadata-action@v5
with:
images: |
name=ghcr.io/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=pr
type=edge,enable={{is_default_branch}}
type=raw,value={{tag}},enable=${{ startsWith(github.ref, 'refs/tags/v') }}
- name: Docker meta (DockerHub) π
id: meta_dockerhub
uses: docker/metadata-action@v5
with:
images: docker.io/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=pr
type=edge,enable={{is_default_branch}}
type=raw,value={{tag}},enable=${{ startsWith(github.ref, 'refs/tags/v') }}
- name: Build and push ARM image
id: build_upload_arm
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/arm64
push: ${{ ! (github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork) }}
load: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork }}
tags: |
${{ steps.meta_ghcr.outputs.tags }}-arm,
${{ steps.meta_dockerhub.outputs.tags }}-arm
cache-to: type=gha,scope=${{ github.workflow }},mode=min
cache-from: type=gha,scope=${{ github.workflow }}
create-manifest:
if: |
(github.event_name == 'push' && (
startsWith(github.ref, 'refs/heads/main') ||
startsWith(github.ref, 'refs/tags/v')
))
||
(github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.fork == false &&
!startsWith(github.head_ref, 'release/'))
runs-on: ubuntu-latest
needs: [build-amd, build-arm]
steps:
- name: Login to GitHub Container Registry π
if: ${{ !github.event.pull_request.head.repo.fork }}
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to DockerHub π
if: ${{ !github.event.pull_request.head.repo.fork }}
uses: docker/login-action@v2
with:
registry: docker.io
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Create and push manifest for GHCR
run: |
BASE_TAG="${{ needs.build-amd.outputs.base_tags_ghcr }}"
docker buildx imagetools create -t ${BASE_TAG} ${BASE_TAG}-amd ${BASE_TAG}-arm
- name: Create and push manifest for DockerHub
run: |
BASE_TAG="${{ needs.build-amd.outputs.base_tags_dockerhub }}"
docker buildx imagetools create -t ${BASE_TAG} ${BASE_TAG}-amd ${BASE_TAG}-arm
# Create a βlatestβ manifest only if the tag is a proper release (not a)
- name: Create and push manifest for GHCR latest
if: startsWith(github.ref, 'refs/tags/v') && !contains(github.ref, 'a') && !contains(github.ref, 'b') && !contains(github.ref, 'rc')
run: |
docker buildx imagetools create -t ghcr.io/${{ env.IMAGE_NAME }}:latest \
${{ needs.build-amd.outputs.base_tags_ghcr }}-amd \
${{ needs.build-amd.outputs.base_tags_ghcr }}-arm
- name: Create and push manifest for DockerHub latest
if: startsWith(github.ref, 'refs/tags/v') && !contains(github.ref_name, 'a') && !contains(github.ref_name, 'b') && !contains(github.ref_name,
'rc')
run: |
docker buildx imagetools create -t docker.io/${{ env.IMAGE_NAME }}:latest \
${{ needs.build-amd.outputs.base_tags_dockerhub }}-amd \
${{ needs.build-amd.outputs.base_tags_dockerhub }}-arm