diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index c2933d1..48de195 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -30,9 +30,6 @@ jobs: # https://github.com/docker/setup-buildx-action - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - with: - # Only build for amd64 for now, we should extend to arm64 eventually - platforms: linux/amd64 # Login against a Docker registry except on PR # https://github.com/docker/login-action @@ -59,6 +56,7 @@ jobs: uses: docker/build-push-action@v5 with: context: . + platforms: linux/amd64,linux/arm64 push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile index 2f0da39..04baaae 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,22 @@ -FROM golang:1.22.5-alpine3.19 AS builder +# Use the $BUILDPLATFORM for the build stage +FROM --platform=$BUILDPLATFORM golang:1.22.5-alpine3.19 AS builder + WORKDIR /app -RUN cat /etc/resolv.conf && apk add --no-cache git && \ - git config --add --global url."git@github.com:".insteadOf https://github.com # Prepare dependencies -COPY go.mod go.sum ./ +COPY go.mod go.sum . RUN go mod download -# Build the binary + +# Copy the sources and config COPY ./cmd ./cmd COPY ./internal ./internal COPY ./config ./config -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o api ./cmd/api +# Build the binary based on the target platform +ARG TARGETOS TARGETARCH +RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o api ./cmd/api +# Use the $TARGETPLATFORM by default for the runtime stage FROM alpine:3.19 WORKDIR /app COPY --from=builder /app/api ./api