-
Notifications
You must be signed in to change notification settings - Fork 805
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add docker reproducible builds #6799
Open
MoeMahhouk
wants to merge
3
commits into
sigp:unstable
Choose a base branch
from
MoeMahhouk:stable
base: unstable
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+82
−0
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Define the Rust image as an argument with a default to x86_64 Rust 1.82 image based on Debian Bullseye | ||
ARG RUST_IMAGE="rust:1.82-bullseye@sha256:ac7fe7b0c9429313c0fe87d3a8993998d1fe2be9e3e91b5e2ec05d3a09d87128" | ||
FROM ${RUST_IMAGE} AS builder | ||
|
||
# Install specific version of the build dependencies | ||
RUN apt-get update && apt-get install -y libclang-dev=1:11.0-51+nmu5 cmake=3.18.4-2+deb11u1 | ||
|
||
# Add target architecture argument with default value | ||
ARG RUST_TARGET="x86_64-unknown-linux-gnu" | ||
|
||
# Copy the project to the container | ||
COPY . /app | ||
WORKDIR /app | ||
|
||
# Get the latest commit timestamp and set SOURCE_DATE_EPOCH | ||
RUN SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct) && \ | ||
echo "SOURCE_DATE_EPOCH=$SOURCE_DATE_EPOCH" >> /etc/environment | ||
|
||
# Set environment variables for reproducibility | ||
ARG RUSTFLAGS="-C target-feature=+crt-static -C link-arg=-Wl,--build-id=none -Clink-arg=-static-libgcc -C metadata='' --remap-path-prefix $(pwd)=." | ||
ENV SOURCE_DATE_EPOCH=$SOURCE_DATE_EPOCH \ | ||
CARGO_INCREMENTAL=0 \ | ||
LC_ALL=C \ | ||
TZ=UTC \ | ||
RUSTFLAGS="${RUSTFLAGS}" | ||
|
||
# Set the default features if not provided | ||
ARG FEATURES="gnosis,slasher-lmdb,slasher-mdbx,slasher-redb,jemalloc" | ||
|
||
# Set the default profile if not provided | ||
ARG PROFILE="reproducible" | ||
|
||
# Build the project with the reproducible settings | ||
RUN . /etc/environment && \ | ||
cargo build --bin lighthouse \ | ||
--features "${FEATURES}" \ | ||
--profile "${PROFILE}" \ | ||
--locked \ | ||
--target "${RUST_TARGET}" | ||
|
||
RUN . /etc/environment && mv /app/target/${RUST_TARGET}/${PROFILE}/lighthouse /lighthouse | ||
|
||
# Create a minimal final image with just the binary | ||
FROM gcr.io/distroless/cc-debian12:nonroot-6755e21ccd99ddead6edc8106ba03888cbeed41a | ||
COPY --from=builder /lighthouse /lighthouse | ||
ENTRYPOINT [ "/lighthouse" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, upon finish building the docker image, there will be a warning shown at the end:
It's not really an issue but I find that if we define the
SOURCE_DATE_EPOCH
as an argument beforehand, then the warning no longer appears. I am not sure if this is a proper way to do, but I have tested this and the build is still reproducible with the added code.If we add this in the code, the
sha256sum
of the resulting binary would be:7ececbec414b0cc51e42a0f81e8441b9d5ae2f915c2e924424f67a9e932b5e95 lighthouse
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for highlighting this warning.
It appears that Docker is not keeping the state nor really getting the value from the command
git log -1 --pretty=%ct
So it was setting SOURCE_DATE_EPOCH to empty string silently which is wrong.
Upon uncovering such issue, I am preparing a fix where we pass it as build arg similar to the build target and currently validating that it works fine and the variable is captured correctly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have tested again and confirm that the warning is gone. The hashes of the binary files are the same upon rebuilding
d85f5ff5fecc515b55982181e8a642788c6dde2a20727a60b1f21b0112e8257b lighthouse