From b4263ef4e5d99d31d34834211d4d432e74e9c6ab Mon Sep 17 00:00:00 2001 From: Saylor Berman Date: Thu, 17 Aug 2023 11:23:03 -0600 Subject: [PATCH 1/4] Fix builder docker image Problem: The builder docker image was out of date and didn't copy the correct files. Solution: Copy the whole directory and run the make command to ensure everything is always in sync. --- build/Dockerfile | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/build/Dockerfile b/build/Dockerfile index b43d7f6c71..9c57f624ab 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -4,15 +4,10 @@ ARG VERSION ARG GIT_COMMIT ARG DATE -WORKDIR /go/src/github.com/nginxinc/nginx-kubernetes-gateway/cmd/gateway +WORKDIR /go/src/github.com/nginxinc/nginx-kubernetes-gateway -COPY go.mod go.sum /go/src/github.com/nginxinc/nginx-kubernetes-gateway -RUN go mod download - -COPY cmd /go/src/github.com/nginxinc/nginx-kubernetes-gateway/cmd -COPY internal /go/src/github.com/nginxinc/nginx-kubernetes-gateway/internal -COPY pkg /go/src/github.com/nginxinc/nginx-kubernetes-gateway/pkg -RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -a -ldflags "-s -w -X main.version=${VERSION} -X main.commit=${GIT_COMMIT} -X main.date=${DATE}" -o gateway . +COPY . /go/src/github.com/nginxinc/nginx-kubernetes-gateway +RUN make build FROM alpine:3.18 as capabilizer RUN apk add --no-cache libcap @@ -22,7 +17,7 @@ COPY ./build/out/gateway /usr/bin/ RUN setcap 'cap_kill=+ep' /usr/bin/gateway FROM capabilizer as container-capabilizer -COPY --from=builder /go/src/github.com/nginxinc/nginx-kubernetes-gateway/cmd/gateway/gateway /usr/bin/ +COPY --from=builder /go/src/github.com/nginxinc/nginx-kubernetes-gateway/build/out/gateway /usr/bin/ RUN setcap 'cap_kill=+ep' /usr/bin/gateway FROM capabilizer as goreleaser-capabilizer From df27dd04b64250f00c27977ea877176037350df8 Mon Sep 17 00:00:00 2001 From: Saylor Berman Date: Thu, 17 Aug 2023 12:49:23 -0600 Subject: [PATCH 2/4] Remove args --- Makefile | 3 +-- build/Dockerfile | 3 --- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/Makefile b/Makefile index bfce0802fc..76ba88b924 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,6 @@ OUT_DIR ?= $(shell pwd)/build/out## The folder where the binary will be stored ARCH ?= amd64## The architecture of the image and/or binary. For example: amd64 or arm64 override HELM_TEMPLATE_COMMON_ARGS += --set creator=template --set nameOverride=nginx-gateway## The common options for the Helm template command. override HELM_TEMPLATE_EXTRA_ARGS_FOR_ALL_MANIFESTS_FILE += --include-crds --set service.create=false## The options to be passed to the full Helm templating command only. -override DOCKER_BUILD_OPTIONS += --build-arg VERSION=$(VERSION) --build-arg GIT_COMMIT=$(GIT_COMMIT) --build-arg DATE=$(DATE)## The options for the docker build command. For example, --pull override NGINX_DOCKER_BUILD_OPTIONS += --build-arg NJS_DIR=$(NJS_DIR) --build-arg NGINX_CONF_DIR=$(NGINX_CONF_DIR) .DEFAULT_GOAL := help @@ -36,7 +35,7 @@ build-images: build-nkg-image build-nginx-image ## Build the NKG and nginx docke .PHONY: build-nkg-image build-nkg-image: check-for-docker build ## Build the NKG docker image - docker build --platform linux/$(ARCH) $(strip $(DOCKER_BUILD_OPTIONS)) --target $(strip $(TARGET)) -f build/Dockerfile -t $(strip $(PREFIX)):$(strip $(TAG)) . + docker build --platform linux/$(ARCH) --target $(strip $(TARGET)) -f build/Dockerfile -t $(strip $(PREFIX)):$(strip $(TAG)) . .PHONY: build-nginx-image build-nginx-image: check-for-docker ## Build the custom nginx image diff --git a/build/Dockerfile b/build/Dockerfile index 9c57f624ab..29f8852236 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -1,8 +1,5 @@ # syntax=docker/dockerfile:1.4 FROM golang:1.21 as builder -ARG VERSION -ARG GIT_COMMIT -ARG DATE WORKDIR /go/src/github.com/nginxinc/nginx-kubernetes-gateway From 359884587123e1887440ca3279cfb4436b44d0d2 Mon Sep 17 00:00:00 2001 From: Saylor Berman Date: Thu, 17 Aug 2023 14:45:22 -0600 Subject: [PATCH 3/4] Add mod download --- build/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/build/Dockerfile b/build/Dockerfile index 29f8852236..d4f2112abc 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -4,6 +4,7 @@ FROM golang:1.21 as builder WORKDIR /go/src/github.com/nginxinc/nginx-kubernetes-gateway COPY . /go/src/github.com/nginxinc/nginx-kubernetes-gateway +RUN go mod download RUN make build FROM alpine:3.18 as capabilizer From 57d3bdb111d1ceead06df68cbdd34faca2ec6e3e Mon Sep 17 00:00:00 2001 From: Saylor Berman Date: Thu, 17 Aug 2023 15:39:17 -0600 Subject: [PATCH 4/4] Fix copy mod files --- build/Dockerfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/build/Dockerfile b/build/Dockerfile index d4f2112abc..ad70680a7b 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -3,8 +3,10 @@ FROM golang:1.21 as builder WORKDIR /go/src/github.com/nginxinc/nginx-kubernetes-gateway -COPY . /go/src/github.com/nginxinc/nginx-kubernetes-gateway +COPY go.mod go.sum /go/src/github.com/nginxinc/nginx-kubernetes-gateway RUN go mod download + +COPY . /go/src/github.com/nginxinc/nginx-kubernetes-gateway RUN make build FROM alpine:3.18 as capabilizer