Skip to content

Fix builder docker image #988

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

Merged
merged 4 commits into from
Aug 17, 2023
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
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
13 changes: 4 additions & 9 deletions build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
# 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/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
Expand All @@ -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
Expand Down