-
Notifications
You must be signed in to change notification settings - Fork 153
/
Copy pathvm-deploy.sh
executable file
·207 lines (169 loc) · 4.94 KB
/
vm-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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#!/bin/sh
set -e
VERSION="latest"
DOMAIN="localhost"
CONFDIR="/etc/convoy"
COMPOSECONFDIR="$CONFDIR/compose"
DATADIR="/var/convoy/data"
# Read Convoy version
read_version() {
echo
echo "What version of Convoy would you like to install? (We default to the latest)"
echo "You can check out available versions here: https://github.com/frain-dev/convoy/releases"
local version=""
read -p "Version: " version
if [ -z "$version" ]
then
echo "Using default and installing $VERSION"
else
export VERSION=$version
echo "Using provided version $VERSION"
fi
}
# Ask if we should generate tls or not?
should_setup_tls() {
echo
while true; do
echo "Should we setup a TLS certificate for you using Let's Encrypt?"
echo "Select no if you are using this internally and Convoy will not be reachable from the intenet."
read -p "TLS (y/n): " yn
case $yn in
[Yy]* ) export USE_SELF_SIGNED_CERT=0; break ;;
[Nn]* ) export USE_SELF_SIGNED_CERT=1; break ;;
* ) echo "Please answer yes or no." ;;
esac
done
}
# Get domain from user.
get_domain_name() {
echo
read -p "Domain: " DOMAIN
export DOMAIN=$DOMAIN
echo "We will set up certs for https://$DOMAIN"
}
# Grant installer sudo access
get_sudo_access() {
echo
echo "We will need sudo access so the next question is for you to give us superuser access"
echo "Please enter your sudo password now:"
sudo echo ""
}
# Stop any running Convoy cluster.
stop_containers() {
sudo -E docker-compose -f docker-compose.yml stop &> /dev/null || true
}
# Installer grabs all necessary dependencies.
get_dependencies() {
echo
echo "Grabbing latest apt caches"
sudo apt install -y apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo -E apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"
sudo apt update
sudo apt-cache policy docker-ce
sudo apt install -y docker-ce git jq
# setup docker-compose
echo "Setting up Docker Compose"
sudo curl -L "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)" \
-o /usr/local/bin/docker-compose || true
sudo chmod +x /usr/local/bin/docker-compose
# enable docker without sudo
sudo usermod -aG docker "${USER}"
}
# clone convoy repository
install_convoy() {
echo
echo "Installing Convoy from Github"
git clone https://github.com/frain-dev/convoy.git &> /dev/null || true
cd convoy
git pull
cd ..
}
# This enables this script to be backward compatible with previous scripts.
prepare_directories() {
echo
echo "Preparing configuration directories ..."
mkdir -p $CONFDIR
mkdir -p $DATADIR
mkdir -p $COMPOSECONFDIR
}
copy_configurations() {
echo
cp convoy/configs/docker-compose.templ.yml $CONFDIR
cp convoy/configs/convoy.templ.json $CONFDIR
cp convoy/configs/caddyfile $CONFDIR
cd $CONFDIR
}
# rewrite convoy.json, caddyfile & docker-compose
write_configurations() {
# rewrite caddyfile
rm -f caddyfile
envsubst > caddyfile <<EOF
$DOMAIN, :80, :443 {
$TLS_BLOCK
reverse_proxy http://web:5005
}
EOF
# rewrite convoy.json
echo "Setting up convoy.json ..."
echo "$( jq --arg domain "${DOMAIN}" '.host = $domain | .environment = "production"' convoy.templ.json )" > convoy.json
rm convoy.templ.json
echo "convoy.json ready"
echo
# rewrite docker compose
envsubst < docker-compose.templ.yml > docker-compose.yml
rm docker-compose.templ.yml
}
# start system
start_containers() {
echo
echo "Starting containers..."
sudo -E docker-compose -f docker-compose.yml up -d
}
# check if the server is ready to start receiving requests
check_if_containers_are_up() {
echo
echo "We will need to wait ~5-10 minutes for things to settle down and TLS certs to be issued"
echo
echo "⏳ Waiting for Convoy web to boot (this will take a few minutes)"
bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:5005/health)" != "200" ]]; do sleep 5; done'
echo "⌛️ Convoy looks up!"
echo
echo "🎉🎉🎉 Done! 🎉🎉🎉"
echo
echo "To stop the stack run 'docker-compose stop'"
echo "To start the stack again run 'docker-compose start'"
echo "If you have any issues at all delete everything in this directory and run the curl command again"
echo
echo "Convoy will be up at the location you provided!"
echo "https://${DOMAIN}"
echo
}
start() {
echo "Welcome to the single instance Convoy installer"
echo
echo "⚠️ You really need 4gb or more of memory to run this stack ⚠️ "
# Ask for version
read_version
# Collect domain name
get_domain_name
# Should we setup TLS?
should_setup_tls
# Update apt caches
get_dependencies
# Install Convoy
install_convoy
# preprare directories
prepare_directories
# copy configurations
copy_configurations
# setup configuration
write_configurations
# stop previously running containers
stop_containers
# start containers
start_containers
# check if services are up
check_if_containers_are_up
}
start