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

Docker build: parameterize base images. #572

Merged
merged 1 commit into from
Mar 7, 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
9 changes: 6 additions & 3 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ on:
workflow_dispatch:

env:
GO_VERSION: "1.21.4"
GO_TOOLCHAIN: "golang"
GO_VERSION: "1.21.6"
# TODO: match BASEIMAGE with Makefile default (nonroot variant)
BASEIMAGE: "gcr.io/distroless/static-debian11"
K8S_VERSION: "v1.27.3"
KIND_CLUSTER_NAME: "kind"

Expand All @@ -33,9 +36,9 @@ jobs:
run: |
mkdir _output

docker build -t gcr.io/k8s-staging-kas-network-proxy/proxy-agent:master -f artifacts/images/agent-build.Dockerfile .
docker build -t gcr.io/k8s-staging-kas-network-proxy/proxy-agent:master -f artifacts/images/agent-build.Dockerfile --build-arg GO_TOOLCHAIN=${{ env.GO_TOOLCHAIN }} --build-arg GO_VERSION=${{ env.GO_VERSION }} --build-arg BASEIMAGE=${{ env.BASEIMAGE }} .
docker save gcr.io/k8s-staging-kas-network-proxy/proxy-agent:master > _output/konnectivity-agent.tar
docker build -t gcr.io/k8s-staging-kas-network-proxy/proxy-server:master -f artifacts/images/server-build.Dockerfile .
docker build -t gcr.io/k8s-staging-kas-network-proxy/proxy-server:master -f artifacts/images/server-build.Dockerfile --build-arg GO_TOOLCHAIN=${{ env.GO_TOOLCHAIN }} --build-arg GO_VERSION=${{ env.GO_VERSION }} --build-arg BASEIMAGE=${{ env.BASEIMAGE }} .
docker save gcr.io/k8s-staging-kas-network-proxy/proxy-server:master > _output/konnectivity-server.tar

- uses: actions/upload-artifact@v2
Expand Down
11 changes: 7 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ ARCH_LIST ?= amd64 arm arm64 ppc64le s390x
RELEASE_ARCH_LIST = amd64 arm64
# The output type could either be docker (local), or registry.
OUTPUT_TYPE ?= docker
GO_TOOLCHAIN ?= golang
GO_VERSION ?= 1.21.6
BASEIMAGE ?= gcr.io/distroless/static-debian11:nonroot

ifeq ($(GOPATH),)
export GOPATH := $(shell go env GOPATH)
Expand Down Expand Up @@ -199,7 +202,7 @@ docker-push: docker-push/proxy-agent docker-push/proxy-server
docker-build/proxy-agent: cmd/agent/main.go proto/agent/agent.pb.go buildx-setup
@[ "${TAG}" ] || ( echo "TAG is not set"; exit 1 )
echo "Building proxy-agent for ${ARCH}"
${DOCKER_CMD} buildx build . --pull --output=type=$(OUTPUT_TYPE) --platform linux/$(ARCH) --build-arg ARCH=$(ARCH) -f artifacts/images/agent-build.Dockerfile -t ${AGENT_FULL_IMAGE}-$(ARCH):${TAG}
${DOCKER_CMD} buildx build . --pull --output=type=$(OUTPUT_TYPE) --platform linux/$(ARCH) --build-arg GO_TOOLCHAIN=$(GO_TOOLCHAIN) --build-arg GO_VERSION=$(GO_VERSION) --build-arg ARCH=$(ARCH) --build-arg BASEIMAGE=$(BASEIMAGE) -f artifacts/images/agent-build.Dockerfile -t ${AGENT_FULL_IMAGE}-$(ARCH):${TAG}

.PHONY: docker-push/proxy-agent
docker-push/proxy-agent: docker-build/proxy-agent
Expand All @@ -210,7 +213,7 @@ docker-push/proxy-agent: docker-build/proxy-agent
docker-build/proxy-server: cmd/server/main.go proto/agent/agent.pb.go buildx-setup
@[ "${TAG}" ] || ( echo "TAG is not set"; exit 1 )
echo "Building proxy-server for ${ARCH}"
${DOCKER_CMD} buildx build . --pull --output=type=$(OUTPUT_TYPE) --platform linux/$(ARCH) --build-arg ARCH=$(ARCH) -f artifacts/images/server-build.Dockerfile -t ${SERVER_FULL_IMAGE}-$(ARCH):${TAG}
${DOCKER_CMD} buildx build . --pull --output=type=$(OUTPUT_TYPE) --platform linux/$(ARCH) --build-arg GO_TOOLCHAIN=$(GO_TOOLCHAIN) --build-arg GO_VERSION=$(GO_VERSION) --build-arg ARCH=$(ARCH) --build-arg BASEIMAGE=$(BASEIMAGE) -f artifacts/images/server-build.Dockerfile -t ${SERVER_FULL_IMAGE}-$(ARCH):${TAG}

.PHONY: docker-push/proxy-server
docker-push/proxy-server: docker-build/proxy-server
Expand All @@ -221,7 +224,7 @@ docker-push/proxy-server: docker-build/proxy-server
docker-build/proxy-test-client: cmd/test-client/main.go proto/agent/agent.pb.go buildx-setup
@[ "${TAG}" ] || ( echo "TAG is not set"; exit 1 )
echo "Building proxy-test-client for ${ARCH}"
${DOCKER_CMD} buildx build . --pull --output=type=$(OUTPUT_TYPE) --platform linux/$(ARCH) --build-arg ARCH=$(ARCH) -f artifacts/images/test-client-build.Dockerfile -t ${TEST_CLIENT_FULL_IMAGE}-$(ARCH):${TAG}
${DOCKER_CMD} buildx build . --pull --output=type=$(OUTPUT_TYPE) --platform linux/$(ARCH) --build-arg GO_TOOLCHAIN=$(GO_TOOLCHAIN) --build-arg GO_VERSION=$(GO_VERSION) --build-arg ARCH=$(ARCH) --build-arg BASEIMAGE=$(BASEIMAGE) -f artifacts/images/test-client-build.Dockerfile -t ${TEST_CLIENT_FULL_IMAGE}-$(ARCH):${TAG}

