diff --git a/.gitignore b/.gitignore index 9f7b550558..f3ddfc4d4c 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,6 @@ # GoLand IDE .idea + +# Binary +gateway diff --git a/Makefile b/Makefile index 291e02a5e5..fa93ae3835 100644 --- a/Makefile +++ b/Makefile @@ -5,11 +5,21 @@ PREFIX = nginx-gateway GIT_COMMIT = $(shell git rev-parse HEAD) DATE = $(shell date -u +"%Y-%m-%dT%H:%M:%SZ") +TARGET ?= local + KIND_KUBE_CONFIG_FOLDER = $${HOME}/.kube/kind +export DOCKER_BUILDKIT = 1 + .PHONY: container -container: - docker build --build-arg VERSION=$(VERSION) --build-arg GIT_COMMIT=$(GIT_COMMIT) --build-arg DATE=$(DATE) --target container -f build/Dockerfile -t $(PREFIX):$(TAG) . +container: build + docker build --build-arg VERSION=$(VERSION) --build-arg GIT_COMMIT=$(GIT_COMMIT) --build-arg DATE=$(DATE) --target $(TARGET) -f build/Dockerfile -t $(PREFIX):$(TAG) . + +.PHONY: build +build: +ifeq (${TARGET},local) + 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 github.com/nginxinc/nginx-gateway-kubernetes/cmd/gateway +endif .PHONY: deps deps: diff --git a/build/Dockerfile b/build/Dockerfile index be6074e70f..4010a7d686 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -11,7 +11,12 @@ RUN go mod download COPY cmd /go/src/github.com/nginxinc/nginx-gateway-kubernetes/cmd 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 . -FROM scratch as container -COPY --from=builder /go/src/github.com/nginxinc/nginx-gateway-kubernetes/cmd/gateway/gateway /usr/bin/ +FROM scratch as common USER 1001:1001 -ENTRYPOINT [ "/usr/bin/gateway" ] \ No newline at end of file +ENTRYPOINT [ "/usr/bin/gateway" ] + +FROM common as container +COPY --from=builder /go/src/github.com/nginxinc/nginx-gateway-kubernetes/cmd/gateway/gateway /usr/bin/ + +FROM common as local +COPY ./gateway /usr/bin/