Last active
July 1, 2024 19:13
-
-
Save Anunayj/f58463793ef3902eb4d0f4a24ce8b875 to your computer and use it in GitHub Desktop.
Build Letsdane statically
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
#Install Openssl | |
FROM base as setup-openssl | |
WORKDIR /tmp | |
RUN wget https://www.openssl.org/source/openssl-1.1.1j.tar.gz && tar -xzf openssl-1.1.1j.tar.gz | |
WORKDIR /tmp/openssl-1.1.1j | |
RUN ./Configure linux-x86_64 --prefix=/opt/install | |
RUN make && make install | |
#Install Unbound | |
FROM setup-openssl as setup-unbound | |
COPY --from=setup-openssl /opt/install/ /usr/local | |
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" ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Or use this intermediate image
and build with this