-
Notifications
You must be signed in to change notification settings - Fork 229
208 lines (194 loc) · 7.18 KB
/
container_images.yml
File metadata and controls
208 lines (194 loc) · 7.18 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
name: Build CI Container Images
on:
workflow_dispatch:
pull_request:
paths:
- ".github/workflows/container_images.yml"
- "container/**"
push:
branches:
- main
paths:
- ".github/workflows/container_images.yml"
- "container/**"
env:
REGISTRY: ghcr.io
jobs:
build-images:
name: Build ${{ matrix.variance.name }} (${{ matrix.platform.arch }})
runs-on: ${{ matrix.platform.runner }}
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
platform:
- runner: ubuntu-latest
arch: amd64
- runner: ubuntu-24.04-arm
arch: arm64
variance:
- name: Ubuntu-24.04/CUDA-12.8.1
image: "rust-gpu/rust-cuda-ubuntu24-cuda12"
dockerfile: ./container/ubuntu24-cuda12/Dockerfile
- name: Ubuntu-24.04/CUDA-13.0.2
image: "rust-gpu/rust-cuda-ubuntu24-cuda13"
dockerfile: ./container/ubuntu24-cuda13/Dockerfile
- name: RockyLinux-9/CUDA-12.8.1
image: "rust-gpu/rust-cuda-rockylinux9-cuda12"
dockerfile: ./container/rockylinux9-cuda12/Dockerfile
- name: RockyLinux-9/CUDA-13.0.2
image: "rust-gpu/rust-cuda-rockylinux9-cuda13"
dockerfile: ./container/rockylinux9-cuda13/Dockerfile
steps:
- name: Free up space
# Without this the job will likely run out of disk space.
run: |
df -h
# Remove Java
sudo rm -rf /usr/lib/jvm
# Remove .NET
sudo rm -rf /usr/share/dotnet
# Remove Swift
sudo rm -rf /usr/share/swift
# Remove Haskell
sudo rm -rf /usr/local/.ghcup
# Remove Julia
sudo rm -rf /usr/local/julia*
# Remove Android SDKs
sudo rm -rf /usr/local/lib/android
# Remove Chromium
sudo rm -rf /usr/local/share/chromium
# Remove Microsoft/Edge and Google Chrome builds
sudo rm -rf /opt/microsoft /opt/google
# Remove Azure CLI
sudo rm -rf /opt/az
# Remove PowerShell
sudo rm -rf /usr/local/share/powershell
# Remove CodeQL and other toolcaches
sudo rm -rf /opt/hostedtoolcache
docker system prune -af || true
docker builder prune -af || true
df -h
- name: Checkout repository
uses: actions/checkout@v4
- name: Validate platform
run: |
ARCH=$(uname -m)
if [[ "${{ matrix.platform.arch }}" == "amd64" && "$ARCH" != "x86_64" ]]; then
echo "Error: Expected x86_64 but got $ARCH"
exit 1
fi
if [[ "${{ matrix.platform.arch }}" == "arm64" && "$ARCH" != "aarch64" ]]; then
echo "Error: Expected aarch64 but got $ARCH"
exit 1
fi
echo "Platform validation passed: $ARCH matches ${{ matrix.platform.arch }}"
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for containers
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ matrix.variance.image }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push by digest
id: build
uses: docker/build-push-action@v6
with:
context: .
file: ${{ matrix.variance.dockerfile }}
platforms: linux/${{ matrix.platform.arch }}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=${{ env.REGISTRY }}/${{ matrix.variance.image }},push-by-digest=true,name-canonical=true,push=${{ github.event_name != 'pull_request' }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Set artifact name
if: github.event_name != 'pull_request'
run: |
ARTIFACT_NAME="${{ matrix.variance.image }}"
ARTIFACT_NAME="${ARTIFACT_NAME#*/}" # Remove everything before and including the slash
echo "ARTIFACT_NAME=$ARTIFACT_NAME" >> $GITHUB_ENV
- name: Export digest
if: github.event_name != 'pull_request'
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
if: github.event_name != 'pull_request'
uses: actions/upload-artifact@v4
with:
name: digests-${{ env.ARTIFACT_NAME }}-${{ matrix.platform.arch }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
merge-manifests:
name: Create manifest for ${{ matrix.variance.name }}
runs-on: ubuntu-latest
if: github.event_name != 'pull_request'
needs: build-images
permissions:
contents: read
packages: write
attestations: write
id-token: write
strategy:
fail-fast: false
matrix:
variance:
- name: Ubuntu-24.04/CUDA-12.8.1
image: "rust-gpu/rust-cuda-ubuntu24-cuda12"
- name: Ubuntu-24.04/CUDA-13.0.2
image: "rust-gpu/rust-cuda-ubuntu24-cuda13"
- name: RockyLinux-9/CUDA-12.8.1
image: "rust-gpu/rust-cuda-rockylinux9-cuda12"
- name: RockyLinux-9/CUDA-13.0.2
image: "rust-gpu/rust-cuda-rockylinux9-cuda13"
steps:
- name: Set artifact name
run: |
ARTIFACT_NAME="${{ matrix.variance.image }}"
ARTIFACT_NAME="${ARTIFACT_NAME#*/}" # Remove everything before and including the slash
echo "ARTIFACT_NAME=$ARTIFACT_NAME" >> $GITHUB_ENV
- name: Download digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-${{ env.ARTIFACT_NAME }}-*
merge-multiple: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ matrix.variance.image }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha,format=short
type=raw,value=latest,enable={{is_default_branch}}
- name: Login to Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.REGISTRY }}/${{ matrix.variance.image }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ matrix.variance.image }}:${{ steps.meta.outputs.version }}