Skip to content

Support local compilation #4

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 1 commit into from
Nov 9, 2021
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: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@

# GoLand IDE
.idea

# Binary
gateway
14 changes: 12 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 8 additions & 3 deletions build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
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/