CARVIEW |
Navigation Menu
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Make building static binaries simpler #7022
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
Conversation
This commit adds STATIC makefile variable to adjust LDFLAGS and build tags accordingly. Fixes containerd#5824. Signed-off-by: Kazuyoshi Kato <katokazu@amazon.com>
Skipping CI for Draft Pull Request. |
make EXTRA_FLAGS="-buildmode pie" \ | ||
EXTRA_LDFLAGS='-linkmode external -extldflags "-fno-PIC -static"' \ | ||
BUILDTAGS="netgo osusergo static_build" | ||
make STATIC=1 | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe better to clarify that this is valid only for 1.7 and later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the patch apply "cleanly" on the release/1.6 branch? (if so, that would make things a bit easier and I could already adjust my build-scripts)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I can backport the patch to 1.6.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That'd be nice yes; IIUC (looking at the change), both the "old" and "new" way would be supported, so it should not be a breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The backport PR is #7045.
Just gave this a try with my original reproducer in #5824; docker build -t foo -<<'EOF'
ARG GO_VERSION=1.18.3
FROM golang:${GO_VERSION}-bullseye AS build
ENV GO111MODULE=off
RUN apt-get update && apt-get install -y --no-install-recommends libbtrfs-dev
RUN git clone https://github.com/kzys/containerd.git "/go/src/github.com/containerd/containerd"
WORKDIR /go/src/github.com/containerd/containerd
RUN git checkout -q "static"
RUN make STATIC=1 bin/ctr
RUN bin/ctr --version
RUN ldd bin/ctr || echo "statically linked?"
FROM alpine:3.16
COPY --from=build /go/src/github.com/containerd/containerd/bin/. /usr/local/bin/
RUN ldd /usr/local/bin/ctr || echo "statically linked?"
RUN /usr/local/bin/ctr --version
EOF docker run --rm foo ctr --version
ctr github.com/containerd/containerd v1.3.0-5457-g00eb74a4c
docker run --rm foo sh -c 'ldd $(command -v ctr)'
/lib/ld-musl-x86_64.so.1: /usr/local/bin/ctr: Not a valid dynamic program |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
This commit adds STATIC makefile variable to adjust LDFLAGS and build
tags accordingly.
Fixes #5824.
Signed-off-by: Kazuyoshi Kato katokazu@amazon.com