Skip to content

Commit

Permalink
Resolving merge conflict vmware-tanzu#3972 Post Merger
Browse files Browse the repository at this point in the history
  • Loading branch information
mohitsharma-in committed Feb 27, 2023
2 parents 45edd14 + ae612fb commit 45b75aa
Show file tree
Hide file tree
Showing 25 changed files with 157 additions and 27 deletions.
9 changes: 6 additions & 3 deletions addons/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@
# Build from publicly reachable source by default, but allow people to re-build images on
# top of their own trusted images.
ARG BUILDER_BASE_IMAGE=golang:1.18

ARG DISTROLESS_BASE_IMAGE=gcr.io/distroless/static:nonroot
# Build the manager binary
FROM $BUILDER_BASE_IMAGE as builder
WORKDIR /workspace
# Copy the go source
COPY ./ ./


# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
ARG GOSUMDB
ARG GOPROXY
ENV GOSUMDB=$GOSUMDB
ENV GOPROXY=$GOPROXY
RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/root/.local/share/golang --mount=type=cache,target=/go/pkg/mod go mod download

# Build
Expand All @@ -26,7 +29,7 @@ RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/r

# 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 $DISTROLESS_BASE_IMAGE
WORKDIR /
COPY --from=builder /workspace/addons/bin/manager .
USER nonroot:nonroot
Expand Down
7 changes: 6 additions & 1 deletion addons/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ IMG_DEFAULT_NAME_TAG := $(IMG_DEFAULT_NAME):latest

IMG_VERSION_OVERRIDE ?= $(shell git describe --always --dirty --tags)

#Adding Support for GOPROXY and GOSUMDB
GOPROXY ?= "https://proxy.golang.org,direct"
GOSUMDB ?= off
DISTROLESS_BASE_IMAGE ?= gcr.io/distroless/static:nonroot

ifeq ($(strip $(OCI_REGISTRY)),)
IMG ?= $(IMG_DEFAULT_NAME):$(IMG_VERSION_OVERRIDE)
else
Expand Down Expand Up @@ -87,7 +92,7 @@ run: fmt vet ## Run locally

.PHONY: docker-build
docker-build: ## Build the docker image
cd .. && docker build -t $(IMG) -f addons/Dockerfile --build-arg LD_FLAGS="$(LD_FLAGS)" .
cd .. && docker build -t $(IMG) -f addons/Dockerfile --build-arg LD_FLAGS="$(LD_FLAGS)" --build-arg DISTROLESS_BASE_IMAGE="$(DISTROLESS_BASE_IMAGE)" --build-arg GOPROXY="$(GOPROXY)" --build-arg GOSUMDB="$(GOSUMDB)" .

.PHONY: docker-push
docker-push: ## Push the docker image
Expand Down
7 changes: 6 additions & 1 deletion capabilities/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ endif

CRD_OPTIONS ?= "crd"

#Adding Support for GOPROXY and GOSUMDB
GOPROXY ?= "https://proxy.golang.org,direct"
GOSUMDB ?= off
DISTROLESS_BASE_IMAGE ?= gcr.io/distroless/static:nonroot

all: manager

# Run tests
Expand Down Expand Up @@ -68,7 +73,7 @@ endif

.PHONY: docker-build
docker-build:
cd .. && docker build -t $(IMG) -f capabilities/controller/Dockerfile --build-arg LD_FLAGS="$(LD_FLAGS)" .
cd .. && docker build -t $(IMG) -f capabilities/controller/Dockerfile --build-arg LD_FLAGS="$(LD_FLAGS)" --build-arg DISTROLESS_BASE_IMAGE="$(DISTROLESS_BASE_IMAGE)" --build-arg GOPROXY="$(GOPROXY)" --build-arg GOSUMDB="$(GOSUMDB)" .

