-
-
Notifications
You must be signed in to change notification settings - Fork 137
212 lines (191 loc) · 7.51 KB
/
Copy pathbuild-arm-intel.yml
File metadata and controls
212 lines (191 loc) · 7.51 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
209
210
211
212
# This workflow builds and pushes a multi-architecture Docker image for both AMD64 and ARM64.
# Each architecture is built NATIVELY on its own runner (no QEMU emulation) to avoid
# "Illegal instruction" crashes caused by QEMU-compiled binaries on real ARM hardware.
# After both builds complete, a manifest is created to combine them into a single multi-arch tag.
#
# Tags are automatically generated based on the triggering event:
# - push to main (e.g. a merged PR) -> 'devel'
# - version tags (e.g., v1.2.3) -> 'latest' + version number (e.g., '1.2.3')
name: Build, Test, and Push AudioMuse AI Docker Image INTEL and ARM
on:
push:
branches:
- main # Trigger on merge/push to main -> 'devel' tag
tags:
- 'v*.*.*' # Trigger for version tags like v1.0.0
pull_request:
types:
- opened
- reopened
- synchronize
# Allow manual runs for debugging or manual pushes
workflow_dispatch:
# Prevent concurrent builds for the same branch/tag - a new push cancels the in-progress build.
# This avoids race conditions where two builds overwrite each other's temporary tags.
concurrency:
group: build-${{ github.ref }}
cancel-in-progress: true
env:
REGISTRY: ghcr.io
jobs:
# ============================================================================
# Step 1: Compute image name and tags once (shared by all jobs)
# ============================================================================
prepare:
# Run on non-PR events; for PR events skip drafts and fork PRs (the
# latter only get a read-only GITHUB_TOKEN and cannot push to ghcr.io).
# Maintainers can build a fork PR manually via workflow_dispatch.
if: >-
github.event_name != 'pull_request' ||
(github.event.pull_request.draft == false &&
github.event.pull_request.head.repo.full_name == github.repository)
runs-on: ubuntu-latest
permissions: {}
outputs:
image: ${{ steps.repo_name.outputs.image }}
tags: ${{ steps.tags.outputs.tags }}
suffix: ${{ steps.tags.outputs.suffix }}
steps:
- name: Set lower-case image name
id: repo_name
run: echo "image=ghcr.io/$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT
- name: Compute tags
id: tags
run: |
TAGS=""
SUFFIX=""
if [[ "${{ github.ref }}" == refs/tags/v* ]]; then
VERSION="${{ github.ref_name }}"
VERSION="${VERSION#v}"
TAGS="latest ${VERSION}"
SUFFIX="release"
elif [[ "${{ github.ref }}" == refs/heads/main ]]; then
TAGS="devel"
SUFFIX="devel"
elif [[ "${{ github.event_name }}" == "pull_request" && "${{ github.event.pull_request.draft }}" == "false" ]]; then
PR_NUM="${{ github.event.pull_request.number }}"
TAGS="pr-${PR_NUM}"
SUFFIX="pr-${PR_NUM}"
echo "Building PR image tag: ${TAGS}"
fi
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
echo "suffix=${SUFFIX}" >> $GITHUB_OUTPUT
echo "Tags to build: ${TAGS} (suffix: ${SUFFIX})"
# ============================================================================
# Step 2: Build each architecture NATIVELY (no QEMU)
# ============================================================================
build-amd64:
needs: prepare
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Free Disk Space
uses: jlumbroso/free-disk-space@main
with:
swap-storage: false
large-packages: true
tool-cache: true
android: true
dotnet: true
haskell: true
docker-images: true
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push AMD64 image
uses: docker/build-push-action@v5
with:
context: ${{ github.workspace }}
file: Dockerfile
platforms: linux/amd64
push: true
tags: ${{ needs.prepare.outputs.image }}:build-amd64-${{ needs.prepare.outputs.suffix }}
cache-from: type=gha,scope=amd64-${{ github.ref_name }}
cache-to: type=gha,scope=amd64-${{ github.ref_name }},mode=max
build-arm64:
needs: prepare
runs-on: ubuntu-24.04-arm # Native ARM64 runner - no QEMU emulation
permissions:
contents: read
packages: write
steps:
- name: Free Disk Space
uses: jlumbroso/free-disk-space@main
with:
swap-storage: false
large-packages: true
tool-cache: true
android: true
dotnet: true
haskell: true
docker-images: true
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push ARM64 image
uses: docker/build-push-action@v5
with:
context: ${{ github.workspace }}
file: Dockerfile
platforms: linux/arm64
push: true
tags: ${{ needs.prepare.outputs.image }}:build-arm64-${{ needs.prepare.outputs.suffix }}
cache-from: type=gha,scope=arm64-${{ github.ref_name }}
cache-to: type=gha,scope=arm64-${{ github.ref_name }},mode=max
# ============================================================================
# Step 3: Merge into a single multi-arch manifest
# ============================================================================
merge-manifest:
needs: [prepare, build-amd64, build-arm64]
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create and push multi-arch manifest
run: |
IMAGE="${{ needs.prepare.outputs.image }}"
TAGS="${{ needs.prepare.outputs.tags }}"
AMD64="${IMAGE}:build-amd64-${{ needs.prepare.outputs.suffix }}"
ARM64="${IMAGE}:build-arm64-${{ needs.prepare.outputs.suffix }}"
for TAG in $TAGS; do
echo "Creating manifest for ${IMAGE}:${TAG}..."
docker buildx imagetools create \
--tag "${IMAGE}:${TAG}" \
"${AMD64}" \
"${ARM64}"
echo "OK: Pushed ${IMAGE}:${TAG}"
done
- name: Verify multi-arch manifest
run: |
IMAGE="${{ needs.prepare.outputs.image }}"
TAGS="${{ needs.prepare.outputs.tags }}"
for TAG in $TAGS; do
echo "=== Inspecting ${IMAGE}:${TAG} ==="
docker buildx imagetools inspect "${IMAGE}:${TAG}"
done
# NOTE: Temporary per-arch tags (build-amd64-*, build-arm64-*) are left in the registry.
# They get overwritten on every build, so at most 2 stale tags exist at any time.
# Delete them manually from the GitHub Packages UI if desired.