From 4b9263ff2466217def7d9c3b2759b6894c9ca8ee Mon Sep 17 00:00:00 2001 From: Adin Schmahmann Date: Mon, 24 Jun 2024 18:15:14 -0400 Subject: [PATCH] feat: standardize dockerfile --- Dockerfile | 50 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4b1c1e6..d1b0d19 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,42 @@ -FROM cimg/go:1.22.4 -USER circleci -RUN mkdir -p /home/circleci/app -WORKDIR /home/circleci/app -COPY --chown=circleci:circleci *.go go.mod go.sum ./ -EXPOSE 3333 -RUN go build -CMD [ "./ipfs-check" ] +# Builder +FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.21-bookworm AS builder + +LABEL org.opencontainers.image.source=https://github.com/ipfs-shipyard/ipfs-check +LABEL org.opencontainers.image.description="Check if you can find your content on IPFS" +LABEL org.opencontainers.image.licenses=MIT+APACHE_2.0 + +ARG TARGETPLATFORM TARGETOS TARGETARCH + +ENV GOPATH /go +ENV SRC_PATH $GOPATH/src/github.com/ipfs-shipyard/ipfs-check +ENV GO111MODULE on +ENV GOPROXY https://proxy.golang.org + +COPY go.* $SRC_PATH/ +WORKDIR $SRC_PATH +RUN go mod download + +COPY . $SRC_PATH +RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o $GOPATH/bin/ipfs-check + +# 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-shipyard/ipfs-check +ENV DATA_PATH /data/ipfs-check + +COPY --from=builder $GOPATH/bin/ipfs-check /usr/local/bin/ipfs-check + +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 + +USER ipfs +ENTRYPOINT ["tini", "--", "/usr/local/bin/ipfs-check", "start"] \ No newline at end of file