1
- FROM alpine:edge
1
+ FROM golang:1.9-stretch
2
2
MAINTAINER Lars Gierth <
[email protected] >
3
3
4
4
# There is a copy of this Dockerfile called Dockerfile.fast,
5
5
# which is optimized for build time, instead of image size.
6
6
#
7
7
# Please keep these two Dockerfiles in sync.
8
8
9
+ ENV GX_IPFS ""
10
+ ENV SRC_DIR /go/src/github.com/ipfs/go-ipfs
11
+
12
+ COPY . $SRC_DIR
13
+
14
+ # Build the thing.
15
+ RUN cd $SRC_DIR \
16
+ # Required for getting the HEAD commit hash via git rev-parse.
17
+ && mkdir .git/objects \
18
+ # Allows using a custom (i.e. local) IPFS API endpoint.
19
+ && ([ -z "$GX_IPFS" ] || echo $GX_IPFS > /root/.ipfs/api) \
20
+ # Build the thing.
21
+ && make build
22
+
23
+ # Get the TLS CA certificates, they're not provided by busybox.
24
+ RUN apt-get install -y ca-certificates
25
+
26
+ # Now comes the actual target image, which aims to be as small as possible.
27
+ FROM busybox:1-glibc
28
+ MAINTAINER Lars Gierth <
[email protected] >
29
+
30
+ # Get the ipfs binary, entrypoint script, and TLS CAs from the build container.
31
+ ENV SRC_DIR /go/src/github.com/ipfs/go-ipfs
32
+ COPY --from=0 $SRC_DIR/cmd/ipfs/ipfs /usr/local/bin/ipfs
33
+ COPY --from=0 $SRC_DIR/bin/container_daemon /usr/local/bin/start_ipfs
34
+ COPY --from=0 /etc/ssl/certs /etc/ssl/certs
35
+
36
+ # This shared lib (part of glibc) doesn't seem to be included with busybox.
37
+ COPY --from=0 /lib/x86_64-linux-gnu/libdl-2.24.so /lib/libdl.so.2
38
+
39
+ # This installs a very simple program acting as the init process.
40
+ # Makes sure signals are properly passed to the ipfs daemon process.
41
+ ENV TINI_VERSION v0.16.1
42
+ ADD https://github.com/krallin/tini/releases/download/$TINI_VERSION/tini /sbin/tini
43
+ RUN chmod +x /sbin/tini
9
44
10
45
# Ports for Swarm TCP, Swarm uTP, API, Gateway, Swarm Websockets
11
46
EXPOSE 4001
@@ -14,51 +49,18 @@ EXPOSE 5001
14
49
EXPOSE 8080
15
50
EXPOSE 8081
16
51
17
- # IPFS API to use for fetching gx packages.
18
- # This can be a gateway too, since its read-only API provides all gx needs.
19
- # - e.g. /ip4/172.17.0.1/tcp/8080 if the Docker host
20
- # has the IPFS gateway listening on the bridge interface
21
- # provided by Docker's default networking.
22
- # - if empty, the public gateway at ipfs.io is used.
23
- ENV GX_IPFS ""
24
- # The IPFS fs-repo within the container
52
+ # Create the fs-repo directory and switch to a non-privileged user.
25
53
ENV IPFS_PATH /data/ipfs
26
- # The default logging level
27
- ENV IPFS_LOGGING ""
28
- # Golang stuff
29
- ENV GOPATH /go
30
- ENV PATH /go/bin:$PATH
31
- ENV SRC_PATH /go/src/github.com/ipfs/go-ipfs
54
+ RUN mkdir -p $IPFS_PATH && adduser -D -h $IPFS_PATH -u 1000 -g 100 ipfs
55
+ USER ipfs
32
56
33
57
# Expose the fs-repo as a volume.
34
- # start_ipfs initializes an fs-repo if none is mounted
58
+ # start_ipfs initializes an fs-repo if none is mounted.
59
+ # Important this happens after the USER directive so permission are correct.
35
60
VOLUME $IPFS_PATH
36
61
37
- # Get the go-ipfs sourcecode
38
- COPY . $SRC_PATH
39
-
40
- RUN apk add --no-cache --virtual .build-deps-ipfs musl-dev gcc go git \
41
- && apk add --no-cache tini su-exec bash wget ca-certificates \
42
- # Setup user
43
- && adduser -D -h $IPFS_PATH -u 1000 ipfs \
44
- # Install gx
45
- && go get -u github.com/whyrusleeping/gx \
46
- && go get -u github.com/whyrusleeping/gx-go \
47
- # Point gx to a specific IPFS API
48
- && ([ -z "$GX_IPFS" ] || echo $GX_IPFS > $IPFS_PATH/api) \
49
- # Invoke gx
50
- && cd $SRC_PATH \
51
- && gx --verbose install --global \
52
- && mkdir .git/objects && commit=$(git rev-parse --short HEAD) \
53
- && echo "ldflags=-X github.com/ipfs/go-ipfs/repo/config.CurrentCommit=$commit" \
54
- # Build and install IPFS and entrypoint script
55
- && cd $SRC_PATH/cmd/ipfs \
56
- && go build -ldflags "-X github.com/ipfs/go-ipfs/repo/config.CurrentCommit=$commit" \
57
- && cp ipfs /usr/local/bin/ipfs \
58
- && cp $SRC_PATH/bin/container_daemon /usr/local/bin/start_ipfs \
59
- && chmod 755 /usr/local/bin/start_ipfs \
60
- # Remove all build-time dependencies
61
- && apk del --purge .build-deps-ipfs && rm -rf $GOPATH && rm -vf $IPFS_PATH/api
62
+ # The default logging level
63
+ ENV IPFS_LOGGING ""
62
64
63
65
# This just makes sure that:
64
66
# 1. There's an fs-repo, and initializes one if there isn't.
0 commit comments