Skip to content

Commit

Permalink
Use BUILDPLATFORM for multi-architecture build (#1178)
Browse files Browse the repository at this point in the history
* Refactor docker build workflows

* Refactor
  • Loading branch information
int128 authored Nov 10, 2024
1 parent ada466d commit 43922b3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 35 deletions.
57 changes: 25 additions & 32 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ on:
- pkg/**
- go.*
- Dockerfile
- Makefile
push:
branches:
- master
Expand All @@ -18,59 +17,53 @@ on:
- pkg/**
- go.*
- Dockerfile
- Makefile
tags:
- v*

jobs:
build-linux-amd64:
uses: int128/docker-build-workflow/.github/workflows/build.yaml@v1
with:
platforms: linux/amd64
flavor: latest=false,suffix=-linux-amd64

build-linux-arm64:
uses: int128/docker-build-workflow/.github/workflows/build.yaml@v1
with:
platforms: linux/arm64
flavor: latest=false,suffix=-linux-arm64

build-linux-ppc64le:
uses: int128/docker-build-workflow/.github/workflows/build.yaml@v1
with:
platforms: linux/ppc64le
flavor: latest=false,suffix=-linux-ppc64le

build:
needs:
- build-linux-amd64
- build-linux-arm64
- build-linux-ppc64le
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
packages: write
outputs:
image-uri: ghcr.io/${{ github.repository }}@${{ steps.build.outputs.digest }}
steps:
- uses: docker/login-action@v3
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/metadata-action@v5
- uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1
id: metadata
with:
images: ghcr.io/${{ github.repository }}
- uses: int128/docker-manifest-create-action@v2
- uses: int128/docker-build-cache-config-action@34bb1b5886d06c161bf0dd9e169f03a52ff858fb # v1.35.0
id: cache
with:
image: ghcr.io/${{ github.repository }}/cache
- uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf # v3.2.0
- uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 # v3.7.1
- uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75 # v6.9.0
id: build
with:
push: true
tags: ${{ steps.metadata.outputs.tags }}
sources: |
ghcr.io/${{ github.repository }}@${{ needs.build-linux-amd64.outputs.digest }}
ghcr.io/${{ github.repository }}@${{ needs.build-linux-arm64.outputs.digest }}
ghcr.io/${{ github.repository }}@${{ needs.build-linux-ppc64le.outputs.digest }}
labels: ${{ steps.metadata.outputs.labels }}
cache-from: ${{ steps.cache.outputs.cache-from }}
cache-to: ${{ steps.cache.outputs.cache-to }}
platforms: |
linux/amd64
linux/arm64
linux/ppc64le
test:
needs: build
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- run: docker run --rm '${{ needs.build.outputs.image-uri }}' --help
- run: docker run --rm "$IMAGE_URI" --help
env:
IMAGE_URI: ${{ needs.build.outputs.image-uri }}
14 changes: 11 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
FROM golang:1.23 as builder
FROM --platform=$BUILDPLATFORM golang:1.23 AS builder

WORKDIR /builder
COPY go.* .

# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
RUN go mod download

# Copy the go source
COPY main.go .
COPY pkg pkg
RUN go build

ARG TARGETOS
ARG TARGETARCH
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build

FROM gcr.io/distroless/base-debian12
COPY --from=builder /builder/kubelogin /
Expand Down

0 comments on commit 43922b3

Please sign in to comment.