Open
Description
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).
# DOCKER_BUILDKIT=1 docker build -f static.Dockerfile -o build/ .
FROM golang:alpine AS base
RUN apk update && apk add linux-headers gcc make perl musl-dev expat-dev openssl-libs-static openssl-dev
#Install Unbound
FROM base as setup-unbound
WORKDIR /tmp
RUN wget https://www.nlnetlabs.nl/downloads/unbound/unbound-1.13.1.tar.gz && tar -xzf unbound-1.13.1.tar.gz
WORKDIR /tmp/unbound-1.13.1
RUN ./configure --prefix=/opt/install
RUN make && make install
FROM base as builder
#Install Dependencies
COPY --from=setup-unbound /opt/install/ /usr/local
#Optionally export this layer and cache this permanently somewhere.
#Copy stuff overgo mod download
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" ]
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
and openssl
), The Image layer can be exported to Dockerhub and used repeatedly if necessary. Subsequent builds should take <100 seconds.
Todo:
- Document building static binaries for Linux
- Document building static binaries for Windows
- Document building static binaries for MacOS
Metadata
Metadata
Assignees
Labels
No labels