Skip to content

Commit

Permalink
merge operator dockerfiles into one dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
anoipm committed Feb 23, 2024
1 parent ab97f2e commit be89654
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 58 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#
# This Dockerfile is used to build serverless-operator image on every pre- and post-submit job
# It's a copy of Dockerfile.release with additional logic bumping serverless images in the values.yaml
#


# Build the operator binary
FROM golang:1.22.0 as builder

Expand All @@ -21,11 +21,14 @@ COPY components/operator components/operator
# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o operator ./components/operator/main.go


# Replace main images in values.yaml
# Bumping serverless images in the values.yaml - used for building "local" and "dev" images
FROM alpine:3.19.1 as replacer

WORKDIR /workspace

ARG PURPOSE
ARG IMG_DIRECTORY
ARG IMG_VERSION

Expand All @@ -38,7 +41,10 @@ COPY components/operator/hack components/operator/hack
COPY config/serverless config/serverless
COPY hack/ hack/

RUN make -C components/operator/hack/ci replace-function-chart-images
RUN if [[ "dev" = "$PURPOSE" ]] ; then make -C components/operator/hack/ci replace-function-chart-images ; fi
RUN if [[ "local" = "$PURPOSE" ]] ; then make -C components/operator/hack/ci replace-only-main-chart-images ; fi
# do nothing (keep unchanged versions) for "release"


# Use distroless as minimal base image to package the operator binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
Expand Down
52 changes: 0 additions & 52 deletions components/operator/Dockerfile.local

This file was deleted.

35 changes: 33 additions & 2 deletions components/operator/Dockerfile.release
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# TODO: This is exact copy of "Dockerfile" because test-infra use "Dockerfile.release" - remove this after changes in test-infra

#
# This Dockerfile is used to build serverless-operator image on every pre- and post-submit job
#


# Build the operator binary
FROM golang:1.22.0 as builder

Expand All @@ -12,18 +19,42 @@ RUN go mod download

# Copy the go source
COPY components/operator components/operator
COPY hack/ hack/

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o operator ./components/operator/main.go


# Replace main images in values.yaml
# Bumping serverless images in the values.yaml - used for building "local" and "dev" images
FROM alpine:3.19.1 as replacer

WORKDIR /workspace

ARG PURPOSE
ARG IMG_DIRECTORY
ARG IMG_VERSION

ENV IMG_DIRECTORY=$IMG_DIRECTORY
ENV IMG_VERSION=$IMG_VERSION

RUN apk update && apk add make yq

COPY components/operator/hack components/operator/hack
COPY config/serverless config/serverless
COPY hack/ hack/

RUN if [[ "dev" = "$PURPOSE" ]] ; then make -C components/operator/hack/ci replace-function-chart-images ; fi
RUN if [[ "local" = "$PURPOSE" ]] ; then make -C components/operator/hack/ci replace-only-main-chart-images ; fi
# do nothing (keep unchanged versions) for "release"


# Use distroless as minimal base image to package the operator binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot

WORKDIR /
COPY --chown=65532:65532 --from=builder /workspace/operator .
COPY --chown=65532:65532 config/serverless /module-chart
COPY --chown=65532:65532 --from=replacer /workspace/config/serverless /module-chart
USER 65532:65532

ENTRYPOINT ["/operator"]
4 changes: 2 additions & 2 deletions components/operator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ run: manifests generate fmt vet ## Run a controller from your host.

.PHONY: docker-build-dev
docker-build-dev: manifests generate ## Build docker dev image with the operator.
docker build -t ${IMG} -f Dockerfile.dev $(PROJECT_ROOT) --build-arg=IMG_DIRECTORY="$(IMG_DIRECTORY)" --build-arg=IMG_VERSION="$(IMG_VERSION)"
docker build -t ${IMG} -f Dockerfile $(PROJECT_ROOT) --build-arg=PURPOSE="dev" --build-arg=IMG_DIRECTORY="$(IMG_DIRECTORY)" --build-arg=IMG_VERSION="$(IMG_VERSION)"

.PHONY: docker-build-local
docker-build-local: manifests generate ## Build docker local image with the operator.
docker build -t ${IMG} -f Dockerfile.local $(PROJECT_ROOT) --build-arg=IMG_DIRECTORY="$(IMG_DIRECTORY)" --build-arg=IMG_VERSION="$(IMG_VERSION)"
docker build -t ${IMG} -f Dockerfile $(PROJECT_ROOT) --build-arg=PURPOSE="local" --build-arg=IMG_DIRECTORY="$(IMG_DIRECTORY)" --build-arg=IMG_VERSION="$(IMG_VERSION)"

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

0 comments on commit be89654

Please sign in to comment.