#!/usr/bin/env bash

if ! docker swarm init | grep -q 'Error'
then
    docker swarm init
fi

cd $2
docker stack deploy -c docker-compose.yml traefik
cd ..

if docker network ls | grep -q 'traefik'
then
    cd $1
    docker stack deploy -c docker-compose.yml $1
else
    cd $1
    docker stack deploy -c docker-compose.yml $1
fi

cd $2
docker stack deploy -c docker-compose.yml traefik
cd ..