.PHONY: docker-publish
docker-publish: ## Publish docker image
Expand Down
7 changes: 6 additions & 1 deletion capabilities/controller/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Build from publicly reachable source by default, but allow people to re-build images on
# top of their own trusted images.
ARG BUILDER_BASE_IMAGE=golang:1.18
ARG DISTROLESS_BASE_IMAGE=gcr.io/distroless/static:nonroot

# Build the manager binary
FROM $BUILDER_BASE_IMAGE as builder
Expand All @@ -17,6 +18,10 @@ COPY apis/ apis/
COPY cli/runtime cli/runtime

WORKDIR capabilities/controller
ARG GOSUMDB
ARG GOPROXY
ENV GOSUMDB=$GOSUMDB
ENV GOPROXY=$GOPROXY
RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/root/.local/share/golang --mount=type=cache,target=/go/pkg/mod go mod download

# Build
Expand All @@ -26,7 +31,7 @@ RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/r

# 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 $DISTROLESS_BASE_IMAGE
WORKDIR /
COPY --from=builder /workspace/capabilities/controller/manager .
USER nonroot:nonroot
Expand Down
7 changes: 6 additions & 1 deletion featuregates/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ endif

CRD_OPTIONS ?= "crd"

#Adding Support for GOPROXY and GOSUMDB
GOPROXY ?= "https://proxy.golang.org,direct"
GOSUMDB ?= off
DISTROLESS_BASE_IMAGE ?= gcr.io/distroless/static:nonroot

all: manager

# Run tests
Expand All @@ -34,7 +39,7 @@ run:

.PHONY: docker-build
docker-build: ## Build docker image
cd ../ && docker build -t $(IMG) -f featuregates/controller/Dockerfile --build-arg LD_FLAGS="$(LD_FLAGS)" .
cd ../ && docker build -t $(IMG) -f featuregates/controller/Dockerfile --build-arg LD_FLAGS="$(LD_FLAGS)" --build-arg DISTROLESS_BASE_IMAGE="$(DISTROLESS_BASE_IMAGE)" --build-arg GOPROXY="$(GOPROXY)" --build-arg GOSUMDB="$(GOSUMDB)" .

.PHONY: docker-publish
docker-publish: ## Publish docker image
Expand Down
8 changes: 7 additions & 1 deletion featuregates/controller/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# Build from publicly reachable source by default, but allow people to re-build images on
# top of their own trusted images.
ARG BUILDER_BASE_IMAGE=golang:1.18
ARG DISTROLESS_BASE_IMAGE=gcr.io/distroless/static:nonroot

# Build the manager binary
FROM $BUILDER_BASE_IMAGE as builder
Expand All @@ -21,6 +22,11 @@ COPY cli/runtime cli/runtime
COPY capabilities/client capabilities/client

WORKDIR featuregates/controller
ARG GOSUMDB
ARG GOPROXY
ENV GOSUMDB=$GOSUMDB
ENV GOPROXY=$GOPROXY

RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/root/.local/share/golang --mount=type=cache,target=/go/pkg/mod go mod download
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
Expand All @@ -37,7 +43,7 @@ RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/r

# 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 $DISTROLESS_BASE_IMAGE
WORKDIR /
COPY --from=builder /workspace/featuregates/controller/manager .
USER nonroot:nonroot
Expand Down
7 changes: 6 additions & 1 deletion object-propagation/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# Build from publicly reachable source by default, but allow people to re-build images on
# top of their own trusted images.
ARG BUILDER_BASE_IMAGE=golang:1.18
ARG DISTROLESS_BASE_IMAGE=gcr.io/distroless/static:nonroot

# Build the manager binary
FROM $BUILDER_BASE_IMAGE as builder
Expand All @@ -21,6 +22,10 @@ COPY object-propagation/go.mod object-propagation/go.mod
COPY object-propagation/go.sum object-propagation/go.sum

WORKDIR /workspace/object-propagation
ARG GOSUMDB
ARG GOPROXY
ENV GOSUMDB=$GOSUMDB
ENV GOPROXY=$GOPROXY
RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/root/.local/share/golang --mount=type=cache,target=/go/pkg/mod go mod download
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
Expand All @@ -35,7 +40,7 @@ RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/r

