-
Notifications
You must be signed in to change notification settings - Fork 32
/
swarm-deploy.sh
executable file
·125 lines (109 loc) · 3.04 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/bash
set -e
# parse args
DEPLOY_DATABASE=0
MIGRATE=0
BUILD=1
DEPLOY_API=0
DEPLOY_EVENTS=0
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 ' --deploy-api Deploy API'
echo ' --deploy-events Deploy event classfier'
echo ' -h --help Show this message'
exit
}
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
usage
exit 1
;;
-d|--db)
DEPLOY_DATABASE=1
shift
;;
-m|--migrate)
MIGRATE=1
shift
;;
--no-build)
BUILD=0
shift
;;
--no-build-cache)
BUILD_ARGS=--no-cache
shift
;;
--api)
DEPLOY_API=1
shift
;;
--events)
DEPLOY_EVENTS=1
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}-indexer-cpp"
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"
# deploy database
if [[ $DEPLOY_DATABASE -eq "1" ]]; then
echo "Deploying Docker database"
docker stack deploy -c docker-compose.database.yaml ${STACK_NAME}
fi
# build image
if [[ $BUILD -eq "1" ]]; then
docker compose -f docker-compose.api.yaml -f docker-compose.events.yaml build $BUILD_ARGS
docker compose -f docker-compose.api.yaml -f docker-compose.events.yaml push
fi
if [[ $MIGRATE -eq "1" ]]; then
echo "Running migrations"
docker stack deploy --with-registry-auth -c docker-compose.alembic.yaml ${STACK_NAME}
fi
if [[ $DEPLOY_API -eq "1" ]]; then
echo "Deploying API"
docker stack deploy --with-registry-auth -c docker-compose.api.yaml ${STACK_NAME}
fi
if [[ $DEPLOY_EVENTS -eq "1" ]]; then
echo "Deploying event classifier"
docker stack deploy --with-registry-auth -c docker-compose.events.yaml ${STACK_NAME}
fi