From b6447811ff6a8abd462666d3ea42de98e020a749 Mon Sep 17 00:00:00 2001 From: Adam Snyder Date: Sat, 3 Dec 2022 21:41:35 -0800 Subject: [PATCH] Update Dockerfile and CI for multi-platform builds (#6) * Use docker buildx in CI * Update Dockerfile for buildx --- .github/workflows/ci.yaml | 3 +++ Dockerfile | 9 ++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b96c113..1f77dd0 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -41,6 +41,9 @@ jobs: with: images: armsnyder/a2s-exporter + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Log in to Docker Hub if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') uses: docker/login-action@v2 diff --git a/Dockerfile b/Dockerfile index a08092e..140d2bc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,10 @@ +# syntax=docker/dockerfile:1.4 FROM golang:1.19 AS builder WORKDIR /build -COPY go.mod go.sum ./ -RUN go mod download -COPY internal internal -COPY *.go . +COPY . . ARG BUILD_VERSION=development -RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags="-w -s -X 'main.buildVersion=$BUILD_VERSION'" -o /bin/a2s-exporter . +ENV CGO_ENABLED=0 +RUN --mount=type=cache,target=/root/.cache/go-build go build -ldflags="-w -s -X 'main.buildVersion=$BUILD_VERSION'" -o /bin/a2s-exporter . FROM scratch COPY --from=builder /bin/a2s-exporter /bin/a2s-exporter