From d0ea451bccb473318e13cf23744c402e5466e374 Mon Sep 17 00:00:00 2001 From: Garrison Davis Date: Wed, 23 Nov 2022 16:30:18 -0700 Subject: [PATCH] Use SOURCE_DATE_EPOCH to make reproducible builds Reproducible builds are something we should be doing, and we are there as far as making them in CI is concerned with this change. The changes to the Dockerfile/Makefile do nothing if the SOURCE_DATE_EPOCH environment variable is not set before `make build` happens, or if the build arg is not passed in to docker. (cherry picked from commit fd93fc99c90b3eeab00bf5118730d212a1c7d98f) --- Dockerfile | 3 +++ Makefile | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 0ca6ef677..cf84b9403 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,6 +20,8 @@ RUN yarn build FROM golang:${GO_VERSION} as pilosa-builder ARG MAKE_FLAGS +ARG SOURCE_DATE_EPOCH + WORKDIR /pilosa RUN go install github.com/rakyll/statik@v0.1.7 @@ -28,6 +30,7 @@ COPY . ./ COPY --from=lattice-builder /lattice/build /lattice RUN /go/bin/statik -src=/lattice -dest=/pilosa +ENV SOURCE_DATE_EPOCH=$SOURCE_DATE_EPOCH RUN make build FLAGS="-o build/featurebase" ${MAKE_FLAGS} ##################### diff --git a/Makefile b/Makefile index a97dad399..f9b1d1804 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,13 @@ GO=go GOOS=$(shell $(GO) env GOOS) GOARCH=$(shell $(GO) env GOARCH) VERSION_ID=$(if $(TRIAL_DEADLINE),trial-$(TRIAL_DEADLINE)-,)$(VERSION)-$(GOOS)-$(GOARCH) -BUILD_TIME := $(shell date -u +%FT%T%z) +DATE_FMT="+%FT%T%z" +ifdef SOURCE_DATE_EPOCH + BUILD_TIME ?= $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || date -u -r "$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || date -u "$(DATE_FMT)") +else + BUILD_TIME ?= $(shell date -u "$(DATE_FMT)") +endif +SHARD_WIDTH = 20 COMMIT := $(shell git describe --exact-match >/dev/null 2>&1 || git rev-parse --short HEAD) LDFLAGS="-X github.com/featurebasedb/featurebase/v3.Version=$(VERSION) -X github.com/featurebasedb/featurebase/v3.BuildTime=$(BUILD_TIME) -X github.com/featurebasedb/featurebase/v3.Variant=$(VARIANT) -X github.com/featurebasedb/featurebase/v3.Commit=$(COMMIT) -X github.com/featurebasedb/featurebase/v3.TrialDeadline=$(TRIAL_DEADLINE)" GO_VERSION=1.19 @@ -177,6 +183,7 @@ docker-build: vendor docker build \ --build-arg GO_VERSION=$(GO_VERSION) \ --build-arg MAKE_FLAGS="TRIAL_DEADLINE=$(TRIAL_DEADLINE) GOOS=$(GOOS) GOARCH=$(GOARCH)" \ + --build-arg SOURCE_DATE_EPOCH=$(SOURCE_DATE_EPOCH) \ --target pilosa-builder \ --tag featurebase:build . docker create --name featurebase-build featurebase:build