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

build: use main package instead of main.go #6766

Merged
merged 1 commit into from
May 24, 2024

Conversation

knqyf263
Copy link
Collaborator

@knqyf263 knqyf263 commented May 24, 2024

Description

Our release binaries don't include the main module information now, and our gobinary analyzer doesn't work on them.

$ docker run --rm -it --entrypoint "sh" ghcr.io/aquasecurity/trivy:0.51.2 -c "apk add go && go version -m /usr/local/bin/trivy" | grep "/usr/local/bin/trivy" -A 5
/usr/local/bin/trivy: go1.22.3
        path    command-line-arguments
        dep     cloud.google.com/go     v0.112.1        h1:uJSeirPke5UNZHIb4SxfZklVSiWWVqW4oXlETwZziwM=
        dep     cloud.google.com/go/compute/metadata    v0.2.3  h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGBW5aJ7UnBMY=
        dep     cloud.google.com/go/iam v1.1.6  h1:bEa06k05IO4f4uJonbB5iAgKTPpABy1ayxaIZV/GHVc=
        dep     cloud.google.com/go/storage     v1.39.1 h1:MvraqHKhogCOTXTlct/9C3K3+Uy2jBmFYb3/Sp6dVtY=

A binary built by Mage includes it.

$ mage build && go version -m ./trivy | head -n 5
./trivy: go1.22.3
        path    github.com/aquasecurity/trivy/cmd/trivy
        mod     github.com/aquasecurity/trivy   (devel)
        dep     cloud.google.com/go     v0.112.1        h1:uJSeirPke5UNZHIb4SxfZklVSiWWVqW4oXlETwZziwM=
        dep     cloud.google.com/go/compute/metadata    v0.2.3  h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGBW5aJ7UnBMY=

This is because GoRelease uses main.go, cmd/trivy/main.go, while Mage uses the main package, ./cmd/trivy. This PR fixes it.

Before

$ goreleaser build -f goreleaser.yml --skip-validate --id build-macos --clean && go version -m dist/build-macos_darwin_amd64_v1/trivy | head -n 5
dist/build-macos_darwin_amd64_v1/trivy: go1.22.3
        path    command-line-arguments
        dep     cloud.google.com/go     v0.112.1        h1:uJSeirPke5UNZHIb4SxfZklVSiWWVqW4oXlETwZziwM=
        dep     cloud.google.com/go/compute/metadata    v0.2.3  h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGBW5aJ7UnBMY=
        dep     cloud.google.com/go/iam v1.1.6  h1:bEa06k05IO4f4uJonbB5iAgKTPpABy1ayxaIZV/GHVc=

After

$ goreleaser build -f goreleaser.yml --skip-validate --id build-macos --clean && go version -m dist/build-macos_darwin_amd64_v1/trivy | head -n 5
dist/build-macos_darwin_amd64_v1/trivy: go1.22.3
        path    github.com/aquasecurity/trivy/cmd/trivy
        mod     github.com/aquasecurity/trivy   (devel)
        dep     cloud.google.com/go     v0.112.1        h1:uJSeirPke5UNZHIb4SxfZklVSiWWVqW4oXlETwZziwM=
        dep     cloud.google.com/go/compute/metadata    v0.2.3  h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGBW5aJ7UnBMY=

Checklist

  • I've read the guidelines for contributing to this repository.
  • I've followed the conventions in the PR title.
  • I've added tests that prove my fix is effective or that my feature works.
  • I've updated the documentation with the relevant information (if needed).
  • I've added usage information (if the PR introduces new options)
  • I've included a "before" and "after" example to the description (if the PR is a user interface change).

Signed-off-by: knqyf263 <knqyf263@gmail.com>
@knqyf263 knqyf263 self-assigned this May 24, 2024
@knqyf263 knqyf263 marked this pull request as ready for review May 24, 2024 07:50
@knqyf263 knqyf263 added this pull request to the merge queue May 24, 2024
Merged via the queue into aquasecurity:main with commit e373833 May 24, 2024
13 checks passed
@knqyf263 knqyf263 deleted the fix/gobinary_mod branch May 24, 2024 08:19
knqyf263 added a commit that referenced this pull request May 24, 2024
Signed-off-by: knqyf263 <knqyf263@gmail.com>
@knqyf263
Copy link
Collaborator Author

I confirmed it's fixed now.

$ docker run --rm -it --entrypoint "sh" ghcr.io/aquasecurity/trivy:0.51.4 -c "apk add go && go version -m /usr/local/bin/trivy" | grep "/usr/local/bin/trivy" -A 5

/usr/local/bin/trivy: go1.22.3
        path    github.com/aquasecurity/trivy/cmd/trivy
        mod     github.com/aquasecurity/trivy   (devel)
        dep     cloud.google.com/go     v0.112.1        h1:uJSeirPke5UNZHIb4SxfZklVSiWWVqW4oXlETwZziwM=
        dep     cloud.google.com/go/compute/metadata    v0.2.3  h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGBW5aJ7UnBMY=
        dep     cloud.google.com/go/iam v1.1.6  h1:bEa06k05IO4f4uJonbB5iAgKTPpABy1ayxaIZV/GHVc=

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

Successfully merging this pull request may close these issues.

None yet

2 participants