-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeploy_docker.sh
executable file
·60 lines (52 loc) · 1.99 KB
/
deploy_docker.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
#!/bin/bash
i=1
VM_ID="100$i"
VM_IP="10.33.0.1$i"
if [ "$(qm list | grep $VM_ID | wc -l)" -eq 0 ]; then
qm clone 9000 $VM_ID \
--name "docker$i" \
--description "Docker $i VM created by bonnetn" \
--pool dockerswarm
qm set $VM_ID --net0 model=virtio,bridge=vmbr1337
qm set $VM_ID --ipconfig0 ip=${VM_IP}/16,gw=10.33.0.1
qm set $VM_ID --nameserver '157.159.10.12'
qm set $VM_ID --ciuser deploy
qm set $VM_ID --sshkey ~/.ssh/id_rsa.pub
qm set $VM_ID --agent 1
qm set $VM_ID --autostart 1
qm start $VM_ID
fi
read -p "Press enter to continue when the VM is started"
scp -o StrictHostKeyChecking=no .provision_vm.sh deploy@${VM_IP}:./provision.sh
ssh -o StrictHostKeyChecking=no deploy@$VM_IP bash provision.sh
ssh -o StrictHostKeyChecking=no deploy@$VM_IP "sudo docker swarm init --advertise-addr $VM_IP" > join_cluster.cmd
cat join_cluster.cmd | head -n 5 | tail -n 1 | tee join_cluster.sh
for i in {2..5}; do
VM_ID="100$i"
VM_IP="10.33.0.1$i"
if [ "$(qm list | grep $VM_ID | wc -l)" -eq 0 ]; then
qm clone 9000 $VM_ID \
--name "docker$i" \
--description "Docker $i VM created by bonnetn" \
--pool dockerswarm
qm set $VM_ID --net0 model=virtio,bridge=vmbr1337
qm set $VM_ID --ipconfig0 ip=${VM_IP}/16,gw=10.33.0.1
qm set $VM_ID --nameserver '157.159.10.12'
qm set $VM_ID --ciuser deploy
qm set $VM_ID --sshkey ~/.ssh/id_rsa.pub
qm set $VM_ID --agent 1
qm set $VM_ID --autostart 1
qm start $VM_ID
fi
done
read -p "Press enter to continue when the worker VMs are started"
for i in {2..5}; do
VM_IP="10.33.0.1$i"
scp -o StrictHostKeyChecking=no .provision_vm.sh deploy@${VM_IP}:./provision.sh
ssh -o StrictHostKeyChecking=no deploy@$VM_IP bash provision.sh
scp -o StrictHostKeyChecking=no join_cluster.sh deploy@${VM_IP}:./
ssh -o StrictHostKeyChecking=no deploy@$VM_IP sudo bash join_cluster.sh
done
VM_IP="10.33.0.11"
scp -o StrictHostKeyChecking=no .promote_everyone.sh deploy@${VM_IP}:./promote.sh
ssh -o StrictHostKeyChecking=no deploy@$VM_IP sudo bash promote.sh