-
Notifications
You must be signed in to change notification settings - Fork 803
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
unable to build static binary #691
Comments
For what it's worth, docker works fine with same registry, [harshal@oc1472752102 skopeo]$ docker pull localhost:5000/nginx:latest
Trying to pull repository localhost:5000/nginx ...
latest: Pulling from localhost:5000/nginx
Digest: sha256:00be67d6ba53d5318cd91c57771530f5251cfbe028b7be2c4b70526f988cfc9f
Status: Image is up to date for localhost:5000/nginx:latest
[harshal@oc1472752102 skopeo]$ |
@harche, thanks for opening the issue. Can you share how the binary was built and with which version of go? |
I cloned upstream master of the skopeo and built using, [harshal@oc1472752102 skopeo]$ go version
go version go1.12.5 linux/amd64
[harshal@oc1472752102 skopeo]$ |
That's odd since the stack trace claims: |
Oh, it's built inside a container right? [harshal@oc1472752102 skopeo]$ make binary-static DISABLE_CGO=1
docker build -f Dockerfile.build -t skopeobuildimage .
Sending build context to Docker daemon 101.2 MB
Step 1/4 : FROM ubuntu:18.10
---> 6f73120de66c
Step 2/4 : RUN apt-get update && apt-get install -y golang libbtrfs-dev git-core libdevmapper-dev libgpgme11-dev go-md2man libglib2.0-dev libostree-dev
---> Using cache
---> bb2870e349d5
Step 3/4 : ENV GOPATH /
---> Using cache
---> 39c804ef056a
Step 4/4 : WORKDIR /src/github.com/containers/skopeo
---> Using cache
---> 1b5ca13b10a6
Successfully built 1b5ca13b10a6
docker run --rm --security-opt label=disable -v $(pwd):/src/github.com/containers/skopeo \
skopeobuildimage make binary-local-static BUILDTAGS='containers_image_ostree_stub exclude_graphdriver_devicemapper exclude_graphdriver_btrfs containers_image_openpgp'
go build -ldflags "-extldflags \"-static\" -X main.gitCommit=5f451126781913c7c72695ad18fe029d2f0e8de8" -gcflags "" -tags "containers_image_ostree_stub exclude_graphdriver_devicemapper exclude_graphdriver_btrfs containers_image_openpgp" -o skopeo ./cmd/skopeo
[harshal@oc1472752102 skopeo]$ |
Yes, it's built in the container. I assume CGO must be disabled. Trying to reproduce now. |
If I disable CGO I am not even able to build, [harshal@oc1472752102 skopeo]$ make binary-static DISABLE_CGO=0
docker build -f Dockerfile.build -t skopeobuildimage .
Sending build context to Docker daemon 101.2 MB
Step 1/4 : FROM ubuntu:18.10
---> 6f73120de66c
Step 2/4 : RUN apt-get update && apt-get install -y golang libbtrfs-dev git-core libdevmapper-dev libgpgme11-dev go-md2man libglib2.0-dev libostree-dev
---> Using cache
---> bb2870e349d5
Step 3/4 : ENV GOPATH /
---> Using cache
---> 39c804ef056a
Step 4/4 : WORKDIR /src/github.com/containers/skopeo
---> Using cache
---> 1b5ca13b10a6
Successfully built 1b5ca13b10a6
docker run --rm --security-opt label=disable -v $(pwd):/src/github.com/containers/skopeo \
skopeobuildimage make binary-local-static BUILDTAGS=' containers_image_ostree_stub '
go build -ldflags "-extldflags \"-static\" -X main.gitCommit=5f451126781913c7c72695ad18fe029d2f0e8de8" -gcflags "" -tags "containers_image_ostree_stub " -o skopeo ./cmd/skopeo
# github.com/containers/skopeo/cmd/skopeo
/usr/lib/go-1.10/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/usr/bin/ld: cannot find -ldevmapper
/usr/bin/ld: /tmp/go-link-031325273/000023.o: in function `mygetgrouplist':
/build/golang-1.10-0Gb4kq/golang-1.10-1.10.4/src/os/user/getgrouplist_unix.go:15: warning: Using 'getgrouplist' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /tmp/go-link-031325273/000022.o: in function `mygetgrgid_r':
/build/golang-1.10-0Gb4kq/golang-1.10-1.10.4/src/os/user/cgo_lookup_unix.go:38: warning: Using 'getgrgid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /tmp/go-link-031325273/000022.o: in function `mygetgrnam_r':
/build/golang-1.10-0Gb4kq/golang-1.10-1.10.4/src/os/user/cgo_lookup_unix.go:43: warning: Using 'getgrnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /tmp/go-link-031325273/000022.o: in function `mygetpwnam_r':
/build/golang-1.10-0Gb4kq/golang-1.10-1.10.4/src/os/user/cgo_lookup_unix.go:33: warning: Using 'getpwnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /tmp/go-link-031325273/000022.o: in function `mygetpwuid_r':
/build/golang-1.10-0Gb4kq/golang-1.10-1.10.4/src/os/user/cgo_lookup_unix.go:28: warning: Using 'getpwuid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /tmp/go-link-031325273/000029.o: in function `_cgo_f7895c2c5a3a_C2func_getaddrinfo':
/tmp/go-build/cgo-gcc-prolog:46: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
collect2: error: ld returned 1 exit status
make: *** [Makefile:101: binary-local-static] Error 2
make: *** [binary-static] Error 2
[harshal@oc1472752102 skopeo]$ |
so |
@harche, it took a while until I refreshed my brain. This is actually a known issue and addressed in PR #670. However, there are a few shortcomings when using static binaries as @mtrmac mentions here #670 (comment). Let's keep this issue open until there's a consensus in #670 how we proceed. |
@vrothberg sure, thanks. |
That just seems like a bug in the build container, FWIW. (Still, static builds are problematic, and at least I don’t think we should make them default. Have the users opt-in after reading documentation with warning.) |
While pulling from dockerhub works fine, not able to pull the image from the locally hosted registry.
The text was updated successfully, but these errors were encountered: