-
Notifications
You must be signed in to change notification settings - Fork 25
244 lines (217 loc) · 7.8 KB
/
docker-build.yml
File metadata and controls
244 lines (217 loc) · 7.8 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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
name: Docker Build and Publish
on:
# Trigger on GitHub releases for production builds
release:
types: [published]
# Manual workflow dispatch for development/testing
workflow_dispatch:
inputs:
tag:
description: 'Docker tag to use'
required: false
default: 'dev'
skip_tests:
description: 'Skip ctest smoke tests'
required: false
type: boolean
default: false
dockerfile:
description: 'Dockerfile to use'
required: false
default: './Dockerfile'
jobs:
# Validate DockerHub credentials before running expensive builds
check-docker-token:
name: Validate DockerHub Credentials
runs-on: ubuntu-latest
steps:
- name: Test DockerHub authentication
run: |
echo "Testing DockerHub credentials..."
if echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" --password-stdin; then
echo "✓ DockerHub credentials are valid"
else
echo "✗ DockerHub authentication failed!"
echo ""
echo "ERROR: The DockerHub credentials could not authenticate."
echo ""
echo "This usually means:"
echo " - The Personal Access Token (PAT) has expired"
echo " - The token has been revoked"
echo " - The username or token is incorrect"
echo ""
echo "To fix this issue:"
echo " 1. Go to https://hub.docker.com/settings/security to create a new PAT"
echo " 2. Update the GitHub repository secrets:"
echo " - DOCKERHUB_USERNAME: Your DockerHub username"
echo " - DOCKERHUB_TOKEN: Your new DockerHub PAT"
echo " 3. Navigate to: Settings > Secrets and variables > Actions"
echo ""
exit 1
fi
# Generate metadata once to be shared across all jobs
prepare-metadata:
name: Prepare Build Metadata
runs-on: ubuntu-latest
outputs:
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
json: ${{ steps.meta.outputs.json }}
primary-tag: ${{ steps.primary.outputs.tag }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Extract metadata (tags, labels)
id: meta
uses: docker/metadata-action@v5
with:
images: pnnl/gridpack
tags: |
type=ref,event=branch
type=semver,pattern=v{{version}}
type=semver,pattern=v{{major}}.{{minor}}
type=semver,pattern=v{{major}}
type=ref,event=tag
type=raw,value=latest,enable=${{ github.event_name == 'release' || github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
type=raw,value=${{ inputs.tag || 'dev' }},enable=${{ github.event_name == 'workflow_dispatch' }}
- name: Extract primary tag
id: primary
run: |
PRIMARY_TAG=$(echo "${{ steps.meta.outputs.tags }}" | head -n 1)
echo "tag=${PRIMARY_TAG}" >> $GITHUB_OUTPUT
echo "Primary tag: ${PRIMARY_TAG}"
# Build for each architecture using native runners
build-native:
name: Build ${{ matrix.platform }} on native runner
needs:
- prepare-metadata
- check-docker-token
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
include:
- platform: linux/amd64
runner: ubuntu-latest
arch: amd64
- platform: linux/arm64
runner: ubuntu-24.04-arm
arch: arm64
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push by digest
id: build
uses: docker/build-push-action@v5
with:
context: .
file: ${{ inputs.dockerfile || './Dockerfile' }}
platforms: ${{ matrix.platform }}
push: true
labels: ${{ needs.prepare-metadata.outputs.labels }}
outputs: type=image,name=pnnl/gridpack,push-by-digest=true,name-canonical=true,push=true
cache-from: type=gha,scope=build-${{ matrix.arch }}
cache-to: type=gha,mode=max,scope=build-${{ matrix.arch }}
build-args: |
boost_version=1.81.0
ga_version=5.9.1
petsc_version=3.24.2
- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
echo "Digest for ${{ matrix.arch }}: ${digest}"
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ matrix.arch }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
# Merge the architecture-specific images into a multi-arch manifest
merge-manifest:
name: Create Multi-Architecture Manifest
runs-on: ubuntu-latest
needs:
- prepare-metadata
- build-native
- check-docker-token
steps:
- name: Download digests
uses: actions/download-artifact@v4
with:
pattern: digests-*
path: /tmp/digests
merge-multiple: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Create manifest list and push
working-directory: /tmp/digests
run: |
# Parse all tags from metadata
TAGS="${{ needs.prepare-metadata.outputs.tags }}"
# Build docker buildx imagetools create command with all tags
CMD="docker buildx imagetools create"
for tag in ${TAGS}; do
CMD="${CMD} -t ${tag}"
done
# Add all digests
for digest in $(ls -1); do
CMD="${CMD} pnnl/gridpack@sha256:${digest}"
done
echo "Creating manifest with command:"
echo "${CMD}"
eval "${CMD}"
- name: Inspect multi-arch manifest
run: |
echo "Inspecting multi-architecture manifest..."
TAG="${{ needs.prepare-metadata.outputs.primary-tag }}"
docker buildx imagetools inspect ${TAG}
# Test both architectures in parallel
test-native:
name: Test ${{ matrix.platform }} image
needs:
- prepare-metadata
- merge-manifest
- check-docker-token
runs-on: ${{ matrix.runner }}
if: ${{ !inputs.skip_tests }}
continue-on-error: true
strategy:
fail-fast: false
matrix:
include:
- platform: linux/amd64
runner: ubuntu-latest
arch: amd64
- platform: linux/arm64
runner: ubuntu-24.04-arm
arch: arm64
steps:
- name: Log in to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Run ctest smoke tests on ${{ matrix.arch }}
run: |
echo "Running ctest smoke tests on ${{ matrix.arch }}..."
echo "Note: Test failures will NOT cause the workflow to fail (continue-on-error: true)"
echo "Typical pass rate: ~94%"
echo ""
TAG="${{ needs.prepare-metadata.outputs.primary-tag }}"
docker pull ${TAG}
docker run --rm ${TAG} bash -c "cd /app/src/build && ctest -j"