0
0
mirror of https://github.com/cjdelisle/cjdns synced 2025-10-05 16:22:54 +02:00

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
This commit is contained in:
Lars Gierth
2015-10-02 02:41:57 +02:00
parent ed561b4a85
commit 65201059da
6 changed files with 71 additions and 0 deletions

9
.dockerignore Normal file
View File

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

1
.gitignore vendored
View File

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

1
Dockerfile Symbolic link
View File

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

23
contrib/docker/Dockerfile Normal file
View File

@@ -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
contrib/docker/entrypoint.sh Executable file
View File

@@ -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
contrib/docker/run Executable file
View File

@@ -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