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

Add support for SOURCE_DATE_EPOCH #734

Closed
2 tasks done
cognifloyd opened this issue Nov 6, 2023 · 1 comment · Fixed by #748
Closed
2 tasks done

Add support for SOURCE_DATE_EPOCH #734

cognifloyd opened this issue Nov 6, 2023 · 1 comment · Fixed by #748
Assignees
Labels
enhancement New feature or request

Comments

@cognifloyd
Copy link
Contributor

Is your feature request related to a problem? Please describe.

If a package is re-built with the same contents, but at two different times, the two packages will have binary differences because of the embedded timestamps.

I need to be able to build packages in a way that is completely reproducible, so that the same inputs gives me byte-for-byte the same package output.

For the files I'm packaging, I can set the mtime via the config file, or by changing the mtime on the file tree before running nfpm. However, there is no current mechanism for me to manage the timestamps generated within nFPM.

Describe the solution you'd like

Make the package build process reproducible by using the standard SOURCE_DATE_EPOCH env var (if available) instead of using time.Now().

More specifically, I think we can replace all of the time.Now() occurrences with one value calculated early on. Then, adjust that calculation to use SOURCE_DATE_EPOCH instead, if available.

This is the go example of calculating that:
https://reproducible-builds.org/docs/source-date-epoch/#go

import (
        "fmt"
        "os"
        "strconv"
        "time"
)

[...]

source_date_epoch := os.Getenv("SOURCE_DATE_EPOCH")
var build_date string
if source_date_epoch == "" {
        build_date = time.Now().UTC().Format(http.TimeFormat)
} else {
        sde, err := strconv.ParseInt(source_date_epoch, 10, 64)
        if err != nil {
                panic(fmt.Sprintf("Invalid SOURCE_DATE_EPOCH: %s", err))
        }
        build_date = time.Unix(sde, 0).UTC().Format(http.TimeFormat)
}

We can probably also use this build_date for a default mtime of package contents, but that is NOT what this issue is about. This issue is about controlling the current usages of time.Now(). These are the current instances that github search shows:
https://github.com/search?q=repo%3Agoreleaser%2Fnfpm+time.now&type=code

Describe alternatives you've considered

A new cli flag, or any other non-standard option means any automation has to learn a new trick instead of reusing the standard env var. More detailed description on why the env var is better: https://wiki.debian.org/ReproducibleBuilds/StandardEnvironmentVariables#A.22We.27ll_add_a_command-line_flag_instead.22

Search

  • I did search for other open and closed issues before opening this.

Code of Conduct

  • I agree to follow this project's Code of Conduct

Additional context

More background on why reproducible builds are important: https://reproducible-builds.org/

The spec for SOURCE_DATE_EPOCH: https://reproducible-builds.org/specs/source-date-epoch/

Apparently, dpkg automatically sets SOURCE_DATE_EPOCH when building packages based on the latest entry in the debian/changelog file. Many other tools have adopted that standard as well:
https://reproducible-builds.org/docs/source-date-epoch/#reading-the-variable

@cognifloyd cognifloyd added the enhancement New feature or request label Nov 6, 2023
caarlos0 added a commit that referenced this issue Dec 6, 2023
defaults to $SOURCE_DATE_EPOCH

closes #744
closes #734

Signed-off-by: Carlos Alexandro Becker <[email protected]>
@caarlos0
Copy link
Member

caarlos0 commented Dec 6, 2023

check #748

caarlos0 added a commit that referenced this issue Dec 7, 2023
* feat: allow to set a build date

defaults to $SOURCE_DATE_EPOCH

closes #744
closes #734

Signed-off-by: Carlos Alexandro Becker <[email protected]>

* fix: rename to mtime

* docs: fix systemd note

closes #739

* fix: improve arch packager

* fix: arch test

Signed-off-by: Carlos Alexandro Becker <[email protected]>

* fix: improve apk packager

* fix: improve deb special files

* fix: reuse keys func

* fix: deps

Signed-off-by: Carlos Alexandro Becker <[email protected]>

---------

Signed-off-by: Carlos Alexandro Becker <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants