Skip to content

Commit 9c35214

Browse files
committed
Docker build: parameterize build images.
1 parent 7438a96 commit 9c35214

File tree

6 files changed

+45
-19
lines changed

6 files changed

+45
-19
lines changed

.github/workflows/e2e.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ on:
1111
workflow_dispatch:
1212

1313
env:
14-
GO_VERSION: "1.21.4"
14+
GO_TOOLCHAIN: "golang"
15+
GO_VERSION: "1.21.6"
16+
# TODO: match BASEIMAGE with Makefile default (nonroot variant)
17+
BASEIMAGE: "gcr.io/distroless/static-debian11"
1518
K8S_VERSION: "v1.27.3"
1619
KIND_CLUSTER_NAME: "kind"
1720

@@ -33,9 +36,9 @@ jobs:
3336
run: |
3437
mkdir _output
3538
36-
docker build -t gcr.io/k8s-staging-kas-network-proxy/proxy-agent:master -f artifacts/images/agent-build.Dockerfile .
39+
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 }} .
3740
docker save gcr.io/k8s-staging-kas-network-proxy/proxy-agent:master > _output/konnectivity-agent.tar
38-
docker build -t gcr.io/k8s-staging-kas-network-proxy/proxy-server:master -f artifacts/images/server-build.Dockerfile .
41+
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 }} .
3942
docker save gcr.io/k8s-staging-kas-network-proxy/proxy-server:master > _output/konnectivity-server.tar
4043
4144
- uses: actions/upload-artifact@v2

Makefile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ ARCH_LIST ?= amd64 arm arm64 ppc64le s390x
1717
RELEASE_ARCH_LIST = amd64 arm64
1818
# The output type could either be docker (local), or registry.
1919
OUTPUT_TYPE ?= docker
20+
GO_TOOLCHAIN ?= golang
21+
GO_VERSION ?= 1.21.6
22+
BASEIMAGE ?= gcr.io/distroless/static-debian11:nonroot
2023

2124
ifeq ($(GOPATH),)
2225
export GOPATH := $(shell go env GOPATH)
@@ -199,7 +202,7 @@ docker-push: docker-push/proxy-agent docker-push/proxy-server
199202
docker-build/proxy-agent: cmd/agent/main.go proto/agent/agent.pb.go buildx-setup
200203
@[ "${TAG}" ] || ( echo "TAG is not set"; exit 1 )
201204
echo "Building proxy-agent for ${ARCH}"
202-
${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}
205+
${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}
203206

204207
.PHONY: docker-push/proxy-agent
205208
docker-push/proxy-agent: docker-build/proxy-agent
@@ -210,7 +213,7 @@ docker-push/proxy-agent: docker-build/proxy-agent
210213
docker-build/proxy-server: cmd/server/main.go proto/agent/agent.pb.go buildx-setup
211214
@[ "${TAG}" ] || ( echo "TAG is not set"; exit 1 )
212215
echo "Building proxy-server for ${ARCH}"
213-
${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}
216+
${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}
214217

215218
.PHONY: docker-push/proxy-server
216219
docker-push/proxy-server: docker-build/proxy-server
@@ -221,7 +224,7 @@ docker-push/proxy-server: docker-build/proxy-server
221224
docker-build/proxy-test-client: cmd/test-client/main.go proto/agent/agent.pb.go buildx-setup
222225
@[ "${TAG}" ] || ( echo "TAG is not set"; exit 1 )
223226
echo "Building proxy-test-client for ${ARCH}"
224-
${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}
227+
${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}
225228

226229
.PHONY: docker-push/proxy-test-client
227230
docker-push/proxy-test-client: docker-build/proxy-test-client
@@ -232,7 +235,7 @@ docker-push/proxy-test-client: docker-build/proxy-test-client
232235
docker-build/http-test-server: cmd/test-server/main.go buildx-setup
233236
@[ "${TAG}" ] || ( echo "TAG is not set"; exit 1 )
234237
echo "Building http-test-server for ${ARCH}"
235-
${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}
238+
${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}
236239

