From de6141c3a7938a5a10fa41490960285beaecb5a4 Mon Sep 17 00:00:00 2001 From: Hardik Dodiya Date: Thu, 25 Jul 2024 14:45:34 +0200 Subject: [PATCH] Fix dockerfile --- .github/workflows/publish-docker.yml | 9 ++------- Dockerfile | 11 +++++++---- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/.github/workflows/publish-docker.yml b/.github/workflows/publish-docker.yml index 5977d06..f7d026c 100644 --- a/.github/workflows/publish-docker.yml +++ b/.github/workflows/publish-docker.yml @@ -21,11 +21,6 @@ on: jobs: buildAndPush: - strategy: - matrix: - image: - - name: cluster-api-provider-metal - target: manager permissions: contents: read packages: write @@ -37,7 +32,7 @@ jobs: id: meta with: images: | - ghcr.io/${{ github.repository_owner }}/${{ matrix.image.name }} + ghcr.io/${{ github.repository_owner }}/cluster-api-metal-controller tags: | type=semver,pattern={{version}} type=schedule @@ -79,4 +74,4 @@ jobs: push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - target: ${{ matrix.image.target }} + target: manager diff --git a/Dockerfile b/Dockerfile index a48973e..7ac5a81 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Build the manager binary -FROM golang:1.22 AS builder +FROM --platform=$BUILDPLATFORM golang:1.22 AS builder ARG TARGETOS ARG TARGETARCH @@ -14,18 +14,21 @@ RUN go mod download # Copy the go source COPY cmd/main.go cmd/main.go COPY api/ api/ -COPY internal/controller/ internal/controller/ +COPY internal/ internal/ # Build # the GOARCH has not a default value to allow the binary be built according to the host where the command # was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO # the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore, # by leaving it empty we can ensure that the container and binary shipped on it will have the same platform. -RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go +RUN --mount=type=cache,target=/root/.cache/go-build \ + --mount=type=cache,target=/go/pkg \ + CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go + # Use distroless as minimal base image to package the manager binary # Refer to https://github.com/GoogleContainerTools/distroless for more details -FROM gcr.io/distroless/static:nonroot +FROM gcr.io/distroless/static:nonroot AS manager WORKDIR / COPY --from=builder /workspace/manager . USER 65532:65532