.PHONY: docker-push/proxy-test-client
docker-push/proxy-test-client: docker-build/proxy-test-client
Expand All @@ -232,7 +235,7 @@ docker-push/proxy-test-client: docker-build/proxy-test-client
docker-build/http-test-server: cmd/test-server/main.go buildx-setup
@[ "${TAG}" ] || ( echo "TAG is not set"; exit 1 )
echo "Building http-test-server for ${ARCH}"
${DOCKER_CMD} buildx build . --pull --output=type=$(OUTPUT_TYPE) --platform linux/$(ARCH) --build-arg ARCH=$(ARCH) -f artifacts/images/test-server-build.Dockerfile -t ${TEST_SERVER_FULL_IMAGE}-$(ARCH):${TAG}
${DOCKER_CMD} buildx build . --pull --output=type=$(OUTPUT_TYPE) --platform linux/$(ARCH) --build-arg GO_TOOLCHAIN=$(GO_TOOLCHAIN) --build-arg GO_VERSION=$(GO_VERSION) --build-arg ARCH=$(ARCH) --build-arg BASEIMAGE=$(BASEIMAGE) -f artifacts/images/test-server-build.Dockerfile -t ${TEST_SERVER_FULL_IMAGE}-$(ARCH):${TAG}

.PHONY: docker-push/http-test-server
docker-push/http-test-server: docker-build/http-test-server
Expand Down
11 changes: 8 additions & 3 deletions artifacts/images/agent-build.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Build the proxy-agent binary
FROM golang:1.21.6 as builder

ARG GO_TOOLCHAIN
ARG GO_VERSION
ARG BASEIMAGE

FROM ${GO_TOOLCHAIN}:${GO_VERSION} as builder

# Copy in the go src
WORKDIR /go/src/sigs.k8s.io/apiserver-network-proxy
Expand All @@ -24,8 +29,8 @@ COPY proto/ proto/
ARG ARCH
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} go build -mod=vendor -v -a -ldflags '-extldflags "-static"' -o proxy-agent sigs.k8s.io/apiserver-network-proxy/cmd/agent

# Copy the loader into a thin image
FROM gcr.io/distroless/static-debian11:nonroot
FROM ${BASEIMAGE}

WORKDIR /
COPY --from=builder /go/src/sigs.k8s.io/apiserver-network-proxy/proxy-agent .
ENTRYPOINT ["/proxy-agent"]
11 changes: 8 additions & 3 deletions artifacts/images/server-build.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Build the proxy-server binary
FROM golang:1.21.6 as builder

ARG GO_TOOLCHAIN
ARG GO_VERSION
ARG BASEIMAGE

FROM ${GO_TOOLCHAIN}:${GO_VERSION} as builder

# Copy in the go src
WORKDIR /go/src/sigs.k8s.io/apiserver-network-proxy
Expand All @@ -23,8 +28,8 @@ COPY proto/ proto/
ARG ARCH
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} go build -mod=vendor -v -a -ldflags '-extldflags "-static"' -o proxy-server sigs.k8s.io/apiserver-network-proxy/cmd/server

# Copy the loader into a thin image
FROM gcr.io/distroless/static-debian11:nonroot
FROM ${BASEIMAGE}

WORKDIR /
COPY --from=builder /go/src/sigs.k8s.io/apiserver-network-proxy/proxy-server .
ENTRYPOINT ["/proxy-server"]
11 changes: 8 additions & 3 deletions artifacts/images/test-client-build.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Build the client binary
FROM golang:1.21.6 as builder

ARG GO_TOOLCHAIN
ARG GO_VERSION
ARG BASEIMAGE

FROM ${GO_TOOLCHAIN}:${GO_VERSION} as builder

# Copy in the go src
WORKDIR /go/src/sigs.k8s.io/apiserver-network-proxy
Expand All @@ -23,8 +28,8 @@ COPY proto/ proto/
ARG ARCH
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} go build -mod=vendor -v -a -ldflags '-extldflags "-static"' -o proxy-test-client sigs.k8s.io/apiserver-network-proxy/cmd/test-client

# Copy the loader into a thin image
FROM gcr.io/distroless/static-debian11
FROM ${BASEIMAGE}

WORKDIR /
COPY --from=builder /go/src/sigs.k8s.io/apiserver-network-proxy/proxy-test-client .
ENTRYPOINT ["/proxy-test-client"]
11 changes: 8 additions & 3 deletions artifacts/images/test-server-build.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Build the http test server binary
FROM golang:1.21.6 as builder

ARG GO_TOOLCHAIN
ARG GO_VERSION
ARG BASEIMAGE

FROM ${GO_TOOLCHAIN}:${GO_VERSION} as builder

# Copy in the go src
WORKDIR /go/src/sigs.k8s.io/apiserver-network-proxy
Expand All @@ -22,8 +27,8 @@ COPY cmd/ cmd/
ARG ARCH
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} go build -mod=vendor -v -a -ldflags '-extldflags "-static"' -o http-test-server sigs.k8s.io/apiserver-network-proxy/cmd/test-server

# Copy the loader into a thin image
FROM gcr.io/distroless/static-debian11
FROM ${BASEIMAGE}

WORKDIR /
COPY --from=builder /go/src/sigs.k8s.io/apiserver-network-proxy/http-test-server .
ENTRYPOINT ["/http-test-server"]
Loading