Skip to content

Commit 8a7401d

Browse files
Build linux/arm64 and linux/amd64 Docker Images (#10)
1 parent 877759a commit 8a7401d

2 files changed

Lines changed: 49 additions & 4 deletions

File tree

.github/workflows/docker.yml

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ on:
1515

1616
jobs:
1717
docker:
18-
name: Docker Build and Push Image
18+
name: Docker Build and Push Image ${{ matrix.architecture }}
1919
runs-on: ubuntu-latest
20+
strategy:
21+
matrix:
22+
architecture: [arm64, amd64]
2023
steps:
2124
- name: Checkout repository
2225
uses: actions/checkout@v2
@@ -27,6 +30,8 @@ jobs:
2730
fallback: latest
2831
- name: Set up QEMU
2932
uses: docker/setup-qemu-action@v1
33+
with:
34+
platforms: linux/${{ matrix.architecture }}
3035
- name: Set up docker buildx
3136
uses: docker/setup-buildx-action@v1
3237
with:
@@ -37,13 +42,51 @@ jobs:
3742
registry: ghcr.io
3843
username: ${{ github.actor }}
3944
password: ${{ secrets.GITHUB_TOKEN }}
45+
- name: Determine Base Image
46+
uses: haya14busa/action-cond@v1
47+
id: baseimage
48+
with:
49+
cond: ${{ matrix.architecture == 'arm64' }}
50+
if_true: 'swiftarm/swift:5.5.1-ubuntu-focal'
51+
if_false: 'swift:focal'
4052
- name: Build and push docker image
4153
id: buildandpush
4254
uses: docker/build-push-action@v2
4355
with:
4456
context: .
4557
file: ./Dockerfile
58+
build-args: |
59+
baseimage=${{ steps.baseimage.outputs.value }}
4660
push: true
47-
tags: ghcr.io/apodini/template:latest,ghcr.io/apodini/template:${{ steps.latesttag.outputs.tag }}
61+
platforms: linux/${{ matrix.architecture }}
62+
tags: ghcr.io/apodini/template:latest-${{ matrix.architecture }},ghcr.io/apodini/template:${{ steps.latesttag.outputs.tag }}-${{ matrix.architecture }}
4863
- name: Image digest
4964
run: echo ${{ steps.buildandpush.outputs.digest }}
65+
dockermanifest:
66+
needs: [docker]
67+
name: Create Multi-CPU Architecture Image
68+
runs-on: ubuntu-latest
69+
steps:
70+
- name: Checkout repository
71+
uses: actions/checkout@v2
72+
- name: Get latest tag
73+
id: latesttag
74+
uses: WyriHaximus/github-action-get-previous-tag@v1
75+
with:
76+
fallback: latest
77+
- name: Log in to the container registry
78+
uses: docker/login-action@v1
79+
with:
80+
registry: ghcr.io
81+
username: ${{ github.actor }}
82+
password: ${{ secrets.GITHUB_TOKEN }}
83+
- name: Create and Push Multi Architecture Image
84+
run: |
85+
docker manifest create ghcr.io/apodini/template:latest \
86+
--amend ghcr.io/apodini/template:latest-amd64 \
87+
--amend ghcr.io/apodini/template:latest-arm64
88+
docker manifest create ghcr.io/apodini/template:${{ steps.latesttag.outputs.tag }} \
89+
--amend ghcr.io/apodini/template:${{ steps.latesttag.outputs.tag }}-amd64 \
90+
--amend ghcr.io/apodini/template:${{ steps.latesttag.outputs.tag }}-arm64
91+
docker manifest push ghcr.io/apodini/template:latest
92+
docker manifest push ghcr.io/apodini/template:${{ steps.latesttag.outputs.tag }}

Dockerfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
# SPDX-License-Identifier: MIT
77
#
88

9+
ARG baseimage=swift:focal
10+
911
# ================================
1012
# Build image
1113
# ================================
12-
FROM swiftlang/swift:nightly-5.5-focal as build
14+
FROM ${baseimage} as build
1315

1416
# Install OS updates and, if needed, sqlite3
1517
RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \
@@ -47,7 +49,7 @@ RUN [ -d "$(swift build --package-path /build -c release --show-bin-path)/WebSer
4749
# ================================
4850
# Run image
4951
# ================================
50-
FROM swiftlang/swift:nightly-5.5-focal-slim as run
52+
FROM ${baseimage}-slim as run
5153

5254
# Make sure all system packages are up to date.
5355
RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \

0 commit comments

Comments
 (0)