Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v15] Fixed plugins using arm64 binaries in all container images #45618

Merged
merged 4 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion e
Submodule e updated from 31d947 to 2809f3
44 changes: 13 additions & 31 deletions integrations/access/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,44 +1,26 @@
ARG BUILDBOX
ARG BASE_IMAGE=gcr.io/distroless/static-debian12

# BUILDPLATFORM is provided by Docker/buildx
FROM --platform=$BUILDPLATFORM $BUILDBOX as builder
# Extract the built tarball to reduce the final image size
FROM --platform=${BUILDPLATFORM} alpine:3.20.0 as extractor

WORKDIR /go/src/github.com/gravitational/teleport/

# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum

# We have to copy the API before `go mod download` because go.mod has a replace directive for it
COPY api/ api/

RUN go mod download

# Copy in code
COPY version.go constants.go ./
COPY lib/ ./lib/
COPY build.assets/images.mk build.assets/arch.mk ./build.assets/
COPY integrations/lib/ ./integrations/lib/
COPY integrations/access/ ./integrations/access/

RUN pwd && ls -la

ARG TARGETOS
ARG TARGETARCH
ARG ACCESS_PLUGIN
ARG VERSION
ARG TARGETOS
ARG ARTIFACT_NAME=plugin # Should be something like 'access-slack' or 'event-handler'
ARG TELEPORT_VERSION=0.0.0 # Should be the version without 'v' prefix
ARG FILENAME=teleport-${ARTIFACT_NAME}-v${TELEPORT_VERSION}-${TARGETOS}-${TARGETARCH}-bin.tar.gz # Optional override

WORKDIR /go/src/github.com/gravitational/teleport/integrations/access/$ACCESS_PLUGIN
WORKDIR /extraction
COPY *${TARGETARCH}*.tar.gz /plugin.tar.gz
COPY "${FILENAME}" /plugin.tar.gz

# Build the program. We rely on golang's cross-compilation capabilities for multiarch building.
RUN make build/teleport-$ACCESS_PLUGIN VERSION=$VERSION
RUN tar -xzvf /plugin.tar.gz && \
find . -type f -executable -name 'teleport-*' -exec mv {} /teleport-plugin \;

# Create the image with the build operator on the $TARGETPLATFORM
# TARGETPLATFORM is provided by Docker/buildx
FROM --platform=$TARGETPLATFORM $BASE_IMAGE
FROM --platform=${TARGETPLATFORM} ${BASE_IMAGE}
WORKDIR /
ARG ACCESS_PLUGIN
COPY --from=builder /go/src/github.com/gravitational/teleport/integrations/access/$ACCESS_PLUGIN/build/teleport-$ACCESS_PLUGIN /usr/local/bin/teleport-plugin
COPY --from=extractor /teleport-plugin /usr/local/bin/teleport-plugin

ENTRYPOINT ["/usr/local/bin/teleport-plugin"]
12 changes: 7 additions & 5 deletions integrations/access/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ RELEASE_MESSAGE = "Building with GOOS=$(OS) GOARCH=$(ARCH)."
DOCKER_VERSION = $(subst +,_,$(VERSION))
DOCKER_NAME = teleport-plugin-$(ACCESS_PLUGIN)
DOCKER_PRIVATE_REGISTRY = 146628656107.dkr.ecr.us-west-2.amazonaws.com
DOCKER_IMAGE = $(DOCKER_PRIVATE_REGISTRY)/gravitational/$(DOCKER_NAME):$(DOCKER_VERSION)
DOCKER_IMAGE_BASE = $(DOCKER_PRIVATE_REGISTRY)/gravitational
DOCKER_IMAGE = $(DOCKER_IMAGE_BASE)/$(DOCKER_NAME):$(DOCKER_VERSION)
DOCKER_ECR_PUBLIC_REGISTRY = public.ecr.aws/gravitational
DOCKER_IMAGE_ECR_PUBLIC = $(DOCKER_ECR_PUBLIC_REGISTRY)/$(DOCKER_NAME):$(DOCKER_VERSION)
DOCKER_BUILD_ARGS = --load --platform="$(OS)/$(ARCH)" --build-arg ACCESS_PLUGIN=$(ACCESS_PLUGIN) --build-arg VERSION=$(VERSION) --build-arg BUILDBOX=$(BUILDBOX)
DOCKER_BUILD_ARGS = --load --platform="$(OS)/$(ARCH)"
# In staging
# DOCKER_PRIVATE_REGISTRY = 603330915152.dkr.ecr.us-west-2.amazonaws.com
# DOCKER_ECR_PUBLIC_REGISTRY = public.ecr.aws/gravitational-staging
Expand All @@ -43,7 +44,7 @@ clean:
rm -rf *.gz

