Skip to content

Commit 9d1c660

Browse files
committed
fix the SOURCE_DATE_EPOCH issue within dockerfile
1 parent af99c34 commit 9d1c660

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

Dockerfile.reproducible

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@ ARG RUST_TARGET="x86_64-unknown-linux-gnu"
1212
COPY . /app
1313
WORKDIR /app
1414

15-
# Get the latest commit timestamp and set SOURCE_DATE_EPOCH
16-
RUN SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct) && \
17-
echo "SOURCE_DATE_EPOCH=$SOURCE_DATE_EPOCH" >> /etc/environment
15+
# Get the latest commit timestamp and set SOURCE_DATE_EPOCH (default it to 0 if not passed)
16+
ARG SOURCE_DATE=0
1817

1918
# Set environment variables for reproducibility
20-
ARG RUSTFLAGS="-C target-feature=+crt-static -C link-arg=-Wl,--build-id=none -Clink-arg=-static-libgcc -C metadata='' --remap-path-prefix $(pwd)=."
21-
ENV SOURCE_DATE_EPOCH=$SOURCE_DATE_EPOCH \
19+
ARG RUSTFLAGS="-C link-arg=-Wl,--build-id=none -C metadata='' --remap-path-prefix $(pwd)=."
20+
ENV SOURCE_DATE_EPOCH=$SOURCE_DATE \
2221
CARGO_INCREMENTAL=0 \
2322
LC_ALL=C \
2423
TZ=UTC \
@@ -31,14 +30,13 @@ ARG FEATURES="gnosis,slasher-lmdb,slasher-mdbx,slasher-redb,jemalloc"
3130
ARG PROFILE="reproducible"
3231

3332
# Build the project with the reproducible settings
34-
RUN . /etc/environment && \
35-
cargo build --bin lighthouse \
33+
RUN cargo build --bin lighthouse \
3634
--features "${FEATURES}" \
3735
--profile "${PROFILE}" \
3836
--locked \
3937
--target "${RUST_TARGET}"
4038

41-
RUN . /etc/environment && mv /app/target/${RUST_TARGET}/${PROFILE}/lighthouse /lighthouse
39+
RUN mv /app/target/${RUST_TARGET}/${PROFILE}/lighthouse /lighthouse
4240

4341
# Create a minimal final image with just the binary
4442
FROM gcr.io/distroless/cc-debian12:nonroot-6755e21ccd99ddead6edc8106ba03888cbeed41a

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ build-lcli-x86_64:
7070
build-lcli-aarch64:
7171
cross build --bin lcli --target aarch64-unknown-linux-gnu --features "portable" --profile "$(CROSS_PROFILE)" --locked
7272

73+
# extracts the current source date for reproducible builds
74+
SOURCE_DATE := $(shell git log -1 --pretty=%ct)
75+
7376
# Default image for x86_64
7477
RUST_IMAGE_AMD64 ?= rust:1.82-bullseye@sha256:ac7fe7b0c9429313c0fe87d3a8993998d1fe2be9e3e91b5e2ec05d3a09d87128
7578

@@ -78,6 +81,7 @@ build-reproducible-x86_64:
7881
DOCKER_BUILDKIT=1 docker build \
7982
--build-arg RUST_TARGET="x86_64-unknown-linux-gnu" \
8083
--build-arg RUST_IMAGE=$(RUST_IMAGE_AMD64) \
84+
--build-arg SOURCE_DATE=$(SOURCE_DATE) \
8185
-f Dockerfile.reproducible \
8286
-t lighthouse:reproducible-amd64 .
8387

@@ -90,6 +94,7 @@ build-reproducible-aarch64:
9094
--platform linux/arm64 \
9195
--build-arg RUST_TARGET="aarch64-unknown-linux-gnu" \
9296
--build-arg RUST_IMAGE=$(RUST_IMAGE_ARM64) \
97+
--build-arg SOURCE_DATE=$(SOURCE_DATE) \
9398
-f Dockerfile.reproducible \
9499
-t lighthouse:reproducible-arm64 .
95100

0 commit comments

Comments
 (0)