Skip to content

Commit

Permalink
Add date to binary when building locally (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacome authored Mar 22, 2021
1 parent 3f927ba commit 700c5d5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ DOCKERFILE = Dockerfile
GIT_COMMIT = $(shell git rev-parse HEAD)

GOLANGCI_CONTAINER=golangci/golangci-lint:v1.29-alpine
DATE = $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")

export DOCKER_BUILDKIT = 1

.PHONY: nginx-prometheus-exporter
nginx-prometheus-exporter:
GO111MODULE=on CGO_ENABLED=0 go build -mod=vendor -ldflags "-X main.version=$(VERSION) -X main.commit=$(GIT_COMMIT)" -o nginx-prometheus-exporter
GO111MODULE=on CGO_ENABLED=0 go build -mod=vendor -ldflags "-X main.version=$(VERSION) -X main.commit=$(GIT_COMMIT) -X main.date=$(DATE)" -o nginx-prometheus-exporter

.PHONY: lint
lint:
Expand All @@ -28,7 +29,7 @@ test:

.PHONY: container
container:
docker build --build-arg VERSION=$(VERSION) --build-arg GIT_COMMIT=$(GIT_COMMIT) --target container -f $(DOCKERFILEPATH)/$(DOCKERFILE) -t $(PREFIX):$(TAG) .
docker build --build-arg VERSION=$(VERSION) --build-arg GIT_COMMIT=$(GIT_COMMIT) --build-arg DATE=$(DATE) --target container -f $(DOCKERFILEPATH)/$(DOCKERFILE) -t $(PREFIX):$(TAG) .

.PHONY: push
push: container
Expand Down
3 changes: 2 additions & 1 deletion build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM golang:1.16 as base
ARG VERSION
ARG GIT_COMMIT
ARG DATE
ARG TARGETARCH

WORKDIR /go/src/github.com/nginxinc/nginx-prometheus-exporter
Expand All @@ -11,7 +12,7 @@ COPY collector ./collector
COPY client ./client

FROM base as builder
RUN GO111MODULE=on CGO_ENABLED=0 GOOS=linux GOARCH=$TARGETARCH go build -mod=vendor -a -ldflags "-s -w -X main.version=${VERSION} -X main.commit=${GIT_COMMIT}" -o nginx-prometheus-exporter .
RUN GO111MODULE=on CGO_ENABLED=0 GOOS=linux GOARCH=$TARGETARCH go build -mod=vendor -a -ldflags "-s -w -X main.version=${VERSION} -X main.commit=${GIT_COMMIT} -X main.date=${DATE}" -o nginx-prometheus-exporter .


FROM scratch as intermediate
Expand Down

0 comments on commit 700c5d5

Please sign in to comment.