Skip to content

Commit c4f876f

Browse files
committed
feat: multiarch build support
1 parent 91f0f4b commit c4f876f

3 files changed

Lines changed: 151 additions & 1 deletion

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: "Docker Manifest Create & Push"
2+
description: "Create OCI manifest list for multi-arch images and push to registry"
3+
author: "babelcloud"
4+
inputs:
5+
manifest-list:
6+
description: "Final manifest list name (e.g. ghcr.io/owner/repo:tag)"
7+
required: true
8+
manifests:
9+
description: "Comma separated list of image references to include"
10+
required: true
11+
post-clean:
12+
description: "Remove manifest list locally after push"
13+
required: false
14+
default: "false"
15+
runs:
16+
using: "composite"
17+
steps:
18+
- shell: bash
19+
run: |
20+
set -euo pipefail
21+
MANIFEST_LIST="${{ inputs.manifest-list }}"
22+
MANIFESTS="${{ inputs.manifests }}"
23+
IFS=',' read -ra IMAGES <<< "$MANIFESTS"
24+
echo "📦 Creating manifest list $MANIFEST_LIST with: ${IMAGES[*]}"
25+
docker manifest create "$MANIFEST_LIST" "${IMAGES[@]}"
26+
docker manifest push "$MANIFEST_LIST"
27+
if [[ "${{ inputs.post-clean }}" == "true" ]]; then
28+
docker manifest rm "$MANIFEST_LIST" || true
29+
fi
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
name: Build & Publish Multi-Arch Appium Image
2+
3+
on:
4+
# Manual trigger (custom tag optional)
5+
workflow_dispatch:
6+
inputs:
7+
tag:
8+
description: "Image tag (default: commit SHA)"
9+
type: string
10+
required: false
11+
default: ""
12+
push:
13+
description: "Push image to registry"
14+
type: boolean
15+
required: false
16+
default: false
17+
push:
18+
branches: ["**"]
19+
tags: ["*"]
20+
pull_request:
21+
22+
jobs:
23+
prepare:
24+
runs-on: ubuntu-24.04
25+
outputs:
26+
matrix: ${{ steps.set-matrix.outputs.matrix }}
27+
tag: ${{ steps.set-tag.outputs.tag }}
28+
steps:
29+
- uses: actions/checkout@v4
30+
31+
- id: set-tag
32+
name: Compute image tag
33+
run: |
34+
TAG_INPUT='${{ github.event.inputs.tag }}'
35+
if [[ -n "$TAG_INPUT" ]]; then
36+
TAG="$TAG_INPUT"
37+
elif [[ "${{ github.ref }}" == refs/tags/* ]]; then
38+
TAG="${GITHUB_REF##*/}"
39+
else
40+
TAG="$(git rev-parse --short HEAD)"
41+
fi
42+
echo "tag=$TAG" | tee -a "$GITHUB_OUTPUT"
43+
44+
- id: set-matrix
45+
name: Generate build matrix
46+
run: |
47+
TAG='${{ steps.set-tag.outputs.tag }}'
48+
MATRIX=$(jq -nc --arg tag "$TAG" '{include:[{"arch":"amd64","platform":"linux/amd64","suffix":"-amd64","tag":$tag},{"arch":"arm64","platform":"linux/arm64","suffix":"-arm64","tag":$tag}]}')
49+
echo "matrix=$MATRIX" | tee -a "$GITHUB_OUTPUT"
50+
51+
build:
52+
needs: prepare
53+
name: Build (${{ matrix.arch }})
54+
runs-on: ${{ matrix.arch == 'arm64' && 'ubuntu-24.04-arm64' || 'ubuntu-24.04' }}
55+
strategy:
56+
fail-fast: false
57+
matrix: ${{ fromJson(needs.prepare.outputs.matrix) }}
58+
permissions:
59+
contents: read
60+
packages: write
61+
env:
62+
REGISTRY: ghcr.io
63+
IMAGE_NAME: babelcloud/appium
64+
steps:
65+
- uses: actions/checkout@v4
66+
67+
- name: Set up Buildx
68+
uses: docker/setup-buildx-action@v3
69+
70+
- name: Login to GitHub Container Registry
71+
uses: docker/login-action@v3
72+
with:
73+
registry: ${{ env.REGISTRY }}
74+
username: ${{ secrets.GH_TOKEN_USER }}
75+
password: ${{ secrets.GH_TOKEN }}
76+
77+
- id: tag-list
78+
name: Generate architecture-specific tags
79+
run: |
80+
FULL_TAG="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ matrix.tag }}${{ matrix.suffix }}"
81+
echo "list=$FULL_TAG" | tee -a "$GITHUB_OUTPUT"
82+
83+
- name: Build & (optional) Push
84+
uses: docker/build-push-action@v5
85+
with:
86+
context: ./Appium
87+
file: ./Appium/Dockerfile
88+
platforms: ${{ matrix.platform }}
89+
tags: ${{ steps.tag-list.outputs.list }}
90+
push: true
91+
provenance: false
92+
cache-from: type=registry,ref=ghcr.io/babelcloud/appium:buildcache-${{ matrix.arch }}
93+
cache-to: type=registry,ref=ghcr.io/babelcloud/appium:buildcache-${{ matrix.arch }},mode=max
94+
95+
manifest:
96+
needs: [prepare, build]
97+
if: ${{ success() && ((github.event_name == 'workflow_dispatch' && github.event.inputs.push == 'true') || startsWith(github.ref, 'refs/tags/')) }}
98+
runs-on: ubuntu-24.04
99+
permissions:
100+
contents: read
101+
packages: write
102+
env:
103+
REGISTRY: ghcr.io
104+
IMAGE_NAME: babelcloud/appium
105+
TAG: ${{ needs.prepare.outputs.tag }}
106+
steps:
107+
- uses: actions/checkout@v4
108+
109+
- name: Login to GitHub Container Registry
110+
uses: docker/login-action@v3
111+
with:
112+
registry: ${{ env.REGISTRY }}
113+
username: ${{ secrets.GH_TOKEN_USER }}
114+
password: ${{ secrets.GH_TOKEN }}
115+
116+
- name: Create & Push Manifest
117+
uses: ./.github/actions/docker-manifest-create-push
118+
with:
119+
manifest-list: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.TAG }}
120+
manifests: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.TAG }}-amd64,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.TAG }}-arm64
121+
post-clean: true

Appium/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ RUN apt-get -qqy update && \
4848
#===============
4949
# Set JAVA_HOME
5050
#===============
51-
ENV JAVA_HOME="/usr/lib/jvm/java-17-openjdk-amd64" \
51+
ENV JAVA_HOME="/usr/lib/jvm/java-11-openjdk-${TARGETARCH:-amd64}" \
5252
PATH=$PATH:$JAVA_HOME/bin
5353

5454
#===============================

0 commit comments

Comments
 (0)