From cf6e64bf94677092ef94a6f4ed7c1391dcd43f23 Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Mon, 13 Apr 2015 14:19:38 +0200 Subject: Run all types of nodes from the same docker image. --- packaging/docker/catlfish-dev/Dockerfile | 27 ++++++++++++++++-------- packaging/docker/catlfish-dev/merge.sh | 29 ++++++++++++++++++++++++++ packaging/docker/catlfish-dev/start.sh | 22 +++++++++++++++++++ packaging/docker/catlfish-dev/supervisord.conf | 2 +- 4 files changed, 70 insertions(+), 10 deletions(-) create mode 100755 packaging/docker/catlfish-dev/merge.sh create mode 100755 packaging/docker/catlfish-dev/start.sh (limited to 'packaging/docker/catlfish-dev') diff --git a/packaging/docker/catlfish-dev/Dockerfile b/packaging/docker/catlfish-dev/Dockerfile index 11ebed5..241c58d 100644 --- a/packaging/docker/catlfish-dev/Dockerfile +++ b/packaging/docker/catlfish-dev/Dockerfile @@ -2,18 +2,29 @@ # /usr/local/etc/catlfish/catlfish.config so mounting # /usr/local/etc/catlfish is recommended. This can be done using the # `-v' flag to `docker run'. - +# # NOTE: The directory on the host system that's mounted at # /var/local/db/catlfish in the container has to be writable by a host # user with uid 147. - +# +# Example, running a frontend node: +# $ docker run -v /etc/catlfish:/usr/local/etc/catlfish:ro catlfish +# frontend /usr/local/catlfish +# +# Example, running a merge node: # $ docker run -v /etc/catlfish:/usr/local/etc/catlfish:ro catlfish +# merge /usr/local/catlfish /var/local/db/catlfish-merge FROM erlang RUN apt-get update RUN echo 'debconf debconf/frontend select noninteractive' | debconf-set-selections + +# For building. RUN apt-get -y -q install gcc git make curl +# For merge. +RUN apt-get -y -q install git python-ecdsa python-yaml + # Build dependencies in /usr/local/src. WORKDIR /usr/local/src @@ -41,10 +52,8 @@ RUN make -C plop RUN git clone https://git.nordu.net/catlfish.git RUN make -C catlfish PREFIX=/usr/local all release -# Config dir and database dir are mounted from host using `-v' to -# 'docker run'. +# Config dir is mounted from host using `-v' to 'docker run'. VOLUME /usr/local/etc/catlfish -VOLUME /var/local/db/catlfish # Create a catlfish user. RUN groupadd --gid 147 catlfish @@ -54,12 +63,12 @@ RUN useradd --uid 147 --gid 147 catlfish # /var/run/catlfish and not in /usr/local/etc/catlfish, so symlink. RUN mkdir /var/run/catlfish WORKDIR /var/run/catlfish -RUN mkdir erlang_log sasl_log supervisord_log +RUN mkdir erlang_log sasl_log merge_log RUN chown -R catlfish:catlfish /var/run/catlfish RUN ln -s /usr/local/etc/catlfish/catlfish.config /var/run/catlfish/ -# Run supervisord. -ADD supervisord.conf /etc/supervisor/ +ADD merge.sh /usr/local/catlfish/ +ADD start.sh /var/run/catlfish/ WORKDIR /var/run/catlfish USER catlfish -CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"] +ENTRYPOINT ["/var/run/catlfish/start.sh"] diff --git a/packaging/docker/catlfish-dev/merge.sh b/packaging/docker/catlfish-dev/merge.sh new file mode 100755 index 0000000..304d8a4 --- /dev/null +++ b/packaging/docker/catlfish-dev/merge.sh @@ -0,0 +1,29 @@ +#! /bin/sh + +# Default intervals +# - 5m before first merge +# - 20m between subsequent merges +S1=300; [ -n "$1" ] && S1=$1 +S2=1200; [ -n "$2" ] && S2=$2 + +DBDIR="$3" + +[ -d $DBDIR ] || mkdir $DBDIR +[ -d $DBDIR/chains ] || mkdir $DBDIR/chains +[ -e $DBDIR/logorder ] || touch $DBDIR/logorder + +echo "merge: ERL_LIBS: $ERL_LIBS" + +date +echo "merge: waiting $(expr $S1 / 60)m$(expr $S1 % 60)s before merging for the first time" +sleep $S1 + +while true; do + echo "$0: merging" + date + python /usr/local/src/catlfish/tools/merge.py \ + --config /usr/local/etc/catlfish/system.cfg \ + --localconfig /usr/local/etc/catlfish/merge.cfg + echo "merge: waiting $(expr $S2 / 60)m$(expr $S2 % 60)s before merging again" + sleep $S2 +done diff --git a/packaging/docker/catlfish-dev/start.sh b/packaging/docker/catlfish-dev/start.sh new file mode 100755 index 0000000..8b3697d --- /dev/null +++ b/packaging/docker/catlfish-dev/start.sh @@ -0,0 +1,22 @@ +#! /bin/sh + +role=$1; [ -n "$1" ] && shift +erlbase=$1; [ -n "$1" ] && shift +database=$1; [ -n "$1" ] && shift + +case $role in + frontend|storage|signing) + $erlbase/bin/run_erl \ + /var/run/catlfish/ \ + /var/run/catlfish/erlang_log/ \ + "exec $erlbase/bin/erl -config catlfish" + ;; + merge) + ERL_LIBS=$erlbase/lib/catlfish-0.6.0-dev.ez/catlfish-0.6.0-dev + ERL_LIBS=$ERL_LIBS:$erlbase/lib/lager-2.1.1.ez/lager-2.1.1 + export ERL_LIBS + $erlbase/merge.sh 60 3600 $database > merge_log/stdout 2> merge_log/stderr + ;; + *) + echo "catlfish: unknown role: $role" +esac diff --git a/packaging/docker/catlfish-dev/supervisord.conf b/packaging/docker/catlfish-dev/supervisord.conf index f3493e5..8eda9b9 100644 --- a/packaging/docker/catlfish-dev/supervisord.conf +++ b/packaging/docker/catlfish-dev/supervisord.conf @@ -3,4 +3,4 @@ nodaemon=true [program:catlfish] childlogdir=/var/run/catlfish/supervisord_log -command=/usr/local/catlfish/bin/run_erl /var/run/catlfish/ /var/run/catlfish/erlang_log/ "exec /usr/local/catlfish/bin/erl -config catlfish" +command=/usr/local/catlfish/start.sh -- cgit v1.1