.PHONY: release
release: clean $(BINARY)
release: $(BINARY)
@echo "---> $(RELEASE_MESSAGE)"
mkdir build/$(RELEASE_NAME)
cp -rf $(BINARY) \
Expand All @@ -56,8 +57,9 @@ release: clean $(BINARY)
@echo "---> Created build/$(RELEASE).tar.gz."

.PHONY: docker-build
docker-build: ## Build docker image with the plugin.
docker buildx build ${DOCKER_BUILD_ARGS} -t ${DOCKER_IMAGE} -f ../Dockerfile ../../..
docker-build: OS = linux
docker-build: release ## Build docker image with the plugin.
docker buildx build ${DOCKER_BUILD_ARGS} -t ${DOCKER_IMAGE} -f ../Dockerfile ./build

.PHONY: docker-push
docker-push: ## Push docker image with the plugin.
Expand Down
41 changes: 14 additions & 27 deletions integrations/event-handler/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,39 +1,26 @@
ARG BUILDBOX
ARG BASE_IMAGE=gcr.io/distroless/static-debian12

# BUILDPLATFORM is provided by Docker/buildx
FROM --platform=$BUILDPLATFORM $BUILDBOX as builder
# Extract the built tarball to reduce the final image size
FROM --platform=${BUILDPLATFORM} alpine:3.20.0 as extractor

WORKDIR /go/src/github.com/gravitational/teleport/

# Copy dependencies and go.mod
COPY api/ api/
COPY version.go constants.go go.mod go.sum ./
COPY lib/ ./lib/
COPY build.assets/images.mk build.assets/arch.mk ./build.assets/
COPY integrations/lib/ ./integrations/lib/

COPY integrations/event-handler/go.mod ./integrations/event-handler/go.mod
COPY integrations/event-handler/go.sum ./integrations/event-handler/go.sum

RUN cd integrations/event-handler && go mod download

COPY integrations/event-handler ./integrations/event-handler

ARG TARGETOS
ARG TARGETARCH
ARG GITREF
ARG VERSION
ARG TARGETOS
ARG ARTIFACT_NAME=plugin # Should be something like 'access-slack' or 'event-handler'
ARG TELEPORT_VERSION=0.0.0 # Should be the version without 'v' prefix
ARG FILENAME=teleport-${ARTIFACT_NAME}-v${TELEPORT_VERSION}-${TARGETOS}-${TARGETARCH}-bin.tar.gz # Optional override

WORKDIR /go/src/github.com/gravitational/teleport/integrations/event-handler
WORKDIR /extraction
COPY *${TARGETARCH}*.tar.gz /plugin.tar.gz
COPY "${FILENAME}" /plugin.tar.gz

# Build the program. We rely on golang's cross-compilation capabilities for multiarch building.
RUN make build GITREF=$GITREF VERSION=$VERSION
RUN tar -xzvf /plugin.tar.gz && \
find . -type f -executable -name 'teleport-*' -exec mv {} /teleport-plugin \;

