From 141ce00100a48192246ee65ab40e42ed5a3819a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20Gustav=20Str=C3=A5b=C3=B8?= Date: Fri, 16 Aug 2024 09:26:44 +0200 Subject: [PATCH] fix multiplatform docker build performance --- .github/workflows/build-push.yml | 1 - .github/workflows/pr.yaml | 19 +++---------------- Dockerfile | 12 ++++-------- 3 files changed, 7 insertions(+), 25 deletions(-) diff --git a/.github/workflows/build-push.yml b/.github/workflows/build-push.yml index db6d11c..9752f26 100644 --- a/.github/workflows/build-push.yml +++ b/.github/workflows/build-push.yml @@ -15,7 +15,6 @@ jobs: strategy: fail-fast: false matrix: - arch: [arm64] target: - name: "dev" ref: "refs/heads/main" diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index afe933c..d465ea7 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -7,9 +7,6 @@ jobs: build: name: pull-request-check runs-on: ubuntu-20.04 - strategy: - matrix: - arch: [arm64] steps: - uses: actions/checkout@v4 - name: Set up Docker Buildx @@ -19,14 +16,13 @@ jobs: with: context: . push: false - platforms: linux/arm64 + platforms: | + linux/amd64 + linux/arm64 test: name: Unit Test runs-on: ubuntu-latest - strategy: - matrix: - arch: [arm64] steps: - uses: actions/checkout@v4 - uses: actions/setup-go@v5 @@ -40,9 +36,6 @@ jobs: lint: name: Lint runs-on: ubuntu-latest - strategy: - matrix: - arch: [arm64] steps: - uses: actions/checkout@v4 with: @@ -58,9 +51,6 @@ jobs: verify-code-generation: name: Verify Code Generation runs-on: ubuntu-latest - strategy: - matrix: - arch: [arm64] steps: - uses: actions/checkout@v4 - uses: actions/setup-go@v5 @@ -73,9 +63,6 @@ jobs: report-swagger-changes: name: Report Changes In Swagger Spec runs-on: ubuntu-latest - strategy: - matrix: - arch: [arm64] steps: - uses: actions/checkout@v4 - uses: actions/setup-go@v5 diff --git a/Dockerfile b/Dockerfile index c86c7a5..54f903a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,23 +1,19 @@ -FROM docker.io/golang:1.22-alpine3.20 AS builder - +FROM --platform=$BUILDPLATFORM docker.io/golang:1.22-alpine3.20 AS builder +ARG TARGETARCH ENV CGO_ENABLED=0 \ - GOOS=linux + GOOS=linux \ + GOARCH=${TARGETARCH} WORKDIR /src -# Install project dependencies COPY go.mod go.sum ./ RUN go mod download - -# Copy project code COPY . . - RUN go build -ldflags="-s -w" -o /build/radix-job-scheduler # Final stage, ref https://github.com/GoogleContainerTools/distroless/blob/main/base/README.md for distroless FROM gcr.io/distroless/static WORKDIR /app COPY --from=builder /build/radix-job-scheduler . - USER 1000 ENTRYPOINT ["/app/radix-job-scheduler"]