summaryrefslogtreecommitdiff
path: root/packaging/docker
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordberg.se>2015-04-01 22:14:13 +0200
committerLinus Nordberg <linus@nordberg.se>2015-04-03 16:48:59 +0200
commit352ade3dfb4890c40f17ebff2cfc55c21e8de20e (patch)
treecf5b10685c93a6c6471eda3e55e40d5b7ea60885 /packaging/docker
parent4860fff216892010a997547b0fa19cd4505cb804 (diff)
[Docker] Add docker support for merge nodes.
Also, run as a separate user in docker-dev.
Diffstat (limited to 'packaging/docker')
-rw-r--r--packaging/docker/catlfish-dev/Dockerfile32
-rw-r--r--packaging/docker/catlfish-dev/supervisord.conf1
-rw-r--r--packaging/docker/catlfish-merge/Dockerfile41
-rwxr-xr-xpackaging/docker/catlfish-merge/merge.sh27
-rw-r--r--packaging/docker/catlfish-merge/supervisord.conf6
5 files changed, 94 insertions, 13 deletions
diff --git a/packaging/docker/catlfish-dev/Dockerfile b/packaging/docker/catlfish-dev/Dockerfile
index b1192cf..11ebed5 100644
--- a/packaging/docker/catlfish-dev/Dockerfile
+++ b/packaging/docker/catlfish-dev/Dockerfile
@@ -1,9 +1,13 @@
# Catlfish expects to find its configuration in
# /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'. Example:
+# `-v' flag to `docker run'.
-# $ docker run -v /etc/catlfish:/usr/local/etc/catlfish catlfish
+# 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.
+
+# $ docker run -v /etc/catlfish:/usr/local/etc/catlfish:ro catlfish
FROM erlang
RUN apt-get update
@@ -35,25 +39,27 @@ RUN git clone https://git.nordu.net/plop.git
RUN make -C plop
RUN git clone https://git.nordu.net/catlfish.git
-RUN make -C catlfish all
-RUN make -C catlfish PREFIX=/usr/local release
+RUN make -C catlfish PREFIX=/usr/local all release
# Config dir and database dir are mounted from host using `-v' to
# 'docker run'.
-VOLUME /usr/local/catlfish
+VOLUME /usr/local/etc/catlfish
VOLUME /var/local/db/catlfish
-# Working directory is where catlfish.config is. We want to run in
+# Create a catlfish user.
+RUN groupadd --gid 147 catlfish
+RUN useradd --uid 147 --gid 147 catlfish
+
+# Working has to be where catlfish.config is. We want to run in
# /var/run/catlfish and not in /usr/local/etc/catlfish, so symlink.
-RUN mkdir -p /var/run/catlfish/erlang_log /var/run/catlfish/sasl_log
-RUN chgrp -R daemon /var/run/catlfish
-RUN chmod -R 775 /var/run/catlfish
-RUN ln -s /usr/local/etc/catlfish/catlfish.config /var/run/catlfish/
+RUN mkdir /var/run/catlfish
WORKDIR /var/run/catlfish
-
-# Don't run as root.
-USER daemon
+RUN mkdir erlang_log sasl_log supervisord_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/
+WORKDIR /var/run/catlfish
+USER catlfish
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"]
diff --git a/packaging/docker/catlfish-dev/supervisord.conf b/packaging/docker/catlfish-dev/supervisord.conf
index 8b317e0..f3493e5 100644
--- a/packaging/docker/catlfish-dev/supervisord.conf
+++ b/packaging/docker/catlfish-dev/supervisord.conf
@@ -2,4 +2,5 @@
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"
diff --git a/packaging/docker/catlfish-merge/Dockerfile b/packaging/docker/catlfish-merge/Dockerfile
new file mode 100644
index 0000000..cf6fa7a
--- /dev/null
+++ b/packaging/docker/catlfish-merge/Dockerfile
@@ -0,0 +1,41 @@
+# Docker file for catlfish merge.
+#
+# NOTE: The directory on the host system that's mounted at
+# /var/local/db/catlfish-merge in the container has to be writable by
+# a host user with uid 147.
+#
+# $ docker run \
+# -v /etc/catlfish:/usr/local/etc/catlfish:ro \
+# -v /var/local/db/catlfish-merge:/var/local/db/catlfish-merge \
+# catlfish-merge
+
+FROM base
+RUN apt-get update
+RUN echo 'debconf debconf/frontend select noninteractive' | debconf-set-selections
+RUN apt-get -y -q install git python-ecdsa python-yaml
+
+WORKDIR /usr/local/src
+RUN git clone https://git.nordu.net/catlfish.git
+
+# Config dir and database dir are mounted from host using `-v' to
+# 'docker run'.
+VOLUME /usr/local/etc/catlfish
+VOLUME /var/local/db/catlfish-merge
+
+# Copy merge.sh.
+RUN mkdir -p /usr/local/catlfish/bin
+ADD merge.sh /usr/local/catlfish/bin/
+
+# Create a catlfish user.
+RUN groupadd --gid 147 catlfish
+RUN useradd --uid 147 --gid 147 catlfish
+
+# We run from /var/run/catlfish.
+RUN mkdir -p /var/run/catlfish/supervisord_log
+RUN chown -R catlfish:catlfish /var/run/catlfish
+WORKDIR /var/run/catlfish
+
+# Run supervisord.
+ADD supervisord.conf /etc/supervisor/
+USER catlfish
+CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"]
diff --git a/packaging/docker/catlfish-merge/merge.sh b/packaging/docker/catlfish-merge/merge.sh
new file mode 100755
index 0000000..b3658cd
--- /dev/null
+++ b/packaging/docker/catlfish-merge/merge.sh
@@ -0,0 +1,27 @@
+#! /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
+
+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-merge/supervisord.conf b/packaging/docker/catlfish-merge/supervisord.conf
new file mode 100644
index 0000000..deaf308
--- /dev/null
+++ b/packaging/docker/catlfish-merge/supervisord.conf
@@ -0,0 +1,6 @@
+[supervisord]
+nodaemon=true
+
+[program:catlfish-merge]
+childlogdir=/var/run/catlfish
+command=/usr/local/catlfish/bin/merge.sh 300 1200 /var/local/db/catlfish-merge