Update dind swarm script.

This commit is contained in:
Patrick Jentsch 2020-01-03 10:27:55 +01:00
parent fe084e87bd
commit 852c8a22a6

View File

@ -1,5 +1,7 @@
#!/bin/bash #!/bin/bash
ECHO_COLOR="\033[0;34m"
ECHO_COLOR_END="\033[0m"
SWARM_MANAGER_IP="" SWARM_MANAGER_IP=""
SWARM_WORKER_NUMBER=4 SWARM_WORKER_NUMBER=4
@ -7,30 +9,33 @@ if [ -z ${SWARM_MANAGER_IP} ]; then
# See https://stackoverflow.com/a/25851186 # See https://stackoverflow.com/a/25851186
SWARM_MANAGER_IP=$(ip route get 1 | awk '{print $(NF-2);exit}') SWARM_MANAGER_IP=$(ip route get 1 | awk '{print $(NF-2);exit}')
fi fi
echo -e "${ECHO_COLOR}Leave possible swarm and down all services...${ECHO_COLOR_END}"
echo "Leave possible swarm and down all services..."
docker swarm leave --force docker swarm leave --force
docker-compose --file dind_swarm.yml down docker-compose --file dind_swarm.yml down
echo "Start storage container" echo -e "${ECHO_COLOR}Start storage container...${ECHO_COLOR_END}"
docker-compose --file dind_swarm.yml up --detach storage docker-compose --file dind_swarm.yml up --detach storage
sleep 3 sleep 3
echo "Mount network storage to host system..." echo -e "${ECHO_COLOR}Mount network storage to host system...${ECHO_COLOR_END}"
sudo mkdir -p /mnt/nopaque if [ ! -d "/mnt/nopaque" ]; then
sudo umount /mnt/nopaque sudo mkdir -p /mnt/nopaque
sudo mount -t cifs -o gid=${USER},password=nopaque,uid=${USER},user=nopaque,vers=3.0 //localhost/storage.nopaque /mnt/nopaque fi
if mountpoint -q /mnt/nopaque; then
sudo umount --force /mnt/nopaque
fi
sudo mount --types cifs --options gid=${USER},password=nopaque,uid=${USER},user=nopaque,vers=3.0 //localhost/storage.nopaque /mnt/nopaque
echo "Start worker service(s)" echo -e "${ECHO_COLOR}Start worker service(s)...${ECHO_COLOR_END}"
docker-compose --file dind_swarm.yml up --detach --scale worker=${SWARM_WORKER_NUMBER} worker viz docker-compose --file dind_swarm.yml up --detach --scale worker=${SWARM_WORKER_NUMBER} worker viz
sleep 7 sleep 7
echo "Init Docker swarm..." echo -e "${ECHO_COLOR}Init Docker swarm...${ECHO_COLOR_END}"
docker swarm init --advertise-addr ${SWARM_MANAGER_IP} docker swarm init --advertise-addr ${SWARM_MANAGER_IP} > /dev/null
echo "Add workers to swarm..." echo -e "${ECHO_COLOR}Add workers to swarm...${ECHO_COLOR_END}"
SWARM_WORKER_TOKEN=$(docker swarm join-token -q worker) SWARM_WORKER_TOKEN=$(docker swarm join-token -q worker)
for i in $(seq 1 ${SWARM_WORKER_NUMBER}); do for i in $(seq 1 ${SWARM_WORKER_NUMBER}); do
echo -n "[opaque_worker_${i}]: " echo -n "[worker_${i}]: "
docker-compose --file dind_swarm.yml exec --index=${i} worker docker swarm join --token ${SWARM_WORKER_TOKEN} ${SWARM_MANAGER_IP}:2377 docker-compose --file dind_swarm.yml exec --index=${i} worker docker swarm join --token ${SWARM_WORKER_TOKEN} ${SWARM_MANAGER_IP}:2377
done done