# 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 $DISTROLESS_BASE_IMAGE
WORKDIR /
COPY --from=builder /workspace/object-propagation/manager .
USER nonroot:nonroot
Expand Down
7 changes: 6 additions & 1 deletion object-propagation/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ else
IMG ?= $(OCI_REGISTRY)/$(IMG_DEFAULT_NAME):$(IMG_VERSION_OVERRIDE)
endif

#Adding Support for GOPROXY and GOSUMDB
GOPROXY ?= "https://proxy.golang.org,direct"
GOSUMDB ?= off
DISTROLESS_BASE_IMAGE ?= gcr.io/distroless/static:nonroot

all: manager

# Run tests
Expand All @@ -35,7 +40,7 @@ vet:

.PHONY: docker-build
docker-build: ## Build docker image
cd ../ && docker build -t $(IMG) -f object-propagation/Dockerfile --build-arg LD_FLAGS="$(LD_FLAGS)" .
cd ../ && docker build -t $(IMG) -f object-propagation/Dockerfile --build-arg LD_FLAGS="$(LD_FLAGS)" --build-arg DISTROLESS_BASE_IMAGE="$(DISTROLESS_BASE_IMAGE)" --build-arg GOPROXY="$(GOPROXY)" --build-arg GOSUMDB="$(GOSUMDB)" .

.PHONY: docker-publish
docker-publish: ## Publish docker image
Expand Down
8 changes: 6 additions & 2 deletions pinniped-components/post-deploy/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Build from publicly reachable source by default, but allow people to re-build images on
# top of their own trusted images.
ARG BUILDER_BASE_IMAGE=golang:1.18
ARG DISTROLESS_BASE_IMAGE=gcr.io/distroless/static:nonroot

# Build the post-deploy binary
FROM $BUILDER_BASE_IMAGE as builder
Expand All @@ -23,7 +24,10 @@ COPY post-deploy/cmd/ post-deploy/cmd/
COPY post-deploy/pkg/ post-deploy/pkg/
COPY post-deploy/Makefile post-deploy/Makefile
#COPY .git/ .git/

ARG GOSUMDB
ARG GOPROXY
ENV GOSUMDB=$GOSUMDB
ENV GOPROXY=$GOPROXY
RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/root/.local/share/golang --mount=type=cache,target=/go/pkg/mod make native -C post-deploy

# Support older deployment YAMLs by providing symlink for the historic job name without -job.
Expand All @@ -32,7 +36,7 @@ RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/r
RUN mkdir -p /tmp/links
RUN ln -s /tkg-pinniped-post-deploy-job /tmp/links/tkg-pinniped-post-deploy

FROM gcr.io/distroless/static:nonroot
FROM $DISTROLESS_BASE_IMAGE
WORKDIR /
# Make sure to copy the symlink.
COPY --from=builder /tmp/links/ .
Expand Down
7 changes: 6 additions & 1 deletion pinniped-components/post-deploy/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ GIT_VERSION ?= $(shell git describe --always --tags)
GIT_REF_LONG = $(shell git rev-parse --verify HEAD)
# Release version
VERSION ?= $(GIT_VERSION)
#Adding Support for GOPROXY and GOSUMDB
GOPROXY ?= "https://proxy.golang.org,direct"
GOSUMDB ?= off
DISTROLESS_BASE_IMAGE ?= gcr.io/distroless/static:nonroot


.PHONY: test
test: fmt vet ## Run tests
Expand All @@ -29,7 +34,7 @@ native: ## Build binary

.PHONY: build-images
build-images: ## Build tkg-pinniped-post-deploy docker images
VERSION=$(VERSION) ./hack/scripts/build-images.sh
VERSION=$(VERSION) DISTROLESS_BASE_IMAGE=$(DISTROLESS_BASE_IMAGE) ./hack/scripts/build-images.sh

