Browse Source

docker: add dockerfile and entrypoint script

This lets us easily spawn one or multiple Docker containers
running the current local cjdns code. The compiled binaries
as well as everything in tools/ will be copied to /usr/bin/.

    $ contrib/docker/run
    $ docker exec -it cjdns cjdnslog
    $ docker exec -it cjdns peerStats

For now, the image build is optimized for fast build times
instead of small image size.

The root Dockerfile enables automatic image builds by hub.docker.com.

The container's cjdroute.conf is persisted at and reused from
contrib/cjdns/cjdns[-<name>].

Note: under certain circumstances, /etc/cjdns won't be mounted and
thus config persistence is broken. See: https://github.com/docker/docker/issues/10595
Lars Gierth 8 years ago
parent
commit
65201059da
6 changed files with 71 additions and 0 deletions
  1. 9 0
      .dockerignore
  2. 1 0
      .gitignore
  3. 1 0
      Dockerfile
  4. 23 0
      contrib/docker/Dockerfile
  5. 14 0
      contrib/docker/entrypoint.sh
  6. 23 0
      contrib/docker/run

+ 9 - 0
.dockerignore

@@ -0,0 +1,9 @@
+Dockerfile
+.dockerignore
+build_*/
+cjdroute
+makekeys
+sybilsim
+randombytes
+privatetopublic
+publictoip6

+ 1 - 0
.gitignore

@@ -22,3 +22,4 @@
 .DS_Store
 /node_modules/jshint
 /node_modules/.bin
+/contrib/docker/cjdns*/

+ 1 - 0
Dockerfile

@@ -0,0 +1 @@
+contrib/docker/Dockerfile

+ 23 - 0
contrib/docker/Dockerfile

@@ -0,0 +1,23 @@
+FROM alpine:3.2
+MAINTAINER Lars Gierth <larsg@systemli.org>
+
+RUN apk add --update nodejs bash python git build-base linux-headers
+
+ADD . /src
+
+RUN adduser -D -h /etc/cjdns -u 1000 cjdns \
+    && rm -rf /src/build_* && /src/do \
+    && cp /src/cjdroute /usr/bin \
+    && cp -r /src/tools/* /usr/bin \
+    && cp /src/makekeys \
+          /src/privatetopublic \
+          /src/makekeys \
+          /src/randombytes \
+          /src/sybilsim /usr/bin \
+    && cp /src/contrib/docker/entrypoint.sh / \
+    && rm -rf /src /var/cache/apk/* \
+    && apk del --purge python build-base linux-headers
+
+VOLUME [ "/etc/cjdns" ]
+
+ENTRYPOINT [ "/entrypoint.sh" ]

+ 14 - 0
contrib/docker/entrypoint.sh

@@ -0,0 +1,14 @@
+#!/usr/bin/env bash
+
+set -e
+
+CONF_DIR="/etc/cjdns"
+
+if [ ! -f "$CONF_DIR/cjdroute.conf" ]; then
+  echo "generate $CONF_DIR/cjdroute.conf"
+  conf=$(cjdroute --genconf | cjdroute --cleanconf)
+  echo $conf > "$CONF_DIR/cjdroute.conf"
+fi
+
+cjdroute --nobg < "$CONF_DIR/cjdroute.conf"
+exit $?

+ 23 - 0
contrib/docker/run

@@ -0,0 +1,23 @@
+#!/usr/bin/env bash
+
+set -ex
+
+# Usage:
+#   contrib/docker/run [<name>]
+#   docker exec -it cjdns[-<name>] cjdnslog
+#   docker exec -it cjdns[-<name>] peerStats
+#   docker exec -it cjdns[-<name>] sessionState
+#   docker exec -it cjdns[-<name>] dumptable
+#   docker exec -it cjdns[-<name>] <any-command-from-tools/>
+#   cat contrib/docker/cjdns[-<name>]/cjdroute.conf
+
+# Location of cjdroute.conf within the container
+CONF_DIR="/etc/cjdns"
+
+[ "$1" = "" ] && name="cjdns" || name="cjdns-$1"
+
+docker build -f contrib/docker/Dockerfile -t $name .
+
+exec docker run -it --rm --name=$name \
+                --cap-add=NET_ADMIN --device=/dev/net/tun \
+                --volume="$(pwd)/contrib/docker/$name:$CONF_DIR" $name