Add Dockerfile

License: MIT
Signed-off-by: Hector Sanjuan <hector@protocol.ai>
This commit is contained in:
Hector Sanjuan 2017-03-06 16:29:23 +01:00
parent 9d6121c426
commit ee57cf8a36
2 changed files with 81 additions and 0 deletions

40
Dockerfile Normal file
View File

@ -0,0 +1,40 @@
FROM ipfs/go-ipfs:release
MAINTAINER Hector Sanjuan <hector@protocol.ai>
EXPOSE 9094
EXPOSE 9095
EXPOSE 9096
ENV GOPATH /go
ENV PATH /go/bin:$PATH
ENV SRC_PATH /go/src/github.com/ipfs/ipfs-cluster
ENV IPFS_CLUSTER_PATH /data/ipfs-cluster
USER root
COPY . $SRC_PATH
RUN apk add --no-cache --virtual cluster-deps make musl-dev go git \
&& apk add --no-cache jq \
&& mkdir -p $IPFS_CLUSTER_PATH \
&& chown ipfs:ipfs $IPFS_CLUSTER_PATH && chmod 0755 $IPFS_CLUSTER_PATH \
&& go get -u github.com/whyrusleeping/gx \
&& go get -u github.com/whyrusleeping/gx-go \
&& cd $SRC_PATH \
&& gx install --global \
&& gx-go rewrite \
&& go build \
&& make -C ipfs-cluster-service install \
&& make -C ipfs-cluster-ctl install \
&& cp docker/entrypoint.sh /usr/local/bin/start-daemons.sh \
&& chmod +x /usr/local/bin/start-daemons.sh \
&& apk del --purge cluster-deps \
&& cd / && rm -rf /go/src /go/bin/gx /go/bin/gx-go
USER ipfs
VOLUME $IPFS_CLUSTER_PATH
ENTRYPOINT ["/usr/local/bin/start-daemons.sh"]
CMD ["$IPFS_CLUSTER_OPTS"]

41
docker/entrypoint.sh Normal file
View File

@ -0,0 +1,41 @@
#!/bin/sh
user=$(whoami)
repo="$IPFS_PATH"
# Test whether the mounted directory is writable for us
if [ ! -w "$repo" 2>/dev/null ]; then
echo "error: $repo is not writable for user $user (uid=$(id -u $user))"
exit 1
fi
ipfs version
if [ -e "$repo/config" ]; then
echo "Found IPFS fs-repo at $repo"
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
# Test whether the mounted directory is writable for us
if [ ! -w "$IPFS_CLUSTER_PATH" 2>/dev/null ]; then
echo "error: $IPFS_CLUSTER_PATH is not writable for user $user (uid=$(id -u $user))"
exit 1
fi
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 $@