hub: Problem with the linux binaries on Alpine
Hi there. I wasn’t able to download and install the linux binaries properly on Alpine linux.
I’ve created a Dockerfile to recreate the problem.
FROM alpine:3.8
RUN apk add --no-cache bash
RUN wget --quiet https://github.com/github/hub/releases/download/v2.5.0/hub-linux-amd64-2.5.0.tgz -O hub.tgz ; \
mkdir hub ; \
tar -xvzf hub.tgz --directory hub --strip-components=1 ; \
./hub*/install
RUN hub
If you build this then you will get:
docker build -t temp .
Sending build context to Docker daemon 2.048kB
Step 1/4 : FROM alpine:3.8
---> 11cd0b38bc3c
Step 2/4 : RUN apk add --no-cache bash
---> Using cache
---> b3d1d700abe2
Step 3/4 : RUN wget --quiet https://github.com/github/hub/releases/download/v2.5.0/hub-linux-amd64-2.5.0.tgz -O hub.tgz ; mkdir hub ; tar -xvzf hub.tgz --directory hub --strip-components=1 ; ./hub*/install
---> Running in a62f8f93e4e4
hub-linux-amd64-2.5.0/
...
hub-linux-amd64-2.5.0/install
Removing intermediate container a62f8f93e4e4
---> d842b5922714
Step 4/4 : RUN hub
---> Running in 83fcf019ef52
/bin/sh: hub: not found
The command '/bin/sh -c hub' returned a non-zero code: 127
As a workaround, I found that if I used the hub package in the alpine testing branch, that works. I.e.
RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories
RUN apk add --no-cache \
git=2.18.0-r0 \
bash=4.4.19-r1 \
hub=2.4.0-r0
Thanks!
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 1
- Comments: 15 (6 by maintainers)
Commits related to this issue
- Update Dockerfile Referrence: https://github.com/github/hub/issues/1818 — committed to VirtualCommunity/git by chetabahana 5 years ago
- Completely static binary https://github.com/github/hub/issues/1818 — committed to Q42Philips/gitops-sync by hermanbanken 3 years ago
install until then with
Something like this would statically compile:
CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-extldflags "-static"' .This is passing
-staticto the external linker and disabling cgo (i.e. disable the ability to call c code. Not sure if it’s required or not but all the examples I’ve seen disable it).@mislav it’s a glibc vs musl issue
Most go binary projects I’ve seen (gosu for example) compile binary in such a way that they are statically linked. For some reason, the hub executable is not statically linked, and thus needs glibc.
lddshows this.docker run -it --rm alpine:3.8Shows
But that one gosu exectuable works on both glibc and musl linux alike.
For some reason, the hub downloaded from the release page shows this
Unfortunately, I don’t know about golang to explain how you fix it. But if you start statically linking the hub executable, then the release downloads will work for both.
Note, there is a package for Alpine, but in ‘testing’ repository, which you should enable explicitly: https://pkgs.alpinelinux.org/packages?name=hub
Adding environment variable
CGO_ENABLED=0beforego buildshould solve this issue.Thank you @philwinder @andyneff. I’ve also been reading https://medium.com/@diogok/on-golang-static-binaries-cross-compiling-and-plugins-1aed33499671 which suggests:
Now the question is, which precompiled builds should I apply these flags to? Or, should I make a separate precompiled build with these settings? When to instruct people in the install docs to try downloading that build?
Thanks for the tips.
Since existing linux build seem to work (at least, there were no complains until now) for most people except those who use Alpine, I don’t want to risk kicking the hornet’s nest by changing the build configuration for those. Instead, I agree that we could offer alternate builds. But since I’m short on time and this issue personally doesn’t affect me, I would like yours or others’ help on figuring out what the exact build flags should be, and how to call this build. If we’re doing this primarily to benefit Alpine users, should we name the build “alpine”? Or, if this is just for alpine, maybe we can go the dynamic-musl route?
Reopening
Hi I can’t help you with linux commands and making docker containers. You’ll have to figure it out on your own.
For what it’s worth, this script installs hub into
/usr/local/bin/hub:You can change the installation location with
PREFIX=/usrwhen running theinstallscript. The$PREFIX/bindirectory should be in your PATH before you can runhub.