Dockerfile 3.57 KB
Newer Older
Steven Allen's avatar
Steven Allen committed
1
FROM golang:1.13.8-buster
Jakub Kaczmarzyk's avatar
Jakub Kaczmarzyk committed
2
LABEL maintainer="Steven Allen <steven@stebalien.com>"
Lars Gierth's avatar
Lars Gierth committed
3

4 5 6 7 8 9
# Install deps
RUN apt-get update && apt-get install -y \
  libssl-dev \
  ca-certificates \
  fuse

10
ENV SRC_DIR /go-ipfs
11

12 13 14 15
# Download packages first so they can be cached.
COPY go.mod go.sum $SRC_DIR/
RUN cd $SRC_DIR \
  && go mod download
16 17 18

COPY . $SRC_DIR

19 20 21 22
# Preload an in-tree but disabled-by-default plugin by adding it to the IPFS_PLUGINS variable
# e.g. docker build --build-arg IPFS_PLUGINS="foo bar baz"
ARG IPFS_PLUGINS

23
# Build the thing.
24
# Also: fix getting HEAD commit hash via git rev-parse.
25 26
RUN cd $SRC_DIR \
  && mkdir .git/objects \
27
  && make build GOTAGS=openssl IPFS_PLUGINS=$IPFS_PLUGINS
28

29 30
# Get su-exec, a very minimal tool for dropping privileges,
# and tini, a very minimal init daemon for containers
31
ENV SUEXEC_VERSION v0.2
32
ENV TINI_VERSION v0.18.0
33 34 35 36 37 38 39
RUN set -eux; \
    dpkgArch="$(dpkg --print-architecture)"; \
    case "${dpkgArch##*-}" in \
        "amd64" | "armhf" | "arm64") tiniArch="tini-$dpkgArch" ;;\
        *) echo >&2 "unsupported architecture: ${dpkgArch}"; exit 1 ;; \
    esac; \
  cd /tmp \
40 41 42 43 44
  && git clone https://github.com/ncopa/su-exec.git \
  && cd su-exec \
  && git checkout -q $SUEXEC_VERSION \
  && make \
  && cd /tmp \
45
  && wget -q -O tini https://github.com/krallin/tini/releases/download/$TINI_VERSION/$tiniArch \
46 47 48
  && chmod +x tini

# Now comes the actual target image, which aims to be as small as possible.
49
FROM busybox:1.31.1-glibc
50
LABEL maintainer="Steven Allen <steven@stebalien.com>"
51 52

# Get the ipfs binary, entrypoint script, and TLS CAs from the build container.
53
ENV SRC_DIR /go-ipfs
54 55 56 57
COPY --from=0 $SRC_DIR/cmd/ipfs/ipfs /usr/local/bin/ipfs
COPY --from=0 $SRC_DIR/bin/container_daemon /usr/local/bin/start_ipfs
COPY --from=0 /tmp/su-exec/su-exec /sbin/su-exec
COPY --from=0 /tmp/tini /sbin/tini
58
COPY --from=0 /bin/fusermount /usr/local/bin/fusermount
59 60
COPY --from=0 /etc/ssl/certs /etc/ssl/certs

61 62 63
# Add suid bit on fusermount so it will run properly
RUN chmod 4755 /usr/local/bin/fusermount

64 65 66
# Fix permissions on start_ipfs (ignore the build machine's permissions)
RUN chmod 0755 /usr/local/bin/start_ipfs

67
# This shared lib (part of glibc) doesn't seem to be included with busybox.
68
COPY --from=0 /lib/*-linux-gnu*/libdl.so.2 /lib/
Knut Ahlers's avatar
Knut Ahlers committed
69

70
# Copy over SSL libraries.
71 72
COPY --from=0 /usr/lib/*-linux-gnu*/libssl.so* /usr/lib/
COPY --from=0 /usr/lib/*-linux-gnu*/libcrypto.so* /usr/lib/
73

74
# Swarm TCP; should be exposed to the public
Lars Gierth's avatar
Lars Gierth committed
75
EXPOSE 4001
76
# Daemon API; must not be exposed publicly but to client services under you control
Lars Gierth's avatar
Lars Gierth committed
77
EXPOSE 5001
78
# Web Gateway; can be exposed publicly with a proxy, e.g. as https://ipfs.example.org
Lars Gierth's avatar
Lars Gierth committed
79
EXPOSE 8080
80
# Swarm Websockets; must be exposed publicly when the node is listening using the websocket transport (/ipX/.../tcp/8081/ws).
81
EXPOSE 8081
Knut Ahlers's avatar
Knut Ahlers committed
82

83
# Create the fs-repo directory and switch to a non-privileged user.
Lars Gierth's avatar
Lars Gierth committed
84
ENV IPFS_PATH /data/ipfs
85
RUN mkdir -p $IPFS_PATH \
86 87
  && adduser -D -h $IPFS_PATH -u 1000 -G users ipfs \
  && chown ipfs:users $IPFS_PATH
88

89 90 91 92
# Create mount points for `ipfs mount` command
RUN mkdir /ipfs /ipns \
  && chown ipfs:users /ipfs /ipns

kpcyrd's avatar
kpcyrd committed
93
# Expose the fs-repo as a volume.
94 95
# start_ipfs initializes an fs-repo if none is mounted.
# Important this happens after the USER directive so permission are correct.
kpcyrd's avatar
kpcyrd committed
96 97
VOLUME $IPFS_PATH

98 99
# The default logging level
ENV IPFS_LOGGING ""
100

Lars Gierth's avatar
Lars Gierth committed
101 102 103
# This just makes sure that:
# 1. There's an fs-repo, and initializes one if there isn't.
# 2. The API and Gateway are accessible from outside the container.
kpcyrd's avatar
kpcyrd committed
104
ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/start_ipfs"]
105 106

# Execute the daemon subcommand by default
kpcyrd's avatar
kpcyrd committed
107
CMD ["daemon", "--migrate=true"]