Skip to content

Commit

Permalink
Fix dockerfile (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
hardikdr authored Jul 25, 2024
1 parent f1cc653 commit e3c9589
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
9 changes: 2 additions & 7 deletions .github/workflows/publish-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ on:

jobs:
buildAndPush:
strategy:
matrix:
image:
- name: cluster-api-provider-metal
target: manager
permissions:
contents: read
packages: write
Expand All @@ -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
Expand Down Expand Up @@ -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
11 changes: 7 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand Down

0 comments on commit e3c9589

Please sign in to comment.