# Create the image with the build operator on the $TARGETPLATFORM
# TARGETPLATFORM is provided by Docker/buildx
FROM --platform=$TARGETPLATFORM $BASE_IMAGE
FROM --platform=${TARGETPLATFORM} ${BASE_IMAGE}
WORKDIR /
COPY --from=builder /go/src/github.com/gravitational/teleport/integrations/event-handler/build/teleport-event-handler /usr/local/bin/teleport-event-handler
COPY --from=extractor /teleport-plugin /usr/local/bin/teleport-plugin

ENTRYPOINT ["/usr/local/bin/teleport-event-handler"]
ENTRYPOINT ["/usr/local/bin/teleport-plugin"]
14 changes: 8 additions & 6 deletions integrations/event-handler/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ GENTERRAFORMPATH := $(shell go env GOPATH)/bin
BUILDDIR ?= build
BINARY = $(BUILDDIR)/teleport-event-handler

GITREF ?= $(shell git describe --dirty --long --tags --match '*event-handler*')
GITREF ?= $(shell git describe --dirty --long --tags --match '$(VERSION)')
ADDFLAGS ?=
BUILDFLAGS ?= $(ADDFLAGS) -trimpath -ldflags "-w -s -X main.Gitref=$(GITREF) -X main.Version=$(VERSION)"
CGOFLAG ?= CGO_ENABLED=0
Expand All @@ -30,10 +30,11 @@ IDENTITY_FILE=example/keys/identity
DOCKER_VERSION = $(subst +,_,$(VERSION))
DOCKER_NAME=teleport-plugin-event-handler
DOCKER_PRIVATE_REGISTRY = 146628656107.dkr.ecr.us-west-2.amazonaws.com
DOCKER_IMAGE = $(DOCKER_PRIVATE_REGISTRY)/gravitational/$(DOCKER_NAME):$(DOCKER_VERSION)
DOCKER_IMAGE_BASE = $(DOCKER_PRIVATE_REGISTRY)/gravitational
DOCKER_IMAGE = $(DOCKER_IMAGE_BASE)/$(DOCKER_NAME):$(DOCKER_VERSION)
DOCKER_ECR_PUBLIC_REGISTRY = public.ecr.aws/gravitational
DOCKER_IMAGE_ECR_PUBLIC = $(DOCKER_ECR_PUBLIC_REGISTRY)/$(DOCKER_NAME):$(DOCKER_VERSION)
DOCKER_BUILD_ARGS = --build-arg GO_VERSION=${GO_VERSION} --build-arg GITREF=$(GITREF) --build-arg VERSION=$(VERSION) --build-arg VERSION=$(VERSION) --load --platform="$(OS)/$(ARCH)" --build-arg BUILDBOX=$(BUILDBOX)
DOCKER_BUILD_ARGS = --load --platform="$(OS)/$(ARCH)"
RELEASE_NAME = teleport-event-handler
RELEASE = $(RELEASE_NAME)-v$(VERSION)-$(OS)-$(ARCH)-bin
RELEASE_MESSAGE = "Building with GOOS=$(OS) GOARCH=$(ARCH)."
Expand All @@ -42,7 +43,7 @@ RELEASE_MESSAGE = "Building with GOOS=$(OS) GOARCH=$(ARCH)."
# DOCKER_ECR_PUBLIC_REGISTRY = public.ecr.aws/gravitational-staging

.PHONY: build
build: clean
build:
GOOS=$(OS) GOARCH=$(ARCH) $(CGOFLAG) go build -o $(BUILDDIR)/teleport-event-handler $(BUILDFLAGS)

.PHONY: release
Expand All @@ -64,8 +65,9 @@ clean:
go clean

.PHONY: docker-build
docker-build: ## Build docker image with the plugin.
docker build ${DOCKER_BUILD_ARGS} -t ${DOCKER_IMAGE} -f ./Dockerfile ../..
docker-build: OS = linux
docker-build: release ## Build docker image with the plugin.
docker build ${DOCKER_BUILD_ARGS} -t ${DOCKER_IMAGE} -f ./Dockerfile .

.PHONY: docker-push
docker-push:
Expand Down
Loading