From 4c4a87e358a60cb16d4d9c4e2e4faff0f577181f Mon Sep 17 00:00:00 2001 From: Joseph Anttila Hall Date: Tue, 23 Jan 2024 16:45:49 -0800 Subject: [PATCH] Change build commands to use vendoring. --- Makefile | 26 ++++++++++--------- artifacts/images/agent-build.Dockerfile | 11 ++++---- artifacts/images/server-build.Dockerfile | 10 +++---- artifacts/images/test-client-build.Dockerfile | 10 +++---- artifacts/images/test-server-build.Dockerfile | 11 +++----- 5 files changed, 31 insertions(+), 37 deletions(-) diff --git a/Makefile b/Makefile index aa23c9990..5d7d663d6 100644 --- a/Makefile +++ b/Makefile @@ -57,36 +57,38 @@ mock_gen: .PHONY: test test: - go test -race -covermode=atomic -coverprofile=konnectivity.out ./... && go tool cover -html=konnectivity.out -o=konnectivity.html + go test -mod=vendor -race -covermode=atomic -coverprofile=konnectivity.out ./... && go tool cover -html=konnectivity.out -o=konnectivity.html cd konnectivity-client && go test -race -covermode=atomic -coverprofile=client.out ./... && go tool cover -html=client.out -o=client.html .PHONY: test-integration test-integration: build - go test -race ./tests -agent-path $(PWD)/bin/proxy-agent + go test -mod=vendor -race ./tests -agent-path $(PWD)/bin/proxy-agent ## -------------------------------------- ## Binaries ## -------------------------------------- -SOURCE = $(shell find . -name \*.go) - bin: mkdir -p bin .PHONY: build build: bin/proxy-agent bin/proxy-server bin/proxy-test-client bin/http-test-server -bin/proxy-agent: bin $(SOURCE) - GO111MODULE=on go build -o bin/proxy-agent cmd/agent/main.go +.PHONY: bin/proxy-agent +bin/proxy-agent: + GO111MODULE=on go build -mod=vendor -o bin/proxy-agent cmd/agent/main.go -bin/proxy-test-client: bin $(SOURCE) - GO111MODULE=on go build -o bin/proxy-test-client cmd/test-client/main.go +.PHONY: bin/proxy-test-client +bin/proxy-test-client: + GO111MODULE=on go build -mod=vendor -o bin/proxy-test-client cmd/test-client/main.go -bin/http-test-server: bin $(SOURCE) - GO111MODULE=on go build -o bin/http-test-server cmd/test-server/main.go +.PHONY: bin/http-test-server +bin/http-test-server: + GO111MODULE=on go build -mod=vendor -o bin/http-test-server cmd/test-server/main.go -bin/proxy-server: bin $(SOURCE) - GO111MODULE=on go build -o bin/proxy-server cmd/server/main.go +.PHONY: bin/proxy-server +bin/proxy-server: + GO111MODULE=on go build -mod=vendor -o bin/proxy-server cmd/server/main.go ## -------------------------------------- ## Linting diff --git a/artifacts/images/agent-build.Dockerfile b/artifacts/images/agent-build.Dockerfile index 57eeb4308..c54c52abc 100644 --- a/artifacts/images/agent-build.Dockerfile +++ b/artifacts/images/agent-build.Dockerfile @@ -8,22 +8,21 @@ WORKDIR /go/src/sigs.k8s.io/apiserver-network-proxy COPY go.mod go.mod COPY go.sum go.sum -# This is required before go mod download because we have a -# replace directive for konnectivity-client in go.mod -# The download will fail without the directory present +# We have a replace directive for konnectivity-client in go.mod COPY konnectivity-client/ konnectivity-client/ -# Cache dependencies -RUN go mod download +# Copy vendored modules +COPY vendor/ vendor/ # Copy the sources COPY pkg/ pkg/ COPY cmd/ cmd/ COPY proto/ proto/ + # Build ARG ARCH -RUN CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} go build -v -a -ldflags '-extldflags "-static"' -o proxy-agent sigs.k8s.io/apiserver-network-proxy/cmd/agent +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 diff --git a/artifacts/images/server-build.Dockerfile b/artifacts/images/server-build.Dockerfile index f7f49dcea..5587faad0 100644 --- a/artifacts/images/server-build.Dockerfile +++ b/artifacts/images/server-build.Dockerfile @@ -8,13 +8,11 @@ WORKDIR /go/src/sigs.k8s.io/apiserver-network-proxy COPY go.mod go.mod COPY go.sum go.sum -# This is required before go mod download because we have a -# replace directive for konnectivity-client in go.mod -# The download will fail without the directory present +# We have a replace directive for konnectivity-client in go.mod COPY konnectivity-client/ konnectivity-client/ -# Cache dependencies -RUN go mod download +# Copy vendored modules +COPY vendor/ vendor/ # Copy the sources COPY pkg/ pkg/ @@ -23,7 +21,7 @@ COPY proto/ proto/ # Build ARG ARCH -RUN CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} go build -v -a -ldflags '-extldflags "-static"' -o proxy-server sigs.k8s.io/apiserver-network-proxy/cmd/server +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 diff --git a/artifacts/images/test-client-build.Dockerfile b/artifacts/images/test-client-build.Dockerfile index 71f44a4a8..b24e11e68 100644 --- a/artifacts/images/test-client-build.Dockerfile +++ b/artifacts/images/test-client-build.Dockerfile @@ -8,13 +8,11 @@ WORKDIR /go/src/sigs.k8s.io/apiserver-network-proxy COPY go.mod go.mod COPY go.sum go.sum -# This is required before go mod download because we have a -# replace directive for konnectivity-client in go.mod -# The download will fail without the directory present +# We have a replace directive for konnectivity-client in go.mod COPY konnectivity-client/ konnectivity-client/ -# Cache dependencies -RUN go mod download +# Copy vendored modules +COPY vendor/ vendor/ # Copy the sources COPY pkg/ pkg/ @@ -23,7 +21,7 @@ COPY proto/ proto/ # Build ARG ARCH -RUN CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} go build -v -a -ldflags '-extldflags "-static"' -o proxy-test-client sigs.k8s.io/apiserver-network-proxy/cmd/test-client +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 diff --git a/artifacts/images/test-server-build.Dockerfile b/artifacts/images/test-server-build.Dockerfile index 3c55310ea..feb837d3d 100644 --- a/artifacts/images/test-server-build.Dockerfile +++ b/artifacts/images/test-server-build.Dockerfile @@ -8,14 +8,11 @@ WORKDIR /go/src/sigs.k8s.io/apiserver-network-proxy COPY go.mod go.mod COPY go.sum go.sum - -# This is required before go mod download because we have a -# replace directive for konnectivity-client in go.mod -# The download will fail without the directory present +# We have a replace directive for konnectivity-client in go.mod COPY konnectivity-client/ konnectivity-client/ -# Cache dependencies -RUN go mod download +# Copy vendored modules +COPY vendor/ vendor/ # Copy the sources COPY pkg/ pkg/ @@ -23,7 +20,7 @@ COPY cmd/ cmd/ # Build ARG ARCH -RUN CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} go build -v -a -ldflags '-extldflags "-static"' -o http-test-server sigs.k8s.io/apiserver-network-proxy/cmd/test-server +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