Skip to content

Commit

Permalink
Build a multi-arch Docker image (amd64 and arm64)
Browse files Browse the repository at this point in the history
  • Loading branch information
desmondgc committed May 19, 2024
1 parent 2b16e98 commit f365c7f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
21 changes: 17 additions & 4 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ name: Publish Docker image
on:
release:
types: [published]

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
TARGET_PLATFORMS: linux/amd64,linux/arm64

jobs:
push_to_registry:
Expand All @@ -12,17 +17,24 @@ jobs:
- name: Check out the repo
uses: actions/checkout@v4

- name: Log in to Docker Hub
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: jgkawell/yarr
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and push Docker image
uses: docker/build-push-action@v5
Expand All @@ -32,3 +44,4 @@ jobs:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: ${{ env.TARGET_PLATFORMS }}
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:alpine AS build
FROM --platform=$BUILDPLATFORM golang:alpine AS build

WORKDIR /app

Expand All @@ -7,7 +7,9 @@ COPY . .
RUN go mod download
RUN go mod verify

RUN GOOS=linux GOARCH=amd64 go build -o bin/yarr .
ARG TARGETOS
ARG TARGETARCH
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o bin/yarr .

FROM alpine:latest

Expand Down

0 comments on commit f365c7f

Please sign in to comment.