237240
.PHONY: docker-push/http-test-server
238241
docker-push/http-test-server: docker-build/http-test-server

artifacts/images/agent-build.Dockerfile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Build the proxy-agent binary
2-
FROM golang:1.21.6 as builder
2+
3+
ARG GO_TOOLCHAIN
4+
ARG GO_VERSION
5+
ARG BASEIMAGE
6+
7+
FROM ${GO_TOOLCHAIN}:${GO_VERSION} as builder
38

49
# Copy in the go src
510
WORKDIR /go/src/sigs.k8s.io/apiserver-network-proxy
@@ -24,8 +29,8 @@ COPY proto/ proto/
2429
ARG ARCH
2530
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
2631

27-
# Copy the loader into a thin image
28-
FROM gcr.io/distroless/static-debian11:nonroot
32+
FROM ${BASEIMAGE}
33+
2934
WORKDIR /
3035
COPY --from=builder /go/src/sigs.k8s.io/apiserver-network-proxy/proxy-agent .
3136
ENTRYPOINT ["/proxy-agent"]

artifacts/images/server-build.Dockerfile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Build the proxy-server binary
2-
FROM golang:1.21.6 as builder
2+
3+
ARG GO_TOOLCHAIN
4+
ARG GO_VERSION
5+
ARG BASEIMAGE
6+
7+
FROM ${GO_TOOLCHAIN}:${GO_VERSION} as builder
38

49
# Copy in the go src
510
WORKDIR /go/src/sigs.k8s.io/apiserver-network-proxy
@@ -23,8 +28,8 @@ COPY proto/ proto/
2328
ARG ARCH
2429
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
2530

26-
# Copy the loader into a thin image
27-
FROM gcr.io/distroless/static-debian11:nonroot
31+
FROM ${BASEIMAGE}
32+
2833
WORKDIR /
2934
COPY --from=builder /go/src/sigs.k8s.io/apiserver-network-proxy/proxy-server .
3035
ENTRYPOINT ["/proxy-server"]

artifacts/images/test-client-build.Dockerfile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Build the client binary
2-
FROM golang:1.21.6 as builder
2+
3+
ARG GO_TOOLCHAIN
4+
ARG GO_VERSION
5+
ARG BASEIMAGE
6+
7+
FROM ${GO_TOOLCHAIN}:${GO_VERSION} as builder
38

49
# Copy in the go src
510
WORKDIR /go/src/sigs.k8s.io/apiserver-network-proxy
@@ -23,8 +28,8 @@ COPY proto/ proto/
2328
ARG ARCH
2429
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
2530

26-
# Copy the loader into a thin image
27-
FROM gcr.io/distroless/static-debian11
31+
FROM ${BASEIMAGE}
32+
2833
WORKDIR /
2934
COPY --from=builder /go/src/sigs.k8s.io/apiserver-network-proxy/proxy-test-client .
3035
ENTRYPOINT ["/proxy-test-client"]

artifacts/images/test-server-build.Dockerfile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Build the http test server binary
2-
FROM golang:1.21.6 as builder
2+
3+
ARG GO_TOOLCHAIN
4+
ARG GO_VERSION
5+
ARG BASEIMAGE
6+
7+
FROM ${GO_TOOLCHAIN}:${GO_VERSION} as builder
38

49
# Copy in the go src
510
WORKDIR /go/src/sigs.k8s.io/apiserver-network-proxy
@@ -22,8 +27,8 @@ COPY cmd/ cmd/
2227
ARG ARCH
2328
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
2429

25-
# Copy the loader into a thin image
26-
FROM gcr.io/distroless/static-debian11
30+
FROM ${BASEIMAGE}
31+
2732
WORKDIR /
2833
COPY --from=builder /go/src/sigs.k8s.io/apiserver-network-proxy/http-test-server .
2934
ENTRYPOINT ["/http-test-server"]

0 commit comments

Comments
 (0)