Skip to content

Commit 4c5f212

Browse files
committed
feat: Add GitHub Actions workflow for building and releasing multi-arch Docker images
1 parent b6f4794 commit 4c5f212

1 file changed

Lines changed: 187 additions & 0 deletions

File tree

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
name: Build and Release Multi-Arch Docker Images
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- 'v*'
9+
pull_request:
10+
branches:
11+
- main
12+
workflow_dispatch:
13+
14+
env:
15+
REGISTRY: ghcr.io
16+
IMAGE_NAME: ${{ github.repository }}
17+
18+
jobs:
19+
build-amd64:
20+
name: Build AMD64 - Python ${{ matrix.python-version }}
21+
runs-on: ubuntu-latest
22+
permissions:
23+
contents: read
24+
packages: write
25+
strategy:
26+
matrix:
27+
python-version: ['3.10', '3.11', '3.12', '3.13', '3.14']
28+
steps:
29+
- name: Checkout repository
30+
uses: actions/checkout@v4
31+
32+
- name: Set up Docker Buildx
33+
uses: docker/setup-buildx-action@v3
34+
35+
- name: Log in to Container Registry
36+
if: github.event_name != 'pull_request'
37+
uses: docker/login-action@v3
38+
with:
39+
registry: ${{ env.REGISTRY }}
40+
username: ${{ github.actor }}
41+
password: ${{ secrets.GITHUB_TOKEN }}
42+
43+
- name: Extract metadata
44+
id: meta
45+
uses: docker/metadata-action@v5
46+
with:
47+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
48+
tags: |
49+
type=raw,value=python${{ matrix.python-version }}-amd64-latest,enable={{is_default_branch}}
50+
type=ref,event=branch,suffix=-python${{ matrix.python-version }}-amd64
51+
type=ref,event=pr,suffix=-python${{ matrix.python-version }}-amd64
52+
type=semver,pattern={{version}},suffix=-python${{ matrix.python-version }}-amd64
53+
type=semver,pattern={{major}}.{{minor}},suffix=-python${{ matrix.python-version }}-amd64
54+
type=sha,suffix=-python${{ matrix.python-version }}-amd64
55+
56+
- name: Build and push AMD64 image
57+
uses: docker/build-push-action@v5
58+
with:
59+
context: .
60+
platforms: linux/amd64
61+
build-args: |
62+
PYTHON_VERSION=${{ matrix.python-version }}
63+
push: ${{ github.event_name != 'pull_request' }}
64+
tags: ${{ steps.meta.outputs.tags }}
65+
labels: ${{ steps.meta.outputs.labels }}
66+
cache-from: type=gha,scope=amd64-${{ matrix.python-version }}
67+
cache-to: type=gha,mode=max,scope=amd64-${{ matrix.python-version }}
68+
69+
build-arm64:
70+
name: Build ARM64 - Python ${{ matrix.python-version }}
71+
runs-on: ubuntu-24.04-arm64
72+
permissions:
73+
contents: read
74+
packages: write
75+
strategy:
76+
matrix:
77+
python-version: ['3.10', '3.11', '3.12', '3.13', '3.14']
78+
steps:
79+
- name: Checkout repository
80+
uses: actions/checkout@v4
81+
82+
- name: Set up Docker Buildx
83+
uses: docker/setup-buildx-action@v3
84+
85+
- name: Log in to Container Registry
86+
if: github.event_name != 'pull_request'
87+
uses: docker/login-action@v3
88+
with:
89+
registry: ${{ env.REGISTRY }}
90+
username: ${{ github.actor }}
91+
password: ${{ secrets.GITHUB_TOKEN }}
92+
93+
- name: Extract metadata
94+
id: meta
95+
uses: docker/metadata-action@v5
96+
with:
97+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
98+
tags: |
99+
type=raw,value=python${{ matrix.python-version }}-arm64-latest,enable={{is_default_branch}}
100+
type=ref,event=branch,suffix=-python${{ matrix.python-version }}-arm64
101+
type=ref,event=pr,suffix=-python${{ matrix.python-version }}-arm64
102+
type=semver,pattern={{version}},suffix=-python${{ matrix.python-version }}-arm64
103+
type=semver,pattern={{major}}.{{minor}},suffix=-python${{ matrix.python-version }}-arm64
104+
type=sha,suffix=-python${{ matrix.python-version }}-arm64
105+
106+
- name: Build and push ARM64 image
107+
uses: docker/build-push-action@v5
108+
with:
109+
context: .
110+
platforms: linux/arm64
111+
build-args: |
112+
PYTHON_VERSION=${{ matrix.python-version }}
113+
push: ${{ github.event_name != 'pull_request' }}
114+
tags: ${{ steps.meta.outputs.tags }}
115+
labels: ${{ steps.meta.outputs.labels }}
116+
cache-from: type=gha,scope=arm64-${{ matrix.python-version }}
117+
cache-to: type=gha,mode=max,scope=arm64-${{ matrix.python-version }}
118+
119+
create-manifest:
120+
name: Create Multi-Arch Manifest - Python ${{ matrix.python-version }}
121+
runs-on: ubuntu-latest
122+
needs: [build-amd64, build-arm64]
123+
if: github.event_name != 'pull_request'
124+
permissions:
125+
contents: read
126+
packages: write
127+
strategy:
128+
matrix:
129+
python-version: ['3.10', '3.11', '3.12', '3.13', '3.14']
130+
steps:
131+
- name: Log in to Container Registry
132+
uses: docker/login-action@v3
133+
with:
134+
registry: ${{ env.REGISTRY }}
135+
username: ${{ github.actor }}
136+
password: ${{ secrets.GITHUB_TOKEN }}
137+
138+
- name: Create and push manifest for latest
139+
if: github.ref == 'refs/heads/main'
140+
run: |
141+
docker buildx imagetools create -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:python${{ matrix.python-version }}-latest \
142+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:python${{ matrix.python-version }}-amd64-latest \
143+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:python${{ matrix.python-version }}-arm64-latest
144+
145+
- name: Create and push manifest for tags
146+
if: startsWith(github.ref, 'refs/tags/')
147+
run: |
148+
TAG_VERSION=${GITHUB_REF#refs/tags/}
149+
docker buildx imagetools create -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${TAG_VERSION}-python${{ matrix.python-version }} \
150+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${TAG_VERSION}-python${{ matrix.python-version }}-amd64 \
151+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${TAG_VERSION}-python${{ matrix.python-version }}-arm64
152+
153+
create-release:
154+
name: Create GitHub Release
155+
runs-on: ubuntu-latest
156+
needs: [create-manifest]
157+
if: startsWith(github.ref, 'refs/tags/')
158+
permissions:
159+
contents: write
160+
steps:
161+
- name: Checkout repository
162+
uses: actions/checkout@v4
163+
164+
- name: Create Release
165+
uses: softprops/action-gh-release@v1
166+
with:
167+
generate_release_notes: true
168+
body: |
169+
## Multi-Arch Docker Images
170+
171+
Images are available for Python 3.10, 3.11, 3.12, 3.13, and 3.14 on both AMD64 and ARM64 architectures.
172+
173+
### Usage
174+
175+
Pull a specific Python version:
176+
```bash
177+
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }}-python3.14
178+
```
179+
180+
The images support both AMD64 and ARM64 architectures automatically.
181+
182+
### Available Tags
183+
- `${{ github.ref_name }}-python3.10` (multi-arch)
184+
- `${{ github.ref_name }}-python3.11` (multi-arch)
185+
- `${{ github.ref_name }}-python3.12` (multi-arch)
186+
- `${{ github.ref_name }}-python3.13` (multi-arch)
187+
- `${{ github.ref_name }}-python3.14` (multi-arch)

0 commit comments

Comments
 (0)