run:
go run ./cmd/job \
Expand Down
8 changes: 8 additions & 0 deletions pinniped-components/post-deploy/hack/scripts/build-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,22 @@ FULL_IMAGE_TAR_NAME="${IMAGE_NAME}-${IMAGE_TAG}"
# Build from publicly reachable source by default, but allow people to re-build images on
# top of their own trusted images.
BUILDER_BASE_IMAGE="${BUILDER_BASE_IMAGE:-}"
DISTROLESS_BASE_IMAGE="${DISTROLESS_BASE_IMAGE}"

if [[ -z "${BUILDER_BASE_IMAGE}" ]];
then
docker build \
--build-arg DISTROLESS_BASE_IMAGE="${DISTROLESS_BASE_IMAGE}" \
--build-arg GOPROXY="${GOPROXY}" \
--build-arg GOSUMDB="${GOSUMDB}" \
-t "${FULL_IMAGE_NAME}" \
-f "${ROOT_DIR}"/Dockerfile ..
else
docker build \
--build-arg BUILDER_BASE_IMAGE="${BUILDER_BASE_IMAGE}" \
--build-arg DISTROLESS_BASE_IMAGE="${DISTROLESS_BASE_IMAGE}" \
--build-arg GOPROXY="${GOPROXY}" \
--build-arg GOSUMDB="${GOSUMDB}" \
-t "${FULL_IMAGE_NAME}" \
-f "${ROOT_DIR}"/Dockerfile ..
fi
Expand Down
7 changes: 6 additions & 1 deletion pinniped-components/tanzu-auth-controller-manager/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# Build from publicly reachable source by default, but allow people to re-build images on
# top of their own trusted images.
ARG BUILDER_BASE_IMAGE=golang:1.18
ARG DISTROLESS_BASE_IMAGE=gcr.io/distroless/static:nonroot

# Build the tanzu-auth-controller-manager binary
FROM $BUILDER_BASE_IMAGE as builder
Expand All @@ -15,6 +16,10 @@ WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
ARG GOSUMDB
ARG GOPROXY
ENV GOSUMDB=$GOSUMDB
ENV GOPROXY=$GOPROXY
RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/root/.local/share/golang --mount=type=cache,target=/go/pkg/mod go mod download

# Copy the source
Expand All @@ -26,7 +31,7 @@ ARG LD_FLAGS
ENV LD_FLAGS="$LD_FLAGS "'-extldflags "-static"'
RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/root/.local/share/golang --mount=type=cache,target=/go/pkg/mod CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -ldflags "$LD_FLAGS" -o tanzu-auth-controller-manager .

FROM gcr.io/distroless/static:nonroot
FROM $DISTROLESS_BASE_IMAGE
WORKDIR /
COPY --from=builder /workspace/tanzu-auth-controller-manager .
USER nonroot:nonroot
Expand Down
7 changes: 6 additions & 1 deletion pinniped-components/tanzu-auth-controller-manager/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ IMG_DEFAULT_NAME_TAG := $(IMG_DEFAULT_NAME):$(IMG_DEFAULT_TAG)

IMG_VERSION_OVERRIDE ?= $(IMG_DEFAULT_TAG)

#Adding Support for GOPROXY and GOSUMDB
GOPROXY ?= "https://proxy.golang.org,direct"
GOSUMDB ?= off
DISTROLESS_BASE_IMAGE ?= gcr.io/distroless/static:nonroot

ifeq ($(strip $(OCI_REGISTRY)),)
IMG ?= $(IMG_DEFAULT_NAME):$(IMG_VERSION_OVERRIDE)
else
Expand All @@ -38,7 +43,7 @@ endif

