Skip to content

Instantly share code, notes, and snippets.

@jamesbrink
Created February 8, 2019 02:07
Show Gist options
  • Save jamesbrink/e158ba1efa78aea1fd179cfd6ed0c54f to your computer and use it in GitHub Desktop.
Save jamesbrink/e158ba1efa78aea1fd179cfd6ed0c54f to your computer and use it in GitHub Desktop.
IPFS Dockerfile
FROM golang:1.11.5-alpine3.9
ARG IPFS_VERSION="v0.4.18"
ARG IPFS_CLUSTER_VERSION="v0.8.0"
ARG IPFS_WEBUI_VERSION="v2.3.3"
ARG IPFS_SRC_DIR="/go/src/github.com/ipfs"
# Build IPFS & IPFS Cluster from source.
WORKDIR ${IPFS_SRC_DIR}
# Install build deps.
RUN set -xe; \
apk add --update --no-cache \
bash \
build-base \
git \
nodejs \
npm \
python; \
go get -u github.com/whyrusleeping/gx; \
go get -u github.com/whyrusleeping/gx-go;
# Clone IPFS
RUN set -xe; \
git clone --branch "${IPFS_VERSION}" --single-branch https://github.com/ipfs/go-ipfs.git;
# Build IPFS
RUN set -xe; \
cd go-ipfs; \
gx --verbose install --global; \
make install_unsupported;
# Clone IPFS Cluster
RUN set -xe; \
git clone --branch "${IPFS_CLUSTER_VERSION}" --single-branch https://github.com/ipfs/ipfs-cluster.git;
# Build IPFS Cluster
RUN set -xe; \
cd ipfs-cluster; \
gx --verbose install --global; \
gx-go rw; \
go get; \
make -C cmd/ipfs-cluster-service install; \
make -C cmd/ipfs-cluster-ctl install;
# Clone IPFS WebUI
RUN set- xe; \
mkdir -p /usr/src; \
cd /usr/src; \
git clone --branch "${IPFS_WEBUI_VERSION}" --single-branch https://github.com/ipfs-shipyard/ipfs-webui;
# Install IPFS WebUI deps.
RUN set -xe; \
cd /usr/src/ipfs-webui; \
npm install;
# Build IPFS WebUI.
RUN set -xe; \
cd /usr/src/ipfs-webui; \
npm run build;
# Build our runtime container.
FROM alpine:3.9
# Create our group & user.
RUN addgroup -g 1000 -S ipfs; \
adduser -u 1000 -S -h /ipfs -s /bin/sh -G ipfs ipfs
# Install runtime deps.
RUN set -xe; \
apk add --update --no-cache --virtual .runtime-deps \
su-exec \
tini;
# Copy the IPFS binary from build stage.
COPY --from=0 /go/bin/ipfs /usr/local/bin/ipfs
# Copy the IPFS Cluster binaries from build state.
COPY --from=0 /go/bin/ipfs-cluster-service /usr/local/bin/ipfs-cluster-service
COPY --from=0 /go/bin/ipfs-cluster-ctl /usr/local/bin/ipfs-cluster-ctl
# Copy the IPFS WebUI
# Swarm TCP; should be exposed to the public
EXPOSE 4001
# Daemon API; must not be exposed publicly but to client services under you control
EXPOSE 5001
# Web Gateway; can be exposed publicly with a proxy, e.g. as https://ipfs.example.org
EXPOSE 8080
# Swarm Websockets; must be exposed publicly when the node is listening using the websocket transport (/ipX/.../tcp/8081/ws).
EXPOSE 8081
# Setup the IPFS repo.
RUN set -xe; \
mkdir -p /data/ipfs; \
chown -R ipfs:ipfs /data/ipfs;
# Switch to our non-privileged user.
USER ipfs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment