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

Use -trimpath and ldflags -s -w build flags #1880

Merged
merged 1 commit into from
Sep 30, 2022

Conversation

pratikbin
Copy link
Contributor

@pratikbin pratikbin commented Sep 29, 2022

Use build flags -trimpath and ldflags -s -w to generate slim binaries, More here and here

Before

image

After (~48% downsize)

image

@@ -30,14 +30,14 @@ ARG TARGETPLATFORM TARGETOS TARGETARCH TARGETVARIANT VERSION=dev
# to avoid https://github.com/moby/buildkit/issues/2334
# We can use docker layer cache so the build is fast enogh anyway
# We also use per-platform GOCACHE for the same reason.
env GOCACHE /build/${TARGETPLATFORM}/root/.cache/go-build
Copy link
Collaborator

Choose a reason for hiding this comment

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

OMG! How did it ever work with lower-case?!

Copy link
Contributor Author

@pratikbin pratikbin Oct 4, 2022

Choose a reason for hiding this comment

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

Docker tries to interpret the first word as instruction unless it's bounded in between here doc. So it will work but not the best practice

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good to know! Thanks a lot for the explanation ☺️

Copy link
Collaborator

@mumoshu mumoshu left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks a lot for your effort @pratikbin!

@mumoshu mumoshu merged commit f2f2282 into actions:master Sep 30, 2022
@pratikbin
Copy link
Contributor Author

Yay

image

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.

2 participants