Skip to content

Commit d9d3657

Browse files
committed
[build] add arm64 image build
1 parent 5660b0b commit d9d3657

File tree

2 files changed

+103
-18
lines changed

2 files changed

+103
-18
lines changed

.github/workflows/docker-build.yml

Lines changed: 102 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,61 +15,146 @@ on:
1515
app-version:
1616
value: ${{ jobs.build.outputs.app-version }}
1717

18+
env:
19+
DOCKERHUB_REPO: capcom6/${{ inputs.app-name }}
20+
GHCR_REPO: ghcr.io/${{ github.repository }}
21+
1822
jobs:
1923
build:
2024
name: Docker image
2125
runs-on: ubuntu-latest
22-
if: github.actor != 'dependabot[bot]' # skip on dependabot because it's not allowed to access secrets
26+
strategy:
27+
fail-fast: false
28+
matrix:
29+
platform:
30+
- linux/amd64
31+
- linux/arm64
2332
permissions:
2433
packages: write
2534
outputs:
2635
app-version: ${{ steps.meta.outputs.version }}
36+
2737
steps:
28-
- name: Checkout repository
29-
uses: actions/checkout@v4
38+
- name: Prepare
39+
run: |
40+
platform=${{ matrix.platform }}
41+
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
3042
3143
- name: Docker meta
3244
id: meta
3345
uses: docker/metadata-action@v5
3446
with:
3547
images: |
36-
capcom6/${{ inputs.app-name }}
37-
ghcr.io/${{ github.repository }}
38-
tags: |
39-
type=ref,event=branch
40-
type=ref,event=pr
41-
type=semver,pattern={{version}}
42-
type=semver,pattern={{major}}.{{minor}}
43-
type=semver,pattern={{major}}
48+
${{ env.DOCKERHUB_REPO }}
49+
${{ env.GHCR_REPO }}
4450
4551
- name: Log into Docker Hub
4652
uses: docker/login-action@v3
53+
if: github.actor != 'dependabot[bot]'
4754
with:
4855
username: ${{ secrets.username }}
4956
password: ${{ secrets.password }}
5057

5158
- name: Login to Container registry
5259
uses: docker/login-action@v3
60+
if: github.actor != 'dependabot[bot]'
5361
with:
5462
registry: ghcr.io
55-
username: ${{ github.actor }}
63+
username: ${{ github.repository_owner }}
5664
password: ${{ secrets.GITHUB_TOKEN }}
5765

5866
- name: Set APP_VERSION env
5967
run: echo APP_VERSION=$(echo ${GITHUB_REF} | rev | cut -d'/' -f 1 | rev ) >> ${GITHUB_ENV}
6068
- name: Set APP_RELEASE env
6169
run: echo APP_RELEASE=$(( ($(date +%s) - $(date -d "2022-06-15" +%s)) / 86400 )) >> ${GITHUB_ENV}
6270

71+
- name: Set up QEMU
72+
uses: docker/setup-qemu-action@v3
73+
74+
- name: Set up Docker Buildx
75+
uses: docker/setup-buildx-action@v3
76+
6377
- name: Build and push Docker image
64-
uses: docker/build-push-action@v5
78+
id: build
79+
uses: docker/build-push-action@v6
6580
with:
6681
file: build/package/Dockerfile
82+
platforms: ${{ matrix.platform }}
6783
build-args: |
6884
APP=${{ inputs.app-name }}
6985
APP_VERSION=${{ env.APP_VERSION }}
7086
APP_RELEASE_ID=${{ env.APP_RELEASE }}
71-
push: true
72-
tags: ${{ steps.meta.outputs.tags }}
87+
push: ${{ github.actor != 'dependabot[bot]' }}
7388
labels: ${{ steps.meta.outputs.labels }}
74-
# cache-from: type=gha
75-
# cache-to: type=gha,mode=max
89+
outputs: type=image,"name=${{ env.DOCKERHUB_REPO }},${{ env.GHCR_REPO }}",push-by-digest=true,name-canonical=true,push=true
90+
91+
- name: Export digest
92+
run: |
93+
mkdir -p ${{ runner.temp }}/digests
94+
digest="${{ steps.build.outputs.digest }}"
95+
touch "${{ runner.temp }}/digests/${digest#sha256:}"
96+
97+
- name: Upload digest
98+
uses: actions/upload-artifact@v4
99+
with:
100+
name: digests-${{ env.PLATFORM_PAIR }}
101+
path: ${{ runner.temp }}/digests/*
102+
if-no-files-found: error
103+
retention-days: 1
104+
105+
merge:
106+
runs-on: ubuntu-latest
107+
needs:
108+
- build
109+
steps:
110+
- name: Download digests
111+
uses: actions/download-artifact@v4
112+
with:
113+
path: ${{ runner.temp }}/digests
114+
pattern: digests-*
115+
merge-multiple: true
116+
117+
- name: Log into Docker Hub
118+
uses: docker/login-action@v3
119+
if: github.actor != 'dependabot[bot]'
120+
with:
121+
username: ${{ secrets.username }}
122+
password: ${{ secrets.password }}
123+
124+
- name: Login to Container registry
125+
uses: docker/login-action@v3
126+
if: github.actor != 'dependabot[bot]'
127+
with:
128+
registry: ghcr.io
129+
username: ${{ github.repository_owner }}
130+
password: ${{ secrets.GITHUB_TOKEN }}
131+
132+
- name: Set up Docker Buildx
133+
uses: docker/setup-buildx-action@v3
134+
135+
- name: Docker meta
136+
id: meta
137+
uses: docker/metadata-action@v5
138+
with:
139+
images: |
140+
${{ env.DOCKERHUB_REPO }}
141+
${{ env.GHCR_REPO }}
142+
tags: |
143+
type=ref,event=branch
144+
type=ref,event=pr
145+
type=semver,pattern={{version}}
146+
type=semver,pattern={{major}}.{{minor}}
147+
type=semver,pattern={{major}}
148+
149+
- name: Create manifest list and push
150+
working-directory: ${{ runner.temp }}/digests
151+
run: |
152+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
153+
$(printf '${{ env.DOCKERHUB_REPO }}@sha256:%s ' *)
154+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
155+
$(printf '${{ env.GHCR_REPO }}@sha256:%s ' *)
156+
157+
- name: Inspect image
158+
run: |
159+
docker buildx imagetools inspect ${{ env.DOCKERHUB_REPO }}:${{ steps.meta.outputs.version }}
160+
docker buildx imagetools inspect ${{ env.GHCR_REPO }}:${{ steps.meta.outputs.version }}

build/package/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ RUN go generate ./...
2929
RUN CGO_ENABLED=0 go build -a -installsuffix cgo -ldflags="-w -s -X github.com/android-sms-gateway/server/internal/version.AppVersion=${APP_VERSION} -X github.com/android-sms-gateway/server/internal/version.AppRelease=${APP_RELEASE_ID}" -o app ./cmd/${APP}/main.go
3030

3131
# Moving the binary to the 'final Image' to make it smaller
32-
FROM alpine:3 as prod
32+
FROM alpine:3 AS prod
3333

3434
WORKDIR /app
3535

0 commit comments

Comments
 (0)