-
Notifications
You must be signed in to change notification settings - Fork 11
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
Building Static Binaries for multi platform deployment. #9
Comments
This Dockerfile can be used to automatically make builds using GitHub Actions, though I'm unsure how I should deal with the dependencies part, Should I export that as a Image and keep it on Dockerhub (and use FROM anunayj/go-alpine-unbound) or should I keep it like this and let the cache do it's job. (GitHub Actions evicts cache after 7 days of inactivity). |
Also I have no idea what was causing the problems compiling earlier when i was using a lxd container. I guess I installed unbound from apk and then built it from source causing a unholy mess. |
Alternatively to save time/or if you are lazy to compile openssl this can be used. FROM anunayj/golang-libunbound@sha256:4db0797175be0d38f0a65f81517d1862a72c745cfb42d53b09aed477f00d6e5d as builder
#Install Dependendencies
WORKDIR /tmp/dane
COPY go.mod /tmp/dane/go.mod
RUN go mod download
#Will allow caching dependencies in layers.
COPY . /tmp/dane/
WORKDIR /tmp/dane/cmd/letsdane
#Build Static
RUN go build -tags unbound --ldflags '-extldflags "-lunbound -lssl -lcrypto -static"'
FROM scratch
COPY --from=builder /tmp/dane/cmd/letsdane/letsdane /
ENTRYPOINT [ "letsdane" ] Sources for intermediate image here https://gist.github.com/Anunayj/f58463793ef3902eb4d0f4a24ce8b875 |
I have no idea how one would go about compiling for windows and mac, go does allow you to specify to build for P.S. We really need a Windows subsystem for Linux haha. |
Also are https://www.openssl.org/source/openssl-1.1.1j.tar.gz and https://www.nlnetlabs.nl/downloads/unbound/unbound-1.13.1.tar.gz updated with appropriate security fixes if there is one? |
Building static binaries isn't a frequent process if it's only done for every release. It's okay to leave it to build from source even if takes a bit of time. It's unfortunate that alpine doesn't include
Unbound is an optional dependency so letsdane can be built on most OSs with just building on macOS with unbound is pretty simple (shared libs) brew install unbound
git clone ...
go build -tags unbound To bundle unbound in the same binary, I built it this way (on MBP running Big Sur). I just installed unbound using macos prefers dynamic libraries so if there is a dynamic lib and a static lib in the same directory it will pick the dynamic one. So I specified the path for each CGO_LDFLAGS="/usr/local/opt/unbound/lib/libunbound.a \
/usr/local/opt/openssl/lib/libssl.a \
/usr/local/opt/openssl/lib/libcrypto.a \
/usr/local/opt/nghttp2/lib/libnghttp2.a \
/usr/local/opt/libevent/lib/libevent.a" go build -tags unbound it's not clear to me yet if that's the best way to do it.
Those are links to the latest stable versions. They must be updated if new versions come up. Unbound includes a link for latest version https://nlnetlabs.nl/downloads/unbound/unbound-latest.tar.gz which is always updated (but this probably wouldn't be very stable if they include a new dependency or change something that affects compatibility) |
Just tested it, and it works, updated the dockerfile. |
I tried making binaries for macos using this command
but seems like it still dynamically linked the binary?
if I use
I get
|
Static Binaries for each platform can be built using:
Linux
Static Binaries for Linux can be made using the following Dockerfile (or running the commands in Dockerfile manually).
Use
DOCKER_BUILDKIT=1 docker build -f static.Dockerfile -o build/ .
to export the binary into build directory.Running this first time can take >500 seconds (Mostly because of all the compiling that needs to be done for
unbound
andopenssl
), The Image layer can be exported to Dockerhub and used repeatedly if necessary. Subsequent builds should take <100 seconds.Todo:
The text was updated successfully, but these errors were encountered: