Skip to content
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

scripts/build/.variables: Support SOURCE_DATE_EPOCH #2855

Merged
merged 1 commit into from
Jul 23, 2021

Conversation

Foxboron
Copy link
Contributor

Repeated builds of docker is currently unreproducible as the embedded
time does not support SOURCE_DATE_EPOCH. This patch ensures we check for
the defined variable before utilizing current date.

This has been fixed previously with manpages as well

2d7091a

Signed-off-by: Morten Linderud morten@linderud.pw

- How to verify it

λ cli morten/reprobuilds» export SOURCE_DATE_EPOCH=1606660000
λ cli morten/reprobuilds» export DISABLE_WARN_OUTSIDE_CONTAINER=1
λ cli morten/reprobuilds» make
WARNING: binary creates a Linux executable. Use cross for macOS or Windows.
./scripts/build/binary
Building statically linked build/docker-linux-amd64
+ go build -o build/docker-linux-amd64 --ldflags '    -w 
  -X "github.com/docker/cli/cli/version.GitCommit=9d40c7464e" 
  -X "github.com/docker/cli/cli/version.BuildTime=2020-11-29T14:26:40Z" 
  -X "github.com/docker/cli/cli/version.Version=unknown-version"      ' github.com/docker/cli/cmd/docker
++ basename build/docker-linux-amd64
+ ln -sf docker-linux-amd64 build/docker

- Description for the changelog
Support reproducible builds by checking SOURCE_DATE_EPOCH before build.

- A picture of a cute animal (not mandatory but encouraged)

Repeated builds of docker is currently unreproducible as the embedded
time does not support SOURCE_DATE_EPOCH. This patch ensures we check for
the defined variable before utilizing current date.

This has been fixed previously with manpages as well

docker@2d7091a

Signed-off-by: Morten Linderud <morten@linderud.pw>
@elboulangero
Copy link
Contributor

Regarding the format of the date, the docker engine does that:

hack/make.sh
43:! BUILDTIME=$(date -u -d "@${SOURCE_DATE_EPOCH:-$(date +%s)}" --rfc-3339 ns 2> /dev/null | sed -e 's/ /T/')

While docker-ce-packaging does that:

common.mk
2:BUILDTIME=$(shell date -u -d "@$${SOURCE_DATE_EPOCH:-$$(date +%s)}" --rfc-3339 ns 2> /dev/null | sed -e 's/ /T/')

So I'd suggest going for --rfc-3339 ns 2> /dev/null | sed -e 's/ /T/' here as well, just for consistency.

@elboulangero
Copy link
Contributor

So I'd suggest going for --rfc-3339 ns 2> /dev/null | sed -e 's/ /T/' here as well, just for consistency

Unless you have backward compatibility concerns regarding the format of this date?

Copy link
Collaborator

@cpuguy83 cpuguy83 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Foxboron
Copy link
Contributor Author

Foxboron commented Mar 9, 2021

Whats the holdup on this change?

@cpuguy83 cpuguy83 requested a review from thaJeztah April 5, 2021 16:20
@Foxboron
Copy link
Contributor Author

@cpuguy83 ping :)? It's a long wait for a fairly simple change in my eyes.

@cpuguy83
Copy link
Collaborator

Maybe @tianon can give it a 2nd review.

Copy link
Contributor

@tianon tianon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@cpuguy83 cpuguy83 merged commit 43dc024 into docker:master Jul 23, 2021
@thaJeztah
Copy link
Member

Looks like this broke make binary when running on macOS, which uses a different flavour of date 😓

./scripts/build/binary
date: illegal option -- -
usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
make: *** [binary] Error 1

@elboulangero
Copy link
Contributor

Interesting. Looking at the man page, they have a COMPLETELY different date command in macOS. Seems like macOS needs to use date -r to display Epoch time

-r seconds Print the date and time represented by seconds, where seconds is the number of seconds since the Epoch (00:00:00 UTC, January 1, 1970; see time(3)), and can be specified in decimal, octal, or hex.

Ref: https://www.unix.com/man-page/osx/1/date/

@thaJeztah
Copy link
Member

Yes, I recall some hacks in other repositories to try to get it to work both on Linux and Mac. I need to dig up how it was handled there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants