-
Notifications
You must be signed in to change notification settings - Fork 276
191 lines (162 loc) · 6.35 KB
/
Container.yml
File metadata and controls
191 lines (162 loc) · 6.35 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
# Based on:
# * <https://docs.github.com/en/actions/publishing-packages/publishing-docker-images>
# * <https://docs.docker.com/build/ci/github-actions/multi-platform/#distribute-build-across-multiple-runners>
name: Publish Docker container
on:
push:
tags:
- 'v*'
branches:
- main
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
JULIA_VERSION: "1.12"
jobs:
build:
name: Container for ${{ matrix.platform }} - CUDA ${{ matrix.cuda }}
permissions:
contents: read
packages: write
strategy:
matrix:
cuda: ["12.9", "13.2"]
platform: ["linux/amd64"]
os: ["ubuntu-24.04"]
include:
# Additional arm64 build for the latest CUDA version.
- cuda: "13.2"
platform: "linux/arm64"
os: "ubuntu-24.04-arm"
runs-on: ${{ matrix.os }}
steps:
- name: Check out the repo
uses: actions/checkout@v6
- name: Compute build variables
id: vars
run: |
# Docker rejects uppercase image names.
image=$(echo "${IMAGE_NAME}" | tr 'A-Z' 'a-z')
echo "image=${image}" >> $GITHUB_OUTPUT
cuda_major=$(echo ${{ matrix.cuda }} | cut -d'.' -f1)
echo "variant=cuda${cuda_major}" >> $GITHUB_OUTPUT
# platform is e.g. linux/amd64 — use a slug for filenames and artifact names.
echo "platform_slug=$(echo "${{ matrix.platform }}" | tr / -)" >> $GITHUB_OUTPUT
version=$(grep "^version = " Project.toml | cut -d'"' -f2)
echo "version=${version}" >> $GITHUB_OUTPUT
if [[ "${{ matrix.platform }}" == "linux/amd64" ]]; then
echo "cpu_target=generic;sandybridge,-xsaveopt,clone_all;haswell,-rdrnd,base(1)" >> $GITHUB_OUTPUT
elif [[ "${{ matrix.platform }}" == "linux/arm64" ]]; then
echo "cpu_target=generic;cortex-a57;thunderx2t99;carmel,clone_all;apple-m1,base(3);neoverse-512tvb,base(3)" >> $GITHUB_OUTPUT
fi
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to registry
uses: docker/login-action@v4
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push image by digest
id: build
uses: docker/build-push-action@v7
with:
context: .
platforms: ${{ matrix.platform }}
provenance: false
labels: |
org.opencontainers.image.version=${{ steps.vars.outputs.version }}
outputs: type=image,name=${{ env.REGISTRY }}/${{ steps.vars.outputs.image }},push-by-digest=true,name-canonical=true,push=true
build-args: |
JULIA_VERSION=${{ env.JULIA_VERSION }}
CUDA_VERSION=${{ matrix.cuda }}
PACKAGE_REF=${{ github.ref_type == 'tag' && github.ref_name || github.sha }}
JULIA_CPU_TARGET=${{ steps.vars.outputs.cpu_target }}
- name: Export digest
run: |
mkdir -p /tmp/digests
# "__" separator avoids collisions with hyphens in either part.
echo "${{ steps.build.outputs.digest }}" \
> "/tmp/digests/${{ steps.vars.outputs.variant }}__${{ steps.vars.outputs.platform_slug }}"
- name: Upload digest
uses: actions/upload-artifact@v7
with:
name: digest-${{ steps.vars.outputs.variant }}-${{ steps.vars.outputs.platform_slug }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
merge:
name: Merge multi-arch manifests
needs: build
runs-on: ubuntu-24.04
permissions:
contents: read
packages: write
steps:
- name: Lowercase image name
id: image
run: |
echo "name=$(echo "${IMAGE_NAME}" | tr 'A-Z' 'a-z')" >> $GITHUB_OUTPUT
- name: Classify ref
id: ref
run: |
# base_name: the version-like prefix used in `<base>-cuda<c>` tags.
# is_stable: whether to additionally publish the bare `cuda<c>` alias
# (i.e. on non-prerelease release tag pushes).
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
echo "base_name=${GITHUB_REF_NAME}" >> $GITHUB_OUTPUT
if [[ "${GITHUB_REF_NAME}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "is_stable=true" >> $GITHUB_OUTPUT
else
echo "is_stable=false" >> $GITHUB_OUTPUT
fi
else
echo "base_name=dev" >> $GITHUB_OUTPUT
echo "is_stable=false" >> $GITHUB_OUTPUT
fi
- name: Download digests
uses: actions/download-artifact@v8
with:
path: /tmp/digests
pattern: digest-*
merge-multiple: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to registry
uses: docker/login-action@v4
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create manifest lists
env:
IMAGE: ${{ env.REGISTRY }}/${{ steps.image.outputs.name }}
BASE_NAME: ${{ steps.ref.outputs.base_name }}
IS_STABLE: ${{ steps.ref.outputs.is_stable }}
run: |
set -euo pipefail
# Group digest files by variant (everything before "__").
declare -A variants
for file in /tmp/digests/*; do
name=${file##*/}
variants[${name%%__*}]=1
done
for variant in "${!variants[@]}"; do
sources=()
for file in /tmp/digests/"${variant}"__*; do
sources+=("${IMAGE}@$(cat "${file}")")
done
# Always: <base>-<variant> (e.g. v6.1.0-cuda13, dev-cuda13)
tags=("${IMAGE}:${BASE_NAME}-${variant}")
# On stable releases, additionally publish the bare <variant>
# alias (e.g. cuda13) pointing at the latest stable release.
if [[ "${IS_STABLE}" == "true" ]]; then
tags+=("${IMAGE}:${variant}")
fi
tag_args=()
for tag in "${tags[@]}"; do
tag_args+=(--tag "${tag}")
done
echo "Creating manifest ${tags[*]} from ${#sources[@]} platforms"
docker buildx imagetools create "${tag_args[@]}" "${sources[@]}"
done