.PHONY: docker-build
docker-build: ## Build docker image
docker build -t $(IMG) -f Dockerfile --build-arg LD_FLAGS="$(LD_FLAGS)" .
docker build -t $(IMG) -f Dockerfile --build-arg LD_FLAGS="$(LD_FLAGS)" --build-arg DISTROLESS_BASE_IMAGE="$(DISTROLESS_BASE_IMAGE)" --build-arg GOPROXY="$(GOPROXY)" --build-arg GOSUMDB="$(GOSUMDB)" .

.PHONY: docker-publish
docker-publish: ## Publish docker image
Expand Down
7 changes: 6 additions & 1 deletion pkg/v1/tkr/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Build from publicly reachable source by default, but allow people to re-build images on
# top of their own trusted images.
ARG BUILDER_BASE_IMAGE=golang:1.18
ARG DISTROLESS_BASE_IMAGE=gcr.io/distroless/static:nonroot

# Build the manager binary
FROM $BUILDER_BASE_IMAGE as builder
Expand All @@ -19,6 +20,10 @@ COPY pkg/v1/tkr/go.mod pkg/v1/tkr/go.mod
COPY pkg/v1/tkr/go.sum pkg/v1/tkr/go.sum

WORKDIR /workspace/pkg/v1/tkr
ARG GOSUMDB
ARG GOPROXY
ENV GOSUMDB=$GOSUMDB
ENV GOPROXY=$GOPROXY
RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/root/.local/share/golang --mount=type=cache,target=/go/pkg/mod go mod download
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
Expand All @@ -33,7 +38,7 @@ RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/r

# 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 $DISTROLESS_BASE_IMAGE
WORKDIR /
COPY --from=builder /workspace/pkg/v1/tkr/manager .
USER nonroot:nonroot
Expand Down
7 changes: 6 additions & 1 deletion pkg/v1/tkr/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ include ../../../common.mk
IMG ?= tkr-controller-manager:latest
CRD_OPTIONS ?= "crd"

#Adding Support for GOPROXY and GOSUMDB
GOPROXY ?= "https://proxy.golang.org,direct"
GOSUMDB ?= off
DISTROLESS_BASE_IMAGE ?= gcr.io/distroless/static:nonroot

all: manager

# Run tests
Expand Down Expand Up @@ -61,4 +66,4 @@ fakes: ## Generate fake files for go unit tests

.PHONY: docker-build
docker-build:
cd ../../../ && docker build -t $(IMG) -f pkg/v1/tkr/Dockerfile --build-arg LD_FLAGS="$(LD_FLAGS)" .
cd ../../../ && docker build -t $(IMG) -f pkg/v1/tkr/Dockerfile --build-arg LD_FLAGS="$(LD_FLAGS)" --build-arg DISTROLESS_BASE_IMAGE="$(DISTROLESS_BASE_IMAGE)" --build-arg GOPROXY="$(GOPROXY)" --build-arg GOSUMDB="$(GOSUMDB)" .
7 changes: 6 additions & 1 deletion tkg/vsphere-template-resolver/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Build from publicly reachable source by default, but allow people to re-build images on
# top of their own trusted images.
ARG BUILDER_BASE_IMAGE=golang:1.18
ARG DISTROLESS_BASE_IMAGE=gcr.io/distroless/static:nonroot

# Build the manager binary
FROM $BUILDER_BASE_IMAGE as builder
Expand All @@ -27,6 +28,10 @@ COPY tkg/go.mod tkg/go.mod
COPY tkg/go.sum tkg/go.sum

WORKDIR /workspace/tkg
ARG GOSUMDB
ARG GOPROXY
ENV GOSUMDB=$GOSUMDB
ENV GOPROXY=$GOPROXY
RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/root/.local/share/golang --mount=type=cache,target=/go/pkg/mod go mod download
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
Expand All @@ -41,7 +46,7 @@ RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/r

# 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 $DISTROLESS_BASE_IMAGE
WORKDIR /
COPY --from=builder /workspace/tkg/manager .
USER nonroot:nonroot
Expand Down
Loading

0 comments on commit 45b75aa

Please # to comment.