-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdeploy.sh
55 lines (46 loc) · 1.55 KB
/
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
#!/bin/bash
set -e
read -p "Linode Token: " LINODE_TOKEN
# LINODE_TOKEN=...
LINODE_ROOT_PASSWORD=$(openssl rand -base64 32); echo Password for root: $LINODE_ROOT_PASSWORD
LINODE_REGION=ap-south
create_node() {
local name=$1
docker-machine create \
-d linode \
--linode-label=$name \
--linode-instance-type=g6-nanode-1 \
--linode-image=linode/ubuntu20.04 \
--linode-region=$LINODE_REGION \
--linode-token=$LINODE_TOKEN \
--linode-root-pass=$LINODE_ROOT_PASSWORD \
--linode-create-private-ip \
$name
}
get_private_ip() {
local name=$1
docker-machine inspect -f '{{.Driver.PrivateIPAddress}}' $name
}
init_swarm_master() {
local name=$1
local ip=$(get_private_ip $name)
docker-machine ssh $name "docker swarm init --advertise-addr ${ip}"
}
init_swarm_worker() {
local master_name=$1
local worker_name=$2
local master_addr=$(get_private_ip $master_name):2377
local join_token=$(docker-machine ssh $master_name "docker swarm join-token worker -q")
docker-machine ssh $worker_name "docker swarm join --token=${join_token} ${master_addr}"
}
# create master and worker node
create_node swarm-master-01 & create_node swarm-worker-01
# init swarm master
init_swarm_master swarm-master-01
# init swarm worker
init_swarm_worker swarm-master-01 swarm-worker-01
# install the docker-volume-linode plugin on each node
for NODE in swarm-master-01 swarm-worker-01; do
eval $(docker-machine env $NODE)
docker plugin install --alias linode linode/docker-volume-linode:latest linode-token=$LINODE_TOKEN
done