Skip to content

Commit 842782a

Browse files
committed
feat: initial multiarch image
0 parents  commit 842782a

7 files changed

Lines changed: 1892 additions & 0 deletions

File tree

Lines changed: 268 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,268 @@
1+
name: Build and Push Application Image
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: ["main"]
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: read
11+
packages: write
12+
13+
defaults:
14+
run:
15+
shell: bash
16+
17+
env:
18+
REGISTRY: ghcr.io
19+
IMAGE_NAME: ${{ github.repository }}/my-cuda-app
20+
21+
jobs:
22+
create_local_images:
23+
strategy:
24+
fail-fast: false
25+
matrix:
26+
arch: ["amd64", "arm64"]
27+
runs-on: ${{ matrix.arch == 'arm64' && 'ubuntu-24.04-arm' || 'ubuntu-24.04' }}
28+
steps:
29+
30+
- name: Free Disk Space (Ubuntu)
31+
uses: jlumbroso/free-disk-space@main
32+
with:
33+
# this might remove tools that are actually needed,
34+
# if set to "true" but frees about 6 GB
35+
tool-cache: true
36+
37+
# all of these default to true, but feel free to set to
38+
# "false" if necessary for your workflow
39+
android: true
40+
dotnet: true
41+
haskell: true
42+
large-packages: true
43+
docker-images: true
44+
swap-storage: true
45+
46+
- name: Checkout
47+
uses: actions/checkout@v4
48+
49+
- name: Set up Docker Buildx
50+
uses: docker/setup-buildx-action@v3
51+
with:
52+
driver-opts: |
53+
image=moby/buildkit:v0.12.0
54+
network=host
55+
56+
- name: Install Pack CLI
57+
uses: buildpacks/github-actions/setup-pack@v5.9.4
58+
59+
- name: Build CUDA Build Image (local only)
60+
run: |
61+
docker build -t cuda-build-run:latest -f Dockerfile \
62+
--platform linux/${{ matrix.arch }} .
63+
64+
- name: Create Builder Image (local only)
65+
run: |
66+
pack builder create cuda-builder:latest \
67+
--config builder.toml \
68+
--pull-policy if-not-present
69+
70+
- name: Export Docker images from the Docker daemon
71+
run: |
72+
docker save cuda-builder:latest cuda-build-run:latest | \
73+
zstd -T0 --long=31 -o images.tar.zst
74+
75+
- name: Save Docker images to the cache
76+
uses: actions/cache/save@v4
77+
with:
78+
key: ${{ github.run_id }}-cuda-images-${{ matrix.arch }}
79+
path: images.tar.zst
80+
81+
build_application_image:
82+
runs-on: ${{ matrix.arch == 'arm64' && 'ubuntu-24.04-arm' || 'ubuntu-24.04' }}
83+
needs: create_local_images
84+
strategy:
85+
fail-fast: false
86+
matrix:
87+
arch: ["amd64", "arm64"]
88+
steps:
89+
- name: Free Disk Space (Ubuntu)
90+
uses: jlumbroso/free-disk-space@main
91+
with:
92+
# this might remove tools that are actually needed,
93+
# if set to "true" but frees about 6 GB
94+
tool-cache: true
95+
96+
# all of these default to true, but feel free to set to
97+
# "false" if necessary for your workflow
98+
android: true
99+
dotnet: true
100+
haskell: true
101+
large-packages: true
102+
docker-images: true
103+
swap-storage: true
104+
105+
- name: Maximize Disk Space (Aggressive)
106+
run: |
107+
echo "Available space before cleanup:"
108+
df -h
109+
# Remove Java (JDKs)
110+
sudo rm -rf /usr/lib/jvm
111+
112+
# Remove .NET SDKs
113+
sudo rm -rf /usr/share/dotnet
114+
115+
# Remove Swift toolchain
116+
sudo rm -rf /usr/share/swift
117+
118+
# Remove Haskell (GHC)
119+
sudo rm -rf /usr/local/.ghcup
120+
121+
# Remove Julia
122+
sudo rm -rf /usr/local/julia*
123+
124+
# Remove Android SDKs
125+
sudo rm -rf /usr/local/lib/android
126+
127+
# Remove Chromium (optional if not using for browser tests)
128+
sudo rm -rf /usr/local/share/chromium
129+
130+
# Remove Microsoft/Edge and Google Chrome builds
131+
sudo rm -rf /opt/microsoft /opt/google
132+
133+
# Remove Azure CLI
134+
sudo rm -rf /opt/az
135+
136+
# Remove PowerShell
137+
sudo rm -rf /usr/local/share/powershell
138+
139+
# Remove CodeQL and other toolcaches
140+
sudo rm -rf /opt/hostedtoolcache
141+
142+
docker system prune -af || true
143+
docker builder prune -af || true
144+
145+
146+
echo "Available space after cleanup:"
147+
df -h
148+
149+
- name: Checkout
150+
uses: actions/checkout@v4
151+
152+
- name: Install Pack CLI
153+
uses: buildpacks/github-actions/setup-pack@v5.9.4
154+
155+
- name: Configure Docker for Large Images
156+
run: |
157+
sudo systemctl stop docker
158+
echo '{"storage-driver": "overlay2", "max-concurrent-downloads": 1, "max-concurrent-uploads": 1, "log-driver": "none"}' | sudo tee /etc/docker/daemon.json
159+
sudo systemctl start docker
160+
docker system prune -af --volumes
161+
162+
- name: Restore Docker images from the cache
163+
uses: actions/cache/restore@v4
164+
with:
165+
fail-on-cache-miss: true
166+
key: ${{ github.run_id }}-cuda-images-${{ matrix.arch }}
167+
path: images.tar.zst
168+
env:
169+
SEGMENT_DOWNLOAD_TIMEOUT_MINS: 1
170+
171+
- name: Load Docker images into the Docker daemon
172+
run: |
173+
zstd -dc --long=31 images.tar.zst | docker load
174+
rm -rf images.tar.zst
175+
176+
- name: Build Application Image
177+
run: |
178+
IMAGE_NAME_LOWER=$(echo "${{ env.IMAGE_NAME }}" | tr '[:upper:]' '[:lower:]')
179+
pack build ${{ env.REGISTRY }}/${IMAGE_NAME_LOWER}:${{ github.sha }}_linux-${{ matrix.arch }} \
180+
--builder cuda-builder:latest \
181+
--trust-builder \
182+
--pull-policy never \
183+
--platform linux/${{ matrix.arch }}
184+
185+
- name: Export Application Image
186+
run: |
187+
IMAGE_NAME_LOWER=$(echo "${{ env.IMAGE_NAME }}" | tr '[:upper:]' '[:lower:]')
188+
docker save ${{ env.REGISTRY }}/${IMAGE_NAME_LOWER}:${{ github.sha }}_linux-${{ matrix.arch }} | \
189+
zstd -T0 --long=31 -o app-image.tar.zst
190+
191+
- name: Save Application Image to cache
192+
uses: actions/cache/save@v4
193+
with:
194+
key: ${{ github.run_id }}-app-image-${{ matrix.arch }}
195+
path: app-image.tar.zst
196+
197+
push_application_image:
198+
runs-on: ubuntu-24.04
199+
if: success() && github.ref == 'refs/heads/main'
200+
needs: build_application_image
201+
strategy:
202+
fail-fast: false
203+
matrix:
204+
arch: ["amd64", "arm64"]
205+
steps:
206+
- name: Free Disk Space (Ubuntu)
207+
uses: jlumbroso/free-disk-space@main
208+
with:
209+
# this might remove tools that are actually needed,
210+
# if set to "true" but frees about 6 GB
211+
tool-cache: true
212+
213+
# all of these default to true, but feel free to set to
214+
# "false" if necessary for your workflow
215+
android: true
216+
dotnet: true
217+
haskell: true
218+
large-packages: true
219+
docker-images: true
220+
swap-storage: true
221+
222+
- name: Log in to Container Registry
223+
uses: docker/login-action@v3
224+
with:
225+
registry: ${{ env.REGISTRY }}
226+
username: ${{ github.actor }}
227+
password: ${{ secrets.GITHUB_TOKEN }}
228+
229+
- name: Restore Application Image from cache
230+
uses: actions/cache/restore@v4
231+
with:
232+
fail-on-cache-miss: true
233+
key: ${{ github.run_id }}-app-image-${{ matrix.arch }}
234+
path: app-image.tar.zst
235+
236+
- name: Load and Push Application Image
237+
run: |
238+
zstd -dc --long=31 app-image.tar.zst | docker load
239+
IMAGE_NAME_LOWER=$(echo "${{ env.IMAGE_NAME }}" | tr '[:upper:]' '[:lower:]')
240+
docker push ${{ env.REGISTRY }}/${IMAGE_NAME_LOWER}:${{ github.sha }}_linux-${{ matrix.arch }}
241+
242+
create_manifest:
243+
runs-on: ubuntu-24.04
244+
needs: push_application_image
245+
if: success() && github.ref == 'refs/heads/main'
246+
steps:
247+
- name: Log in to Container Registry
248+
uses: docker/login-action@v3
249+
with:
250+
registry: ${{ env.REGISTRY }}
251+
username: ${{ github.actor }}
252+
password: ${{ secrets.GITHUB_TOKEN }}
253+
254+
- name: Create and push manifest lists
255+
run: |
256+
# Create manifest for commit SHA
257+
IMAGE_NAME_LOWER=$(echo "${{ env.IMAGE_NAME }}" | tr '[:upper:]' '[:lower:]')
258+
docker manifest create ${{ env.REGISTRY }}/${IMAGE_NAME_LOWER}:${{ github.sha }} \
259+
${{ env.REGISTRY }}/${IMAGE_NAME_LOWER}:${{ github.sha }}_linux-amd64 \
260+
${{ env.REGISTRY }}/${IMAGE_NAME_LOWER}:${{ github.sha }}_linux-arm64
261+
docker manifest push ${{ env.REGISTRY }}/${IMAGE_NAME_LOWER}:${{ github.sha }}
262+
263+
# Create manifest for latest tag
264+
docker manifest create ${{ env.REGISTRY }}/${IMAGE_NAME_LOWER}:latest \
265+
${{ env.REGISTRY }}/${IMAGE_NAME_LOWER}:${{ github.sha }}_linux-amd64 \
266+
${{ env.REGISTRY }}/${IMAGE_NAME_LOWER}:${{ github.sha }}_linux-arm64
267+
docker manifest push ${{ env.REGISTRY }}/${IMAGE_NAME_LOWER}:latest
268+

0 commit comments

Comments
 (0)