Skip to content

Commit

Permalink
operator: revert to old dockerfile and oci image build process
Browse files Browse the repository at this point in the history
  • Loading branch information
hugoShaka committed Apr 3, 2023
1 parent afb7bd2 commit cf14a86
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
16 changes: 9 additions & 7 deletions integrations/operator/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
ARG BUILDBOX
ARG BASE_IMAGE=gcr.io/distroless/static-debian11
# BUILDPLATFORM is provided by Docker/buildx
FROM --platform=$BUILDPLATFORM $BUILDBOX as builder

Expand All @@ -26,17 +25,20 @@ COPY integrations/operator/sidecar/ integrations/operator/sidecar/
COPY integrations/operator/main.go integrations/operator/main.go
COPY integrations/operator/namespace.go integrations/operator/namespace.go

ARG TARGETOS
ARG TARGETARCH
# Compiler package should use host-triplet-agnostic name (i.e. "x86-64-linux-gnu-gcc" instead of "gcc")
# in most cases, to avoid issues on systems with multiple versions of gcc (i.e. buildboxes)
# TARGETOS and TARGETARCH are provided by Docker/buildx, but must be explicitly listed here
ARG COMPILER_NAME TARGETOS TARGETARCH

# Build the program. We rely on golang's cross-compilation capabilities for multiarch building.
RUN echo "Targeting $TARGETOS/$TARGETARCH" && \
GOOS=$TARGETOS GOARCH=$TARGETARCH \
# Build the program
# CGO is required for github.com/gravitational/teleport/lib/system
RUN echo "Targeting $TARGETOS/$TARGETARCH with CC=$COMPILER_NAME" && \
CGO_ENABLED=1 CC=$COMPILER_NAME GOOS=$TARGETOS GOARCH=$TARGETARCH \
go build -a -o /go/bin/teleport-operator github.com/gravitational/teleport/integrations/operator

# Create the image with the build operator on the $TARGETPLATFORM
# TARGETPLATFORM is provided by Docker/buildx
FROM --platform=$TARGETPLATFORM $BASE_IMAGE
FROM --platform=$TARGETPLATFORM gcr.io/distroless/cc
WORKDIR /
COPY --from=builder /go/bin/teleport-operator .

Expand Down
19 changes: 17 additions & 2 deletions integrations/operator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ include ./envtest.mk
# Configure which compiler and buildbox to use
OS ?= $(shell go env GOOS)
ARCH ?= $(shell go env GOARCH)
ifeq ("$(OS)","linux")
ifeq ("$(ARCH)","amd64")
COMPILER ?= x86_64-linux-gnu-gcc
PLATFORM_BUILDBOX ?= $(BUILDBOX)
else ifeq ("$(ARCH)","386")
COMPILER ?= x86_64-linux-gnu-gcc
PLATFORM_BUILDBOX ?= $(BUILDBOX)
else ifeq ("$(ARCH)","arm")
COMPILER ?= arm-linux-gnueabihf-gcc
PLATFORM_BUILDBOX ?= $(BUILDBOX_ARM)
else ifeq ("$(ARCH)","arm64")
COMPILER ?= aarch64-linux-gnu-gcc
PLATFORM_BUILDBOX ?= $(BUILDBOX_ARM)
endif
endif

.PHONY: all
all: build
Expand Down Expand Up @@ -110,8 +125,8 @@ run: manifests generate fmt vet ## Run a controller from your host.

.PHONY: docker-build
docker-build: ## Build docker image with the manager.
docker buildx build --platform="$(OS)/$(ARCH)" --build-arg BUILDBOX=$(BUILDBOX) \
-t ${IMG} --load ../.. -f ./Dockerfile
docker buildx build --platform="$(OS)/$(ARCH)" --build-arg BUILDBOX=$(PLATFORM_BUILDBOX) \
--build-arg COMPILER_NAME=$(COMPILER) -t ${IMG} --load ../.. -f ./Dockerfile

.PHONY: docker-push
docker-push: ## Push docker image with the manager.
Expand Down

0 comments on commit cf14a86

Please sign in to comment.