From 8a3e5073a320471e2b7772ac7f37f8330c6a531f Mon Sep 17 00:00:00 2001
From: Patrick Jentsch
Date: Tue, 26 Nov 2019 10:57:01 +0100
Subject: [PATCH 1/3] Add dind_swarm setup and config.
---
dind_swarm.yml | 26 ++++++++++++++++++++++++++
setup_dind_swarm.sh | 34 ++++++++++++++++++++++++++++++++++
2 files changed, 60 insertions(+)
create mode 100644 dind_swarm.yml
create mode 100755 setup_dind_swarm.sh
diff --git a/dind_swarm.yml b/dind_swarm.yml
new file mode 100644
index 00000000..8dbc831e
--- /dev/null
+++ b/dind_swarm.yml
@@ -0,0 +1,26 @@
+version: '3'
+
+services:
+ storage:
+ command: ["-p", "-s", "opaque_storage;/srv/opaque/storage;no;no;no;opaque", "-u", "opaque;opaque"]
+ image: dperson/samba:latest
+ ports:
+ - 139:139
+ - 445:445
+ restart: on-failure
+ volumes:
+ - /srv/opaque/storage:/srv/opaque/storage
+ worker:
+ image: docker:dind
+ ports:
+ - 2375
+ privileged: true
+ restart: on-failure
+ volumes:
+ - /mnt/opaque:/mnt/opaque
+ viz:
+ image: dockersamples/visualizer:latest
+ ports:
+ - 8080:8080
+ volumes:
+ - /var/run/docker.sock:/var/run/docker.sock
diff --git a/setup_dind_swarm.sh b/setup_dind_swarm.sh
new file mode 100755
index 00000000..645accdc
--- /dev/null
+++ b/setup_dind_swarm.sh
@@ -0,0 +1,34 @@
+#!/bin/bash
+
+OPAQUE_STORAGE_MOUNT_DIRECTORY="/mnt/opaque" # Don't change this variable, unless you know what you are doing!
+SWARM_MANAGER_IP=""
+SWARM_WORKER_NUMBER=4
+SWARM_WORKER_TOKEN=""
+
+if [ -z ${SWARM_MANAGER_IP} ]; then
+ # See https://stackoverflow.com/a/25851186
+ SWARM_MANAGER_IP=$(ip route get 1 | awk '{print $(NF-2);exit}')
+fi
+
+if [ -z ${SWARM_WORKER_TOKEN} ]; then
+ docker swarm leave --force > /dev/null 2>&1
+ docker swarm init --advertise-addr ${SWARM_MANAGER_IP} > /dev/null 2>&1
+ SWARM_WORKER_TOKEN=$(docker swarm join-token -q worker)
+fi
+
+docker-compose --file dind_swarm.yml up --detach storage
+sleep 3
+echo "Mounting network storage to host system..."
+sudo mkdir -p /mnt/opaque
+sudo mount -t cifs -o gid=${USER},password=opaque,uid=${USER},user=opaque,vers=3.0 //localhost/opaque_storage /mnt/opaque
+echo "Done"
+docker-compose --file dind_swarm.yml up --detach --scale worker=${SWARM_WORKER_NUMBER} worker
+sleep 10
+echo "Add workers to swarm"
+
+for i in $(seq 1 ${SWARM_WORKER_NUMBER}); do
+ docker-compose --file dind_swarm.yml exec --index=${i} worker docker swarm join --token ${SWARM_WORKER_TOKEN} ${SWARM_MANAGER_IP}:2377
+done
+
+
+docker-compose --file dind_swarm.yml up --detach viz
From 3d7ebfa1dd568b58d2392a87d9cba98ee92e0a14 Mon Sep 17 00:00:00 2001
From: Patrick Jentsch
Date: Tue, 26 Nov 2019 11:39:27 +0100
Subject: [PATCH 2/3] Enhancements
---
setup_dind_swarm.sh => dind_swarm_setup.sh | 25 +++++-----
docker_stack_deploy.yml | 56 ++++++++++++++++++++++
2 files changed, 67 insertions(+), 14 deletions(-)
rename setup_dind_swarm.sh => dind_swarm_setup.sh (65%)
create mode 100644 docker_stack_deploy.yml
diff --git a/setup_dind_swarm.sh b/dind_swarm_setup.sh
similarity index 65%
rename from setup_dind_swarm.sh
rename to dind_swarm_setup.sh
index 645accdc..f8f75943 100755
--- a/setup_dind_swarm.sh
+++ b/dind_swarm_setup.sh
@@ -3,32 +3,29 @@
OPAQUE_STORAGE_MOUNT_DIRECTORY="/mnt/opaque" # Don't change this variable, unless you know what you are doing!
SWARM_MANAGER_IP=""
SWARM_WORKER_NUMBER=4
-SWARM_WORKER_TOKEN=""
if [ -z ${SWARM_MANAGER_IP} ]; then
# See https://stackoverflow.com/a/25851186
SWARM_MANAGER_IP=$(ip route get 1 | awk '{print $(NF-2);exit}')
fi
-if [ -z ${SWARM_WORKER_TOKEN} ]; then
- docker swarm leave --force > /dev/null 2>&1
- docker swarm init --advertise-addr ${SWARM_MANAGER_IP} > /dev/null 2>&1
- SWARM_WORKER_TOKEN=$(docker swarm join-token -q worker)
-fi
+echo "Leave possible swarm..."
+docker swarm leave --force > /dev/null 2>&1
docker-compose --file dind_swarm.yml up --detach storage
sleep 3
-echo "Mounting network storage to host system..."
+echo "Mount network storage to host system..."
sudo mkdir -p /mnt/opaque
sudo mount -t cifs -o gid=${USER},password=opaque,uid=${USER},user=opaque,vers=3.0 //localhost/opaque_storage /mnt/opaque
-echo "Done"
-docker-compose --file dind_swarm.yml up --detach --scale worker=${SWARM_WORKER_NUMBER} worker
-sleep 10
-echo "Add workers to swarm"
+docker-compose --file dind_swarm.yml up --detach --scale worker=${SWARM_WORKER_NUMBER} worker viz
+sleep 5
+echo "Init Docker swarm..."
+docker swarm init --advertise-addr ${SWARM_MANAGER_IP} > /dev/null 2>&1
+
+
+echo "Join workers to swarm..."
+SWARM_WORKER_TOKEN=$(docker swarm join-token -q worker)
for i in $(seq 1 ${SWARM_WORKER_NUMBER}); do
docker-compose --file dind_swarm.yml exec --index=${i} worker docker swarm join --token ${SWARM_WORKER_TOKEN} ${SWARM_MANAGER_IP}:2377
done
-
-
-docker-compose --file dind_swarm.yml up --detach viz
diff --git a/docker_stack_deploy.yml b/docker_stack_deploy.yml
new file mode 100644
index 00000000..2fc82642
--- /dev/null
+++ b/docker_stack_deploy.yml
@@ -0,0 +1,56 @@
+version: '3'
+
+services:
+ web:
+ depends_on:
+ - db
+ - redis
+ deploy:
+ placement:
+ constraints:
+ - node.role == manager
+ env_file:
+ - db.env
+ - web.env
+ image: gitlab.ub.uni-bielefeld.de:4567/sfb1288inf/opaque:development
+ ports:
+ - 5000:5000
+ volumes:
+ - storage:/mnt/opaque
+ daemon:
+ depends_on:
+ - db
+ deploy:
+ placement:
+ constraints:
+ - node.role == manager
+ env_file:
+ - db.env
+ - web.env
+ image: gitlab.ub.uni-bielefeld.de:4567/sfb1288inf/opaque_daemon:latest
+ volumes:
+ - storage:/mnt/opaque
+ - $HOME/.docker/config.json:/home/opaque_daemon/.docker/config.json
+ db:
+ deploy:
+ placement:
+ constraints:
+ - node.role == manager
+ env_file: db.env
+ image: postgres:11-alpine
+ volumes:
+ - /srv/opaque/database:/var/lib/postgresql/data
+ redis:
+ deploy:
+ placement:
+ constraints:
+ - node.role == manager
+ image: redis:alpine
+
+volumes:
+ storage:
+ driver: local
+ driver_opts:
+ device: "//127.0.0.1/opaque_storage"
+ o: "gid=1000,password=opaque,uid=1000,username=opaque"
+ type: cifs
From f588cd743fab0724f2c97be648381a2f6fe60122 Mon Sep 17 00:00:00 2001
From: Patrick Jentsch
Date: Tue, 26 Nov 2019 11:43:08 +0100
Subject: [PATCH 3/3] Better output on command line
---
dind_swarm_setup.sh | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/dind_swarm_setup.sh b/dind_swarm_setup.sh
index f8f75943..4460f7e3 100755
--- a/dind_swarm_setup.sh
+++ b/dind_swarm_setup.sh
@@ -1,6 +1,5 @@
#!/bin/bash
-OPAQUE_STORAGE_MOUNT_DIRECTORY="/mnt/opaque" # Don't change this variable, unless you know what you are doing!
SWARM_MANAGER_IP=""
SWARM_WORKER_NUMBER=4
@@ -12,18 +11,21 @@ fi
echo "Leave possible swarm..."
docker swarm leave --force > /dev/null 2>&1
+echo "Start storage container"
docker-compose --file dind_swarm.yml up --detach storage
sleep 3
+
echo "Mount network storage to host system..."
sudo mkdir -p /mnt/opaque
sudo mount -t cifs -o gid=${USER},password=opaque,uid=${USER},user=opaque,vers=3.0 //localhost/opaque_storage /mnt/opaque
+
+echo "Start worker service(s)"
docker-compose --file dind_swarm.yml up --detach --scale worker=${SWARM_WORKER_NUMBER} worker viz
sleep 5
echo "Init Docker swarm..."
docker swarm init --advertise-addr ${SWARM_MANAGER_IP} > /dev/null 2>&1
-
echo "Join workers to swarm..."
SWARM_WORKER_TOKEN=$(docker swarm join-token -q worker)
for i in $(seq 1 ${SWARM_WORKER_NUMBER}); do