forked from toncenter/ton-index-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
swarm-deploy.sh
executable file
·101 lines (88 loc) · 2.31 KB
/
swarm-deploy.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
set -e
# parse args
DEPLOY_DATABASE=0
MIGRATE=0
BUILD=1
DEPLOY_API=1
BUILD_ARGS=
POSITIONAL_ARGS=()
function usage() {
echo 'Supported argumets:'
echo ' -d --deploy-db Deploy docker database'
echo ' -m --migrate Run database migration'
echo ' --no-build Do not build docker images'
echo ' --no-build-cache No build cache'
echo ' --no-api Do not deploy API'
echo ' -h --help Show this message'
exit
}
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
usage
exit 1
;;
-d|--deploy-db)
DEPLOY_DATABASE=1
shift
;;
-m|--migrate)
MIGRATE=1
shift
;;
--no-build)
BUILD=0
shift
;;
--no-build-cache)
BUILD_ARGS=--no-cache
shift
;;
--no-api)
DEPLOY_API=0
shift
;;
-*|--*)
echo "Unknown option $1"
exit 1
;;
*)
POSITIONAL_ARGS+=("$1") # save positional arg
shift # past argument
;;
esac
done
set -- "${POSITIONAL_ARGS[@]}"
# toncenter env: testnet, mainnet, stage
export TONCENTER_ENV=${1:-mainnet}
STACK_NAME="${TONCENTER_ENV}-ton-index-go"
echo "Deploying stack: ${STACK_NAME}"
if [ -f ".env.${TONCENTER_ENV}" ]; then
echo "Found env for ${TONCENTER_ENV}"
ENV_FILE=".env.${TONCENTER_ENV}"
elif [ -f ".env" ]; then
echo "Found default .env"
ENV_FILE=".env"
else
echo "Please provide env file"
exit 1
fi
# load environment variables
if [ ! -z "${ENV_FILE}" ]; then
set -a; source ${ENV_FILE}; set +a
fi
# check global network
NETWORK_ID=$(docker network ls -f "name=toncenter-global" -q)
if [[ -z "$NETWORK_ID" ]]; then
echo "Creating toncenter-global network"
NETWORK_ID=$(docker network create --attachable --driver=overlay toncenter-global)
fi
echo "Network ID of toncenter-global: $NETWORK_ID"
# build image
if [[ $BUILD -eq "1" ]]; then
docker compose -f docker-compose.yaml build $BUILD_ARGS
docker compose -f docker-compose.yaml push
fi
echo "Deploying API"
docker stack deploy --with-registry-auth -c docker-compose.yaml ${STACK_NAME}