Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
refactor(docker): simplify Dockerfile, fix arm64 (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
lidel authored Jul 4, 2023
1 parent 41518e5 commit 453fd72
Showing 1 changed file with 16 additions and 37 deletions.
53 changes: 16 additions & 37 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,67 +1,46 @@
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.20-bullseye AS builder
MAINTAINER IPFS Stewards <[email protected]>
# This builds bifrost-gateway

# This dockerfile builds and runs bifrost-gateway

ARG TARGETPLATFORM
ARG BUILDPLATFORM
ARG TARGETOS
ARG TARGETARCH
ARG TARGETPLATFORM TARGETOS TARGETARCH

ENV GOPATH /go
ENV SRC_PATH $GOPATH/src/github.com/ipfs/bifrost-gateway
ENV GO111MODULE on
ENV GOPROXY https://proxy.golang.org

ENV SUEXEC_VERSION v0.2
ENV TINI_VERSION v0.19.0
RUN set -eux; \
dpkgArch="$(dpkg --print-architecture)"; \
case "${dpkgArch##*-}" in \
"amd64" | "armhf" | "arm64") tiniArch="tini-static-$dpkgArch" ;;\
*) echo >&2 "unsupported architecture: ${dpkgArch}"; exit 1 ;; \
esac; \
cd /tmp \
&& git clone https://github.com/ncopa/su-exec.git \
&& cd su-exec \
&& git checkout -q $SUEXEC_VERSION \
&& make su-exec-static \
&& cd /tmp \
&& wget -q -O tini https://github.com/krallin/tini/releases/download/$TINI_VERSION/$tiniArch \
&& chmod +x tini

# Get the TLS CA certificates, they're not provided by busybox.
RUN apt-get update && apt-get install -y ca-certificates

COPY --chown=1000:users go.* $SRC_PATH/
COPY go.* $SRC_PATH/
WORKDIR $SRC_PATH
RUN go mod download

COPY --chown=1000:users . $SRC_PATH
COPY . $SRC_PATH
RUN git config --global --add safe.directory /go/src/github.com/ipfs/bifrost-gateway
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o $GOPATH/bin/bifrost-gateway

RUN --mount=target=. \
--mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o $GOPATH/bin/bifrost-gateway

#------------------------------------------------------
FROM --platform=${BUILDPLATFORM:-linux/amd64} busybox:1.34.1-glibc
MAINTAINER IPFS Stewards <[email protected]>
FROM alpine:3.18

# This runs bifrost-gateway

# Instal binaries for $TARGETARCH
RUN apk add --no-cache tini su-exec ca-certificates

ENV GOPATH /go
ENV SRC_PATH /go/src/github.com/ipfs/bifrost-gateway
ENV SRC_PATH $GOPATH/src/github.com/ipfs/bifrost-gateway
ENV BIFROST_GATEWAY_PATH /data/bifrost-gateway
ENV KUBO_RPC_URL https://node0.delegate.ipfs.io,https://node1.delegate.ipfs.io,https://node2.delegate.ipfs.io,https://node3.delegate.ipfs.io

COPY --from=builder $GOPATH/bin/bifrost-gateway /usr/local/bin/bifrost-gateway
COPY --from=builder $SRC_PATH/docker/entrypoint.sh /usr/local/bin/entrypoint.sh
COPY --from=builder /tmp/su-exec/su-exec-static /sbin/su-exec
COPY --from=builder /tmp/tini /sbin/tini
COPY --from=builder /etc/ssl/certs /etc/ssl/certs

RUN mkdir -p $BIFROST_GATEWAY_PATH && \
adduser -D -h $BIFROST_GATEWAY_PATH -u 1000 -G users ipfs && \
chown ipfs:users $BIFROST_GATEWAY_PATH

VOLUME $BIFROST_GATEWAY_PATH

ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/entrypoint.sh"]

CMD ["--gateway-port", "8081", "--metrics-port", "8041"]

0 comments on commit 453fd72

Please sign in to comment.