-
Notifications
You must be signed in to change notification settings - Fork 1
244 lines (217 loc) · 9.43 KB
/
build-dockerfile.yml
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
# Copyright (C) 2023 Roberto Rossini <roberros@uio.no>
# SPDX-License-Identifier: MIT
name: Build Dockerfile
on:
push:
branches: [main]
paths:
- ".github/workflows/build-dockerfile.yml"
- "cmake/**"
- "external/**"
- "src/**"
- "test/integration/**"
- "utils/devel/test_docker_image.sh"
- ".dockerignore"
- "CMakeLists.txt"
- "Dockerfile"
- "conanfile.Dockerfile.py"
tags:
- "v*.*.*"
pull_request:
paths:
- ".github/workflows/build-dockerfile.yml"
- "cmake/**"
- "external/**"
- "src/**"
- "test/integration/**"
- "utils/devel/test_docker_image.sh"
- ".dockerignore"
- "CMakeLists.txt"
- "Dockerfile"
- "conanfile.Dockerfile.py"
# https://stackoverflow.com/a/72408109
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
defaults:
run:
shell: bash
jobs:
cache-test-dataset:
uses: paulsengroup/hictk/.github/workflows/cache-test-dataset.yml@main
name: Cache test dataset
build-dockerfile:
name: Build Dockerfile
needs: cache-test-dataset
runs-on: ubuntu-latest
permissions:
contents: "read"
packages: "write"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Restore test dataset
uses: actions/cache/restore@v4
with:
key: ${{ needs.cache-test-dataset.outputs.cache-key }}
path: test/data/hictk_test_data.tar.zst
fail-on-cache-miss: true
- name: Generate build args
id: build-args
run: |
set -e
set -u
set -o pipefail
OS_NAME='ubuntu'
OS_VERSION='22.04'
C_COMPILER='clang-19'
CXX_COMPILER='clang++-19'
BUILD_BASE_IMAGE="ghcr.io/paulsengroup/ci-docker-images/$OS_NAME-$OS_VERSION-cxx-$C_COMPILER:latest"
TEST_BASE_IMAGE="$BUILD_BASE_IMAGE"
FINAL_BASE_IMAGE="docker.io/library/$OS_NAME"
FINAL_BASE_IMAGE_TAG="$OS_VERSION"
sudo docker pull "$FINAL_BASE_IMAGE:$FINAL_BASE_IMAGE_TAG"
FINAL_BASE_IMAGE_DIGEST="$(docker inspect --format='{{index .RepoDigests 0}}' "$FINAL_BASE_IMAGE:$FINAL_BASE_IMAGE_TAG" | grep -o '[[:alnum:]:]\+$')"
GIT_HASH="$(git rev-parse HEAD)"
GIT_SHORT_HASH="$(git rev-parse --short HEAD)"
CREATION_DATE="$(date --iso-8601)"
GIT_TAG="$(git for-each-ref 'refs/tags/v*.*.*' --count 1 --sort=-v:refname --format "%(refname:short)" --points-at HEAD)"
if [ -z "$GIT_TAG" ]; then
VERSION="sha-$GIT_SHORT_HASH"
GIT_TAG=unknown
else
VERSION="$GIT_TAG"
fi
CACHE_REGISTRY='ghcr.io/${{ github.repository }}:buildcache'
echo "C_COMPILER=$C_COMPILER" | tee -a "$GITHUB_OUTPUT"
echo "CXX_COMPILER=$CXX_COMPILER" | tee -a "$GITHUB_OUTPUT"
echo "FINAL_BASE_IMAGE=$FINAL_BASE_IMAGE" | tee -a "$GITHUB_OUTPUT"
echo "FINAL_BASE_IMAGE_TAG=$FINAL_BASE_IMAGE_TAG" | tee -a "$GITHUB_OUTPUT"
echo "BUILD_BASE_IMAGE=$BUILD_BASE_IMAGE" | tee -a "$GITHUB_OUTPUT"
echo "TEST_BASE_IMAGE=$TEST_BASE_IMAGE" | tee -a "$GITHUB_OUTPUT"
echo "FINAL_BASE_IMAGE_DIGEST=$FINAL_BASE_IMAGE_DIGEST" | tee -a "$GITHUB_OUTPUT"
echo "GIT_HASH=$GIT_HASH" | tee -a "$GITHUB_OUTPUT"
echo "GIT_SHORT_HASH=$GIT_SHORT_HASH" | tee -a "$GITHUB_OUTPUT"
echo "CREATION_DATE=$CREATION_DATE" | tee -a "$GITHUB_OUTPUT"
echo "GIT_TAG=$GIT_TAG" | tee -a "$GITHUB_OUTPUT"
echo "VERSION=$VERSION" | tee -a "$GITHUB_OUTPUT"
echo "CACHE_REGISTRY_X86=$CACHE_REGISTRY-x86" | tee -a "$GITHUB_OUTPUT"
echo "CACHE_REGISTRY_ARM64=$CACHE_REGISTRY-arm64" | tee -a "$GITHUB_OUTPUT"
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ github.repository }},ghcr.io/${{ github.repository }}
flavor: |
latest=true
tags: |
type=semver,priority=1000,pattern={{version}}
type=sha,priority=900
type=ref,priority=700,event=branch
type=ref,priority=600,event=pr
- name: Login to DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
platforms: linux/amd64,linux/arm64
- name: Set up QEMU
if: github.event_name != 'pull_request'
uses: docker/setup-qemu-action@v3
with:
platforms: arm64
- name: Build Docker image (x86)
uses: docker/build-push-action@v6
with:
context: ${{ github.workspace }}
load: true
push: false
cache-from: type=registry,ref=${{ steps.build-args.outputs.CACHE_REGISTRY_X86 }}
cache-to: type=registry,ref=${{ steps.build-args.outputs.CACHE_REGISTRY_X86 }},mode=max,compression=zstd
tags: hictk:x86
platforms: linux/amd64
build-args: |
C_COMPILER=${{ steps.build-args.outputs.C_COMPILER }}
CXX_COMPILER=${{ steps.build-args.outputs.CXX_COMPILER }}
BUILD_BASE_IMAGE=${{ steps.build-args.outputs.BUILD_BASE_IMAGE }}
TEST_BASE_IMAGE=${{ steps.build-args.outputs.TEST_BASE_IMAGE }}
FINAL_BASE_IMAGE=${{ steps.build-args.outputs.FINAL_BASE_IMAGE }}
FINAL_BASE_IMAGE_TAG=${{ steps.build-args.outputs.FINAL_BASE_IMAGE_TAG }}
FINAL_BASE_IMAGE_DIGEST=${{ steps.build-args.outputs.FINAL_BASE_IMAGE_DIGEST }}
GIT_HASH=${{ steps.build-args.outputs.GIT_HASH }}
GIT_SHORT_HASH=${{ steps.build-args.outputs.GIT_SHORT_HASH }}
CREATION_DATE=${{ steps.build-args.outputs.CREATION_DATE }}
GIT_TAG=${{ steps.build-args.outputs.GIT_TAG }}
GIT_IS_DIRTY=false
VERSION=${{ steps.build-args.outputs.VERSION }}
- name: Test Docker image (x86)
run: utils/devel/test_docker_image.sh hictk:x86
- name: Build Docker image (arm64)
if: github.event_name != 'pull_request'
uses: docker/build-push-action@v6
with:
context: ${{ github.workspace }}
push: false
cache-from: type=registry,ref=${{ steps.build-args.outputs.CACHE_REGISTRY_ARM64 }}
cache-to: type=registry,ref=${{ steps.build-args.outputs.CACHE_REGISTRY_ARM64 }},mode=max,compression=zstd
tags: hictk:arm64
platforms: linux/arm64
build-args: |
C_COMPILER=${{ steps.build-args.outputs.C_COMPILER }}
CXX_COMPILER=${{ steps.build-args.outputs.CXX_COMPILER }}
BUILD_BASE_IMAGE=${{ steps.build-args.outputs.BUILD_BASE_IMAGE }}
TEST_BASE_IMAGE=${{ steps.build-args.outputs.TEST_BASE_IMAGE }}
FINAL_BASE_IMAGE=${{ steps.build-args.outputs.FINAL_BASE_IMAGE }}
FINAL_BASE_IMAGE_TAG=${{ steps.build-args.outputs.FINAL_BASE_IMAGE_TAG }}
FINAL_BASE_IMAGE_DIGEST=${{ steps.build-args.outputs.FINAL_BASE_IMAGE_DIGEST }}
GIT_HASH=${{ steps.build-args.outputs.GIT_HASH }}
GIT_SHORT_HASH=${{ steps.build-args.outputs.GIT_SHORT_HASH }}
CREATION_DATE=${{ steps.build-args.outputs.CREATION_DATE }}
GIT_TAG=${{ steps.build-args.outputs.GIT_TAG }}
GIT_IS_DIRTY=false
VERSION=${{ steps.build-args.outputs.VERSION }}
- name: Push image to registries
if: github.event_name != 'pull_request'
uses: docker/build-push-action@v6
with:
context: ${{ github.workspace }}
push: true
cache-from: |
type=registry,ref=${{ steps.build-args.outputs.CACHE_REGISTRY_X86 }}
type=registry,ref=${{ steps.build-args.outputs.CACHE_REGISTRY_ARM64 }}
tags: ${{ steps.meta.outputs.tags }}
platforms: linux/amd64,linux/arm64
build-args: |
C_COMPILER=${{ steps.build-args.outputs.C_COMPILER }}
CXX_COMPILER=${{ steps.build-args.outputs.CXX_COMPILER }}
BUILD_BASE_IMAGE=${{ steps.build-args.outputs.BUILD_BASE_IMAGE }}
TEST_BASE_IMAGE=${{ steps.build-args.outputs.TEST_BASE_IMAGE }}
FINAL_BASE_IMAGE=${{ steps.build-args.outputs.FINAL_BASE_IMAGE }}
FINAL_BASE_IMAGE_TAG=${{ steps.build-args.outputs.FINAL_BASE_IMAGE_TAG }}
FINAL_BASE_IMAGE_DIGEST=${{ steps.build-args.outputs.FINAL_BASE_IMAGE_DIGEST }}
GIT_HASH=${{ steps.build-args.outputs.GIT_HASH }}
GIT_SHORT_HASH=${{ steps.build-args.outputs.GIT_SHORT_HASH }}
CREATION_DATE=${{ steps.build-args.outputs.CREATION_DATE }}
GIT_TAG=${{ steps.build-args.outputs.GIT_TAG }}
GIT_IS_DIRTY=false
VERSION=${{ steps.build-args.outputs.VERSION }}
build-dockerfile-status-check:
name: Status Check (Build Dockerfile)
if: ${{ always() }}
runs-on: ubuntu-latest
needs:
- build-dockerfile
steps:
- name: Collect job results
if: needs.build-dockerfile.result != 'success'
run: exit 1