Skip to content

Commit

Permalink
Fixes issue with arm64 support. (#404)
Browse files Browse the repository at this point in the history
* Addresses issue
[#390](#391) by
adding support for multi-architecture container images.

* Removed --platform due to linting rule constraints.

* Removed echo statements due to lint rules.

Signed-off-by: Michael Primeaux <[email protected]>
  • Loading branch information
mprimeaux authored Jan 16, 2023
1 parent cbcd2ca commit 8762e50
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
18 changes: 15 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Build the manager binary
ARG ARCH="amd64"
FROM golang:1.17 as builder
ARG BUILDOS
ARG BUILDPLATFORM
ARG BUILDARCH
ARG BUILDVARIANT
ARG TARGETPLATFORM
ARG TARGETOS
ARG TARGETARCH
ARG TARGETVARIANT

WORKDIR /workspace
# Copy the Go Modules manifests
Expand All @@ -17,11 +24,16 @@ COPY controllers/ controllers/
COPY k8sutils/ k8sutils/

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} GO111MODULE=on go build -a -o manager main.go
ARG LDFLAGS="-s -w"
ENV GOOS=$TARGETOS
ENV GOARCH=$TARGETARCH
ENV CGO_ENABLED=0

RUN GO111MODULE=on go build -ldflags "${LDFLAGS}" -a -o manager 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-${ARCH}
FROM gcr.io/distroless/static:nonroot
LABEL maintainer="The Opstree Opensource <[email protected]>"
WORKDIR /
COPY --from=builder /workspace/manager .
Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,12 @@ vet:
generate: controller-gen
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."

docker-create:
docker buildx create --platform "linux/amd64,linux/arm64" --use

# Build the docker image
docker-build:
docker build -t ${IMG} .
docker buildx build --platform="linux/arm64,linux/amd64" -t ${IMG} .

# Push the docker image
docker-push:
Expand Down Expand Up @@ -116,4 +119,4 @@ bundle: manifests kustomize
# Build the bundle image.
.PHONY: bundle-build
bundle-build:
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .
docker buildx build --platform="linux/arm64,linux/amd64" -f bundle.Dockerfile -t $(BUNDLE_IMG) .

0 comments on commit 8762e50

Please sign in to comment.