diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..2fbde460 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +Dockerfile +Dockerfile-* diff --git a/Dockerfile b/Dockerfile index 5bbde9e4..e6a92b2a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM golang:1.9-stretch AS builder MAINTAINER Hector Sanjuan -# This build state just builds the cluster binaries +# This dockerfile builds and runs ipfs-cluster-service. ENV GOPATH /go ENV SRC_PATH $GOPATH/src/github.com/ipfs/ipfs-cluster @@ -10,8 +10,20 @@ COPY . $SRC_PATH WORKDIR $SRC_PATH RUN make install +ENV SUEXEC_VERSION v0.2 +ENV TINI_VERSION v0.16.1 +RUN set -x \ + && cd /tmp \ + && git clone https://github.com/ncopa/su-exec.git \ + && cd su-exec \ + && git checkout -q $SUEXEC_VERSION \ + && make \ + && cd /tmp \ + && wget -q -O tini https://github.com/krallin/tini/releases/download/$TINI_VERSION/tini \ + && chmod +x tini + #------------------------------------------------------ -FROM ipfs/go-ipfs +FROM busybox:1-glibc MAINTAINER Hector Sanjuan # This is the container which just puts the previously @@ -27,13 +39,16 @@ EXPOSE 9096 COPY --from=builder $GOPATH/bin/ipfs-cluster-service /usr/local/bin/ipfs-cluster-service COPY --from=builder $GOPATH/bin/ipfs-cluster-ctl /usr/local/bin/ipfs-cluster-ctl -COPY --from=builder $SRC_PATH/docker/entrypoint.sh /usr/local/bin/start-daemons.sh +COPY --from=builder $SRC_PATH/docker/entrypoint.sh /usr/local/bin/entrypoint.sh +COPY --from=builder /tmp/su-exec/su-exec /sbin/su-exec +COPY --from=builder /tmp/tini /sbin/tini RUN mkdir -p $IPFS_CLUSTER_PATH && \ - chown 1000:100 $IPFS_CLUSTER_PATH + adduser -D -h $IPFS_CLUSTER_PATH -u 1000 -G users ipfs && \ + chown ipfs:users $IPFS_CLUSTER_PATH VOLUME $IPFS_CLUSTER_PATH -ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/start-daemons.sh"] +ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/entrypoint.sh"] # Defaults for ipfs-cluster-service would go here CMD [] diff --git a/Dockerfile-bundle b/Dockerfile-bundle new file mode 100644 index 00000000..ad34bdfb --- /dev/null +++ b/Dockerfile-bundle @@ -0,0 +1,41 @@ +FROM golang:1.9-stretch AS builder +MAINTAINER Hector Sanjuan + +# This dockerfile builds cluster and runs it along with go-ipfs. +# It re-uses the latest go-ipfs:release container. + +# This builder just builds the cluster binaries +ENV GOPATH /go +ENV SRC_PATH $GOPATH/src/github.com/ipfs/ipfs-cluster + +COPY . $SRC_PATH +WORKDIR $SRC_PATH +RUN make install + +#------------------------------------------------------ +FROM ipfs/go-ipfs:release +MAINTAINER Hector Sanjuan + +# This is the container which just puts the previously +# built binaries on the go-ipfs-container. + +ENV GOPATH /go +ENV SRC_PATH /go/src/github.com/ipfs/ipfs-cluster +ENV IPFS_CLUSTER_PATH /data/ipfs-cluster + +EXPOSE 9094 +EXPOSE 9095 +EXPOSE 9096 + +COPY --from=builder $GOPATH/bin/ipfs-cluster-service /usr/local/bin/ipfs-cluster-service +COPY --from=builder $GOPATH/bin/ipfs-cluster-ctl /usr/local/bin/ipfs-cluster-ctl +COPY --from=builder $SRC_PATH/docker/start-daemons.sh /usr/local/bin/start-daemons.sh + +RUN mkdir -p $IPFS_CLUSTER_PATH && \ + chown 1000:100 $IPFS_CLUSTER_PATH + +VOLUME $IPFS_CLUSTER_PATH +ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/start-daemons.sh"] + +# Defaults for ipfs-cluster-service would go here +CMD [] diff --git a/README.md b/README.md index 6ce5cd84..d69683d9 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ Note that since IPFS Cluster is evolving fast, these builds may not contain the ### Docker -You can build or download an automated build of the ipfs-cluster docker container. This container runs both the IPFS daemon and `ipfs-cluster-service` and includes `ipfs-cluster-ctl`. To launch the latest published version on Docker run: +You can build or download an automated build of the ipfs-cluster docker container. This container runs `ipfs-cluster-service` and includes `ipfs-cluster-ctl`. To launch the latest published version on Docker run: `$ docker run ipfs/ipfs-cluster` @@ -68,7 +68,7 @@ To build the container manually you can: `$ docker build . -t ipfs-cluster` -You can mount your local ipfs-cluster configuration and data folder by passing `-v /data/ipfs-cluster your-local-ipfs-cluster-folder` to Docker. +You can mount your local ipfs-cluster configuration and data folder by passing `-v /data/ipfs-cluster your-local-ipfs-cluster-folder` to Docker. Otherwise, a new configuration will be generated. In that case, you can point it to the right IPFS location by setting `IPFS_API` like `--env IPFS_API="/ip4/1.2.3.4/tcp/5001"`. ### Install from the snap store diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 4dac4640..d356f5df 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -1,41 +1,31 @@ #!/bin/sh set -e +user=ipfs + if [ -n "$DOCKER_DEBUG" ]; then set -x fi -user=ipfs if [ `id -u` -eq 0 ]; then echo "Changing user to $user" # ensure directories are writable - su-exec "$user" test -w "${IPFS_PATH}" || chown -R -- "$user" "${IPFS_PATH}" su-exec "$user" test -w "${IPFS_CLUSTER_PATH}" || chown -R -- "$user" "${IPFS_CLUSTER_PATH}" exec su-exec "$user" "$0" $@ fi -# Second invocation with regular user -ipfs version - -if [ -e "${IPFS_PATH}/config" ]; then - echo "Found IPFS fs-repo at ${IPFS_PATH}" -else - ipfs init - ipfs config Addresses.API /ip4/0.0.0.0/tcp/5001 - ipfs config Addresses.Gateway /ip4/0.0.0.0/tcp/8080 -fi - -ipfs daemon --migrate=true & -sleep 3 - +# Only ipfs user can get here ipfs-cluster-service --version if [ -e "${IPFS_CLUSTER_PATH}/service.json" ]; then echo "Found IPFS cluster configuration at ${IPFS_CLUSTER_PATH}" else ipfs-cluster-service init - sed -i 's/127\.0\.0\.1\/tcp\/9094/0.0.0.0\/tcp\/9094/' "${IPFS_CLUSTER_PATH}/service.json" - sed -i 's/127\.0\.0\.1\/tcp\/9095/0.0.0.0\/tcp\/9095/' "${IPFS_CLUSTER_PATH}/service.json" + if [ -n "$IPFS_API" ]; then + sed -i "s;/ip4/127\.0\.0\.1/tcp/5001;$IPFS_API;" "${IPFS_CLUSTER_PATH}/service.json" + fi + sed -i 's;127\.0\.0\.1/tcp/9094;0.0.0.0/tcp/9094;' "${IPFS_CLUSTER_PATH}/service.json" + sed -i 's;127\.0\.0\.1/tcp/9095;0.0.0.0/tcp/9095;' "${IPFS_CLUSTER_PATH}/service.json" fi exec ipfs-cluster-service $@ diff --git a/docker/start-daemons.sh b/docker/start-daemons.sh new file mode 100755 index 00000000..4dac4640 --- /dev/null +++ b/docker/start-daemons.sh @@ -0,0 +1,41 @@ +#!/bin/sh + +set -e +if [ -n "$DOCKER_DEBUG" ]; then + set -x +fi +user=ipfs + +if [ `id -u` -eq 0 ]; then + echo "Changing user to $user" + # ensure directories are writable + su-exec "$user" test -w "${IPFS_PATH}" || chown -R -- "$user" "${IPFS_PATH}" + su-exec "$user" test -w "${IPFS_CLUSTER_PATH}" || chown -R -- "$user" "${IPFS_CLUSTER_PATH}" + exec su-exec "$user" "$0" $@ +fi + +# Second invocation with regular user +ipfs version + +if [ -e "${IPFS_PATH}/config" ]; then + echo "Found IPFS fs-repo at ${IPFS_PATH}" +else + ipfs init + ipfs config Addresses.API /ip4/0.0.0.0/tcp/5001 + ipfs config Addresses.Gateway /ip4/0.0.0.0/tcp/8080 +fi + +ipfs daemon --migrate=true & +sleep 3 + +ipfs-cluster-service --version + +if [ -e "${IPFS_CLUSTER_PATH}/service.json" ]; then + echo "Found IPFS cluster configuration at ${IPFS_CLUSTER_PATH}" +else + ipfs-cluster-service init + sed -i 's/127\.0\.0\.1\/tcp\/9094/0.0.0.0\/tcp\/9094/' "${IPFS_CLUSTER_PATH}/service.json" + sed -i 's/127\.0\.0\.1\/tcp\/9095/0.0.0.0\/tcp\/9095/' "${IPFS_CLUSTER_PATH}/service.json" +fi + +exec ipfs-cluster-service $@ diff --git a/docs/ipfs-cluster-guide.md b/docs/ipfs-cluster-guide.md index 244432d9..167ce84b 100644 --- a/docs/ipfs-cluster-guide.md +++ b/docs/ipfs-cluster-guide.md @@ -48,7 +48,7 @@ This guide aims to collect useful considerations and information for running an There are several ways to install ipfs-cluster. They are described in the main README and summarized here: * 1. Download the repository and run `make install`. -* 2. Run the [docker ipfs/ipfs-cluster container](https://hub.docker.com/r/ipfs/ipfs-cluster/). The container includes and runs ipfs. +* 2. Run the [docker ipfs/ipfs-cluster container](https://hub.docker.com/r/ipfs/ipfs-cluster/). The container runs `ipfs-cluster-service`. * 3. Download pre-built binaries for your platform at [dist.ipfs.io](https://dist.ipfs.io). Note that we test on Linux and ARM. We're happy to hear if other platforms are working or not. * 4. Install from the [snapcraft.io](https://snapcraft.io) store: `sudo snap install ipfs-cluster --edge`. Note that there is no stable snap yet.