Skip to content

Commit 700c5d5

Browse files
authored
Add date to binary when building locally (#169)
1 parent 3f927ba commit 700c5d5

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ DOCKERFILE = Dockerfile
88
GIT_COMMIT = $(shell git rev-parse HEAD)
99

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

1213
export DOCKER_BUILDKIT = 1
1314

1415
.PHONY: nginx-prometheus-exporter
1516
nginx-prometheus-exporter:
16-
GO111MODULE=on CGO_ENABLED=0 go build -mod=vendor -ldflags "-X main.version=$(VERSION) -X main.commit=$(GIT_COMMIT)" -o nginx-prometheus-exporter
17+
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
1718

1819
.PHONY: lint
1920
lint:
@@ -28,7 +29,7 @@ test:
2829

2930
.PHONY: container
3031
container:
31-
docker build --build-arg VERSION=$(VERSION) --build-arg GIT_COMMIT=$(GIT_COMMIT) --target container -f $(DOCKERFILEPATH)/$(DOCKERFILE) -t $(PREFIX):$(TAG) .
32+
docker build --build-arg VERSION=$(VERSION) --build-arg GIT_COMMIT=$(GIT_COMMIT) --build-arg DATE=$(DATE) --target container -f $(DOCKERFILEPATH)/$(DOCKERFILE) -t $(PREFIX):$(TAG) .
3233

3334
.PHONY: push
3435
push: container

build/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
FROM golang:1.16 as base
22
ARG VERSION
33
ARG GIT_COMMIT
4+
ARG DATE
45
ARG TARGETARCH
56

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

1314
FROM base as builder
14-
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 .
15+
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 .
1516

1617

1718
FROM scratch as intermediate

0 commit comments

Comments
 (0)