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

Forego binary support for alpinelinux #65

Closed
oba11 opened this issue Sep 1, 2015 · 9 comments
Closed

Forego binary support for alpinelinux #65

oba11 opened this issue Sep 1, 2015 · 9 comments

Comments

@oba11
Copy link

oba11 commented Sep 1, 2015

Linux precompiled binary doesnt work with alpinelinux.
Could come useful for people who are very keen on docker image size.
forego is much lightweight compared to supervisor which also requires other dependencies.
Its been compiled for personal use by using the below command

CGO_ENABLED=0 go build -installsuffix cgo github.com/ddollar/forego

Here is the link to the working alpinelinux binary.
Thanks.

@lorenz
Copy link

lorenz commented Sep 16, 2015

+1, would appreciate a musl build with static linking as glibc has its quirks with static linking and makes the binary really large

Nonstatic build for Alpine:

docker run -ti --name build-forego alpine:edge sh
# Enter Docker Shell
apk update && apk upgrade && apk add go musl-dev git
mkdir /go && export GOPATH=/go
go get github.com/ddollar/forego
# Leave Docker shell
docker cp build-forego:/go/bin/forego dist/forego

I'm working on the fully static one.

@lorenz
Copy link

lorenz commented Oct 8, 2015

Fully static stripped build (5.9MiB) now working :)

#!/bin/bash
docker run -i --rm golang:1.5.1 > forego <<END
apt-get update 1> /dev/null && apt-get install -yy musl-dev musl-tools 1> /dev/null
go get github.com/ddollar/forego 1> /dev/null
cd /go/src/github.com/ddollar/forego 1> /dev/null
CC=musl-gcc go build  --ldflags '-linkmode external -extldflags "-static -s"' 1> /dev/null
cat forego
END

This pulls golang:1.5.1, installs the appropriate musl tools, pulls forego and builds a stripped static binary and outputs it to the working directory. It could obviously be altered to take the input from a volume instead of downloading it.
The resulting binary works on every Linux with the same CPU architecture.

@lorenz
Copy link

lorenz commented Oct 23, 2015

@ddollar Can we get this new build process integrated for the new binary releases? There are no downsides to these binaries, they are even smaller than the ones you are currently distributing and they work absolutely everywhere where you have Linux x64, even on a bare kernel or in otherwise empty Docker images. I don't know how you build your binaries but you could just drop my code above into a bash script and you'd get a fully built version in the working directory.

@md5
Copy link

md5 commented Nov 18, 2015

@lorenz Using exec 1>/dev/null or exec 1>&2 at the top of your command might be nice.

@hmalphettes
Copy link

@md5 at the moment the console output of the script is only the error stream.
I think it comes in handy if things go wrong.

This is what it generates on my machine:

core@core-01 ~ $ ./build-forego.sh
debconf: delaying package configuration, since apt-utils is not installed

@md5
Copy link

md5 commented Nov 18, 2015

I just realized that would mess with the final "cat" too.
On Nov 18, 2015 00:07, "Hugues Malphettes" notifications@github.com wrote:

@md5 https://github.com/md5 at the moment the console output of the
script is only the error stream.
I think it comes in handy if things go wrong.

This is what it generates on my machine:

core@core-01 ~ $ ./build-forego.sh
debconf: delaying package configuration, since apt-utils is not installed


Reply to this email directly or view it on GitHub
#65 (comment).

cybercode pushed a commit to cybercode/nginx-proxy that referenced this issue Jan 3, 2016
Now that jwilder includes (docker >= 1.8.0 )mounts in the runtime
container, use his supported version. Note that this is a BREAKING
CHANGE, as the cyberCode version stores the mounts and volumes in the
same runtime container data structure (Volumes) and the jwilder version
stores them separately. This means that templates developed for docker <
1.8.0 cannot be reused as-is.

Also build static musl forego instead of glibc. Approach taken from:
 ddollar/forego#65 (comment)
@thaJeztah
Copy link

Looks like there's work in progress on creating official alpine-based nginx images; https://github.com/nginxinc/docker-nginx/blob/master/mainline/alpine/Dockerfile, and ran into this; are there still plans to ship an alpine-compatible binary?

@ddollar
Copy link
Owner

ddollar commented Apr 23, 2016

Someone figure out how to do this with Equinox and I'll add it! /cc @inconshreveable

@ddollar ddollar closed this as completed Apr 23, 2016
@inconshreveable
Copy link
Contributor

inconshreveable commented Apr 23, 2016

Yeah, I have this same problem with ngrok. Your options (at the moment) are:

  • CGO_ENABLED=0 for all builds. This breaks os/user.Current and disables native certificate store lookups on darwin and forces use of the pure-Go resolver on non-windows platforms.
  • Create a separate channel 'stable-static' in equinox and release to both channels. Equinox forces unique version strings, so you'd just need to pass it ${VERSION}-static or something like that.

I have this problem with static builds and GOARM=5, so we'll get native support into equinox to deal with this problem, just not sure when it will land.

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

No branches or pull requests

7 participants