Fix #154: Update Dockerfiles
After changes on how the final docker image for go-ipfs is generated, our Dockerfiles failed to build. The new version is inspired on go-ipfs Dockerfile. It takes advantage of docker >= v17.06 which allows multi-stage Dockerfiles with several FROM directives and COPY --from. This allows build freely on a first stage, without thinking of cleaning up, and then just copy the final artifacts to a second, minimal image. The Dockerfile-test is similarly updated. Minor changes have been applied to the entrypoints. License: MIT Signed-off-by: Hector Sanjuan <hector@protocol.ai>
This commit is contained in:
parent
03b21bf97d
commit
1d256166d6
50
Dockerfile
50
Dockerfile
|
@ -1,34 +1,38 @@
|
||||||
FROM ipfs/go-ipfs:release
|
FROM golang:1.9-stretch AS builder
|
||||||
MAINTAINER Hector Sanjuan <hector@protocol.ai>
|
MAINTAINER Hector Sanjuan <hector@protocol.ai>
|
||||||
|
|
||||||
|
# This build state 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
|
||||||
|
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 9094
|
||||||
EXPOSE 9095
|
EXPOSE 9095
|
||||||
EXPOSE 9096
|
EXPOSE 9096
|
||||||
|
|
||||||
ENV GOPATH /go
|
COPY --from=builder $GOPATH/bin/ipfs-cluster-service /usr/local/bin/ipfs-cluster-service
|
||||||
ENV PATH /go/bin:$PATH
|
COPY --from=builder $GOPATH/bin/ipfs-cluster-service /usr/local/bin/ipfs-cluster-ctl
|
||||||
ENV SRC_PATH /go/src/github.com/ipfs/ipfs-cluster
|
COPY --from=builder $SRC_PATH/docker/entrypoint.sh /usr/local/bin/start-daemons.sh
|
||||||
ENV IPFS_CLUSTER_PATH /data/ipfs-cluster
|
|
||||||
|
RUN mkdir -p $IPFS_CLUSTER_PATH && \
|
||||||
|
chown 1000:100 $IPFS_CLUSTER_PATH
|
||||||
|
|
||||||
VOLUME $IPFS_CLUSTER_PATH
|
VOLUME $IPFS_CLUSTER_PATH
|
||||||
|
|
||||||
COPY . $SRC_PATH
|
|
||||||
|
|
||||||
RUN apk add --no-cache --virtual cluster-deps make musl-dev go git \
|
|
||||||
&& apk add --no-cache jq \
|
|
||||||
&& 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
|
|
||||||
|
|
||||||
ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/start-daemons.sh"]
|
ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/start-daemons.sh"]
|
||||||
|
|
||||||
CMD ["$IPFS_CLUSTER_OPTS"]
|
CMD ["$IPFS_CLUSTER_OPTS"]
|
||||||
|
|
|
@ -1,38 +1,42 @@
|
||||||
FROM ipfs/go-ipfs:release
|
FROM golang:1.9-stretch AS builder
|
||||||
MAINTAINER Hector Sanjuan <hector@protocol.ai>
|
MAINTAINER Hector Sanjuan <hector@protocol.ai>
|
||||||
|
|
||||||
|
# This build state 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
|
||||||
|
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 9094
|
||||||
EXPOSE 9095
|
EXPOSE 9095
|
||||||
EXPOSE 9096
|
EXPOSE 9096
|
||||||
|
|
||||||
ENV GOPATH /go
|
COPY --from=builder $GOPATH/bin/ipfs-cluster-service /usr/local/bin/ipfs-cluster-service
|
||||||
ENV PATH /go/bin:$PATH
|
COPY --from=builder $GOPATH/bin/ipfs-cluster-service /usr/local/bin/ipfs-cluster-ctl
|
||||||
ENV SRC_PATH /go/src/github.com/ipfs/ipfs-cluster
|
COPY --from=builder $SRC_PATH/docker/test-entrypoint.sh /usr/local/bin/start-daemons.sh
|
||||||
ENV IPFS_CLUSTER_PATH /data/ipfs-cluster
|
COPY --from=builder $SRC_PATH/docker/random-stopper.sh /usr/local/bin/random-stopper.sh
|
||||||
|
COPY --from=builder $SRC_PATH/docker/random-killer.sh /usr/local/bin/random-killer.sh
|
||||||
|
COPY --from=builder $SRC_PATH/docker/wait-killer-stopper.sh /usr/local/bin/wait-killer-stopper.sh
|
||||||
|
COPY --from=builder $SRC_PATH/docker/cluster-restart.sh /usr/local/bin/cluster-restart.sh
|
||||||
|
|
||||||
|
RUN mkdir -p $IPFS_CLUSTER_PATH && \
|
||||||
|
chown 1000:100 $IPFS_CLUSTER_PATH
|
||||||
|
|
||||||
VOLUME $IPFS_CLUSTER_PATH
|
VOLUME $IPFS_CLUSTER_PATH
|
||||||
|
ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/start-daemons.sh"]
|
||||||
COPY . $SRC_PATH
|
|
||||||
|
|
||||||
RUN apk add --no-cache --virtual cluster-deps make musl-dev go git \
|
|
||||||
&& apk add --no-cache jq \
|
|
||||||
&& 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/test-entrypoint.sh /usr/local/bin/start-daemons.sh \
|
|
||||||
&& cp docker/random-stopper.sh /usr/local/bin/random-stopper.sh \
|
|
||||||
&& cp docker/random-killer.sh /usr/local/bin/random-killer.sh \
|
|
||||||
&& cp docker/wait-killer-stopper.sh /usr/local/bin/wait-killer-stopper.sh \
|
|
||||||
&& cp docker/cluster-restart.sh /usr/local/bin/cluster-restart.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
|
|
||||||
|
|
||||||
ENTRYPOINT ["/usr/local/bin/start-daemons.sh"]
|
|
||||||
|
|
||||||
CMD ["$IPFS_CLUSTER_OPTS"]
|
CMD ["$IPFS_CLUSTER_OPTS"]
|
||||||
|
|
18
docker/entrypoint.sh
Normal file → Executable file
18
docker/entrypoint.sh
Normal file → Executable file
|
@ -2,20 +2,20 @@
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
user=ipfs
|
user=ipfs
|
||||||
repo="$IPFS_PATH"
|
|
||||||
|
|
||||||
if [ `id -u` -eq 0 ]; then
|
if [ `id -u` -eq 0 ]; then
|
||||||
|
echo "Changing user to $user"
|
||||||
# ensure directories are writable
|
# ensure directories are writable
|
||||||
su-exec "$user" test -w "$repo" || chown -R -- "$user" "$repo"
|
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"
|
su-exec "$user" test -w "${IPFS_CLUSTER_PATH}" || chown -R -- "$user" "${IPFS_CLUSTER_PATH}"
|
||||||
exec su-exec "$user" "$0" "$@"
|
exec su-exec "$user" "$0" "$@"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Second invocation with regular user
|
# Second invocation with regular user
|
||||||
ipfs version
|
ipfs version
|
||||||
|
|
||||||
if [ -e "$repo/config" ]; then
|
if [ -e "${IPFS_PATH}/config" ]; then
|
||||||
echo "Found IPFS fs-repo at $repo"
|
echo "Found IPFS fs-repo at ${IPFS_PATH}"
|
||||||
else
|
else
|
||||||
ipfs init
|
ipfs init
|
||||||
ipfs config Addresses.API /ip4/0.0.0.0/tcp/5001
|
ipfs config Addresses.API /ip4/0.0.0.0/tcp/5001
|
||||||
|
@ -27,12 +27,12 @@ sleep 3
|
||||||
|
|
||||||
ipfs-cluster-service --version
|
ipfs-cluster-service --version
|
||||||
|
|
||||||
if [ -e "$IPFS_CLUSTER_PATH/service.json" ]; then
|
if [ -e "${IPFS_CLUSTER_PATH}/service.json" ]; then
|
||||||
echo "Found IPFS cluster configuration at $IPFS_CLUSTER_PATH"
|
echo "Found IPFS cluster configuration at ${IPFS_CLUSTER_PATH}"
|
||||||
else
|
else
|
||||||
ipfs-cluster-service init
|
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\/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"
|
sed -i 's/127\.0\.0\.1\/tcp\/9095/0.0.0.0\/tcp\/9095/' "${IPFS_CLUSTER_PATH}/service.json"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exec ipfs-cluster-service $@
|
exec ipfs-cluster-service $@
|
||||||
|
|
24
docker/test-entrypoint.sh
Normal file → Executable file
24
docker/test-entrypoint.sh
Normal file → Executable file
|
@ -2,31 +2,19 @@
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
user=ipfs
|
user=ipfs
|
||||||
repo="$IPFS_PATH"
|
|
||||||
echo "Version 0.4"
|
|
||||||
|
|
||||||
if [ `id -u` -eq 0 ]; then
|
|
||||||
# ensure folders are writeable
|
|
||||||
su-exec "$user" test -w "$repo" || chown -R -- "$user" "$repo"
|
|
||||||
su-exec "$user" test -w "$IPFS_CLUSTER_PATH" || chown -R -- "$user" "$IPFS_CLUSTER_PATH"
|
|
||||||
# restart script with new privileges
|
|
||||||
exec su-exec "$user" "$0" "$@"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Second invocation with regular user
|
|
||||||
echo "Second invocation"
|
|
||||||
|
|
||||||
if [ `id -u` -eq 0 ]; then
|
if [ `id -u` -eq 0 ]; then
|
||||||
|
echo "Changing user to $user"
|
||||||
# ensure directories are writable
|
# ensure directories are writable
|
||||||
su-exec "$user" test -w "$repo" || chown -R -- "$user" "$repo"
|
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"
|
su-exec "$user" test -w "${IPFS_CLUSTER_PATH}" || chown -R -- "$user" "${IPFS_CLUSTER_PATH}"
|
||||||
exec su-exec "$user" "$0" "$@"
|
exec su-exec "$user" "$0" "$@"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ipfs version
|
ipfs version
|
||||||
|
|
||||||
if [ -e "$repo/config" ]; then
|
if [ -e "${IPFS_PATH}/config" ]; then
|
||||||
echo "Found IPFS fs-repo at $repo"
|
echo "Found IPFS fs-repo at ${IPFS_PATH}"
|
||||||
else
|
else
|
||||||
ipfs init
|
ipfs init
|
||||||
ipfs config Addresses.API /ip4/0.0.0.0/tcp/5001
|
ipfs config Addresses.API /ip4/0.0.0.0/tcp/5001
|
||||||
|
@ -46,6 +34,7 @@ else
|
||||||
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\/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"
|
sed -i 's/127\.0\.0\.1\/tcp\/9095/0.0.0.0\/tcp\/9095/' "$IPFS_CLUSTER_PATH/service.json"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ipfs-cluster-service --debug $@ &
|
ipfs-cluster-service --debug $@ &
|
||||||
# Testing scripts that spawn background processes are spawned and stopped here
|
# Testing scripts that spawn background processes are spawned and stopped here
|
||||||
/usr/local/bin/random-stopper.sh &
|
/usr/local/bin/random-stopper.sh &
|
||||||
|
@ -57,5 +46,6 @@ echo $! > /data/ipfs-cluster/random-killer-pid
|
||||||
/usr/local/bin/cluster-restart.sh &
|
/usr/local/bin/cluster-restart.sh &
|
||||||
kill -STOP $!
|
kill -STOP $!
|
||||||
echo $! > /data/ipfs-cluster/cluster-restart-pid
|
echo $! > /data/ipfs-cluster/cluster-restart-pid
|
||||||
|
|
||||||
echo "Daemons launched"
|
echo "Daemons launched"
|
||||||
exec tail -f /dev/null
|
exec tail -f /dev/null
|
||||||
|
|
Loading…
Reference in New Issue
Block a user