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

chore(reproducibility): add buildid= and trimpath #642

Closed
wants to merge 1 commit into from

Conversation

developer-guy
Copy link
Contributor

Signed-off-by: Batuhan Apaydın [email protected]

Copy link
Contributor

@wagoodman wagoodman left a comment

Choose a reason for hiding this comment

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

Nice addition 🙌 . Looks like the snapshot is failing, will kick it off again to see if it was intermittent or a related problem to the change.

@developer-guy developer-guy force-pushed the feature/repro branch 5 times, most recently from 8ed72ed to 325c1bf Compare February 24, 2022 14:42
@wagoodman
Copy link
Contributor

@developer-guy out of curiosity, why the change to explicitly specify GOPATH in the workflow files?

@developer-guy
Copy link
Contributor Author

I saw it from the documentation:
https://goreleaser.com/customization/build/

@wagoodman
Copy link
Contributor

I see the reason for trimpath, but what I'm referring to is:

Where there was a change to explicitly set GOPATH: /home/runner/go. I'm confused as to why this is needed --can you elaborate?

@developer-guy
Copy link
Contributor Author

I see the reason for trimpath, but what I'm referring to is:

Where there was a change to explicitly set GOPATH: /home/runner/go. I'm confused as to why this is needed --can you elaborate?

to be able to use it in .goreleaser.yml via .Env, I think

@developer-guy
Copy link
Contributor Author

I see the reason for trimpath, but what I'm referring to is:

Where there was a change to explicitly set GOPATH: /home/runner/go. I'm confused as to why this is needed --can you elaborate?

I've replaced with ${{ env.GOPATH }} this one.

@developer-guy
Copy link
Contributor Author

@wagoodman
Copy link
Contributor

I've replaced with ${{ env.GOPATH }} this one.

Right, but doesn't this do nothing?

        env:
           GOPATH: ${{ env.GOPATH }}

... since this is setting an environment variable based off of the current environment variable value of the same name? Are these 'GOPATH' changes necessary?

@developer-guy
Copy link
Contributor Author

I reverted GOPATH changes, let's what will happen 😮

@developer-guy
Copy link
Contributor Author

   ⨯ release failed after 96.69s error=failed to build for linux_amd64: exit status 2: # github.com/anchore/grype
open main: no such file or directory

@wagoodman :(

Copy link
Contributor

@wagoodman wagoodman left a comment

Choose a reason for hiding this comment

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

We shouldn't need to set the GOPATH explicitly for this change. Additionally I think we should be using the build trimpath flag and not the gcflag trimpath=<some-path>. I think this would be the equivalent change:

  - id: linux-build
    binary: grype
    goos:
      - linux
    goarch:
      - amd64
      - arm64
    # set the modified timestamp on the output binary to the git timestamp to ensure a reproducible build
    mod_timestamp: &build-timestamp '{{ .CommitTimestamp }}'
    env: &build-env
      - CGO_ENABLED=0
    flags: &build-flags
      - -trimpath
    ldflags: &build-ldflags |
      -buildid=
      -w
      -s
      -extldflags '-static'
      -X github.com/anchore/grype/internal/version.version={{.Version}}
      -X github.com/anchore/grype/internal/version.syftVersion={{.Env.SYFT_VERSION}}
      -X github.com/anchore/grype/internal/version.gitCommit={{.Commit}}
      -X github.com/anchore/grype/internal/version.buildDate={{.CommitDate}}
      -X github.com/anchore/grype/internal/version.gitDescription={{.Summary}}

I made one extra update:

-X github.com/anchore/grype/internal/version.buildDate={{.CommitDate}}

... so the commit date is referenced.

Note: this would not get us 100% to reproducible builds, but I'm not certain what's left to close the gap.

@developer-guy
Copy link
Contributor Author

I think we should get build date via https://reproducible-builds.org/docs/source-date-epoch/

@developer-guy developer-guy force-pushed the feature/repro branch 2 times, most recently from 504055e to 2fcf3bf Compare February 25, 2022 06:20
@developer-guy
Copy link
Contributor Author

seems everything is fine @wagoodman, thanks a ton 🙋🏻‍♂️

@wagoodman
Copy link
Contributor

Clarifying question: why not use the built in goreleaser {{.CommitDate}} variable? Is there a functional difference between that and the makefile updates you made?

I can't seem to parse the specific behavior of the set of date commands, and if the purpose of SOURCE_DATE_EPOCH is to provide a timestamp that is relative to the source change, then the goreleaser CommitDate seems like a much easier option.

@wagoodman
Copy link
Contributor

@developer-guy friendly nudge on #642 (comment) (also 1:1 with anchore/syft#847)

@spiffcs spiffcs self-assigned this Aug 18, 2022
@wagoodman
Copy link
Contributor

I'm going to close this as stale, but please reach out on a new issue if you wanted to chat further about this.

@wagoodman wagoodman closed this Jan 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants