nopaque/dind_swarm_setup.sh

34 lines
1.1 KiB
Bash
Raw Normal View History

2019-11-26 09:57:01 +00:00
#!/bin/bash
SWARM_MANAGER_IP=""
SWARM_WORKER_NUMBER=4
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
2019-11-26 10:39:27 +00:00
echo "Leave possible swarm..."
docker swarm leave --force > /dev/null 2>&1
2019-11-26 09:57:01 +00:00
2019-11-26 10:43:08 +00:00
echo "Start storage container"
2019-11-26 09:57:01 +00:00
docker-compose --file dind_swarm.yml up --detach storage
sleep 3
2019-11-26 10:43:08 +00:00
2019-11-26 10:39:27 +00:00
echo "Mount network storage to host system..."
2019-11-26 09:57:01 +00:00
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
2019-11-26 10:43:08 +00:00
echo "Start worker service(s)"
2019-11-26 10:39:27 +00:00
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)
2019-11-26 09:57:01 +00:00
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