Dockerfile: Remove ipfs from container

The main container will now run only ipfs-cluster-service.

A new ipfs-cluster-bundle container is built by Dockerfile-bundle
which will provide ipfs-cluster+ipfs.

Fixes #197

License: MIT
Signed-off-by: Hector Sanjuan <code@hector.link>
This commit is contained in:
Hector Sanjuan 2017-11-23 14:40:49 +01:00
parent 025fc95279
commit d6800045b5
7 changed files with 115 additions and 26 deletions

2
.dockerignore Normal file
View File

@ -0,0 +1,2 @@
Dockerfile
Dockerfile-*

View File

@ -1,7 +1,7 @@
FROM golang:1.9-stretch AS builder
MAINTAINER Hector Sanjuan <hector@protocol.ai>
# 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 <hector@protocol.ai>
# 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 []

41
Dockerfile-bundle Normal file
View File

@ -0,0 +1,41 @@
FROM golang:1.9-stretch AS builder
MAINTAINER Hector Sanjuan <hector@protocol.ai>
# 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 <hector@protocol.ai>
# 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 []

View File

@ -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

View File

@ -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 $@

41
docker/start-daemons.sh Executable file
View File

@ -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 $@

View File

@ -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.