Skip to content

Commit

Permalink
Force git date to the build files
Browse files Browse the repository at this point in the history
Signed-off-by: Ricardo Zanini <[email protected]>
  • Loading branch information
ricardozanini committed Jan 18, 2024
1 parent 362c03b commit fd5a76e
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 8 deletions.
7 changes: 6 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
# Build the manager binary
FROM docker.io/library/golang:1.21.6 as builder

ARG SOURCE_DATE_EPOCH

WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
Expand All @@ -40,7 +42,10 @@ COPY version/ version/
COPY log/ log/

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags=-buildid= -a -o manager main.go
# We force a timestamp to the output to guarantee a reproducible build, once we have BuildKit 0.12, this won't be needed anymore.
# The workaround to force the date format is because docker cli is expecting an int from this parameter (the timestamp).
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags=-buildid= -a -o manager main.go && \
touch -d $(date '+%FT%H:%M:%S' -d @${SOURCE_DATE_EPOCH}) manager

FROM registry.access.redhat.com/ubi9/ubi-micro:9.3-9
WORKDIR /usr/local/bin
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,11 @@ debug: build-4-debug ## Run a controller from your host from binary

.PHONY: docker-build
docker-build: generate ## Build docker image with the manager.
docker build --build-arg SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct) -t ${IMG} .
docker build --build-arg SOURCE_DATE_EPOCH="$(shell git log -1 --pretty=%ct)" -t ${IMG} .

.PHONY: podman-build
podman-build: generate ## Build container image with the manager.
podman build --build-arg SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct) -t ${IMG} .
podman build --build-arg SOURCE_DATE_EPOCH="$(shell git log -1 --pretty=%ct)" -t ${IMG} .

.PHONY: docker-push
docker-push: ## Push docker image with the manager.
Expand All @@ -186,7 +186,7 @@ docker-buildx: generate ## Build and push docker image for the manager for cross
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
- docker buildx create --name project-v3-builder
docker buildx use project-v3-builder
- docker buildx build --build-arg SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct) --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross
- docker buildx build --build-arg SOURCE_DATE_EPOCH=$(shell git log -1 --pretty=%ct) --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross
- docker buildx rm project-v3-builder
rm Dockerfile.cross

Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha08/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions api/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion container-builder/api/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion modules/org.kie.kogito.app.builder/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
set -e

cd /workspace
CGO_ENABLED=0 GO111MODULE=on go build -a -o manager main.go;
CGO_ENABLED=0 GO111MODULE=on go build -trimpath -ldflags=-buildid= -a -o manager main.go;
2 changes: 1 addition & 1 deletion modules/org.kie.kogito.osl.builder.prod/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
set -e

cd $REMOTE_SOURCE_DIR/app
source $CACHITO_ENV_FILE && go build -a -o manager main.go
source $CACHITO_ENV_FILE && go build -trimpath -ldflags=-buildid= -a -o manager main.go
mkdir /workspace && cp $REMOTE_SOURCE_DIR/app/manager /workspace

0 comments on commit fd5a76e

Please sign in to comment.