From 2f7726e87bf331b27eccac01ba6c4a57a1f0df1e Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Fri, 22 Mar 2024 14:03:13 +0100 Subject: [PATCH] docker: smaller docker image --- Dockerfile | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index bb23baf..a8b5f38 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,42 @@ -FROM golang:1.21-bullseye +# Builder +FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.21-bookworm AS builder -WORKDIR /app +LABEL org.opencontainers.image.source=https://github.com/ipfs/someguy +LABEL org.opencontainers.image.description="A standalone Delegated Routing V1 server" +LABEL org.opencontainers.image.licenses=MIT+APACHE_2.0 -COPY go.mod ./ -COPY go.sum ./ +ARG TARGETPLATFORM TARGETOS TARGETARCH + +ENV GOPATH /go +ENV SRC_PATH $GOPATH/src/github.com/ipfs/someguy +ENV GO111MODULE on +ENV GOPROXY https://proxy.golang.org + +COPY go.* $SRC_PATH/ +WORKDIR $SRC_PATH RUN go mod download -COPY *.go ./ +COPY . $SRC_PATH +RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o $GOPATH/bin/someguy + +# Runner +FROM debian:bookworm-slim + +RUN apt-get update && \ + apt-get install --no-install-recommends -y tini ca-certificates curl && \ + rm -rf /var/lib/apt/lists/* + +ENV GOPATH /go +ENV SRC_PATH $GOPATH/src/github.com/ipfs/someguy +ENV DATA_PATH /data/someguy + +COPY --from=builder $GOPATH/bin/someguy /usr/local/bin/someguy -RUN go build -o /someguy +RUN mkdir -p $DATA_PATH && \ + useradd -d $DATA_PATH -u 1000 -G users ipfs && \ + chown ipfs:users $DATA_PATH +VOLUME $DATA_PATH +WORKDIR $DATA_PATH -CMD [ "/someguy", "start" ] +USER ipfs +ENTRYPOINT ["tini", "--", "/usr/local/bin/someguy", "start"]