-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathfabfile.py
117 lines (102 loc) · 3.93 KB
/
fabfile.py
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
from fabric import Connection, Config, task
import getpass
# Hosts to run the commands on
OLD_HOSTS = ["Carbon"]
NEW_DOCKER = ["Neon"]
HOSTS = ["Oxygen", "Fluorine", "Neon", "wolf"]
# Name of the git repository
GIT_REPO = 'nginx-load-balancer'
# Path of the directory
DIR = '/home/projects/%s/docker' % (GIT_REPO)
sudo_pass = getpass.getpass("Enter your sudo password: ")
@task()
def deploy_and_reload(c):
"Runs 'git pull' and reloads Nginx"
for host in HOSTS:
print('\n\n*** CONNECTING TO: %s' % (host))
config = Config(overrides={'sudo': {'password': sudo_pass}})
if host in OLD_HOSTS:
c = Connection(host, config=config, connect_kwargs={'disabled_algorithms': {'pubkeys': ['rsa-sha2-256', 'rsa-sha2-512']}})
else:
c = Connection(host, config=config)
c.run(
'cd %s && git pull [email protected]:openstate/%s.git' % (
DIR,
GIT_REPO
)
)
c.sudo('bash -c "cd %s && ./reload.sh"' % (DIR))
@task()
def deploy_and_restart(c):
(
"Runs 'git pull', restarts docker-compose (required if you change "
"nginx.conf) and reloads Nginx"
)
for host in HOSTS:
print('\n\n*** CONNECTING TO: %s' % (host))
config = Config(overrides={'sudo': {'password': sudo_pass}})
if host in OLD_HOSTS:
c = Connection(host, config=config, connect_kwargs={'disabled_algorithms': {'pubkeys': ['rsa-sha2-256', 'rsa-sha2-512']}})
else:
c = Connection(host, config=config)
c.run(
'cd %s && git pull [email protected]:openstate/%s.git' % (
DIR,
GIT_REPO
)
)
if host in NEW_DOCKER:
c.sudo('bash -c "cd %s && docker compose restart"' % (DIR))
else:
c.sudo('bash -c "cd %s && docker-compose restart"' % (DIR))
c.sudo('bash -c "cd %s && ./reload.sh"' % (DIR))
@task
def deploy_and_up(c):
(
"Runs 'git pull', 'docker-compose up -d' (required if you update "
"Nginx version) and reloads Nginx"
)
for host in HOSTS:
print('\n\n*** CONNECTING TO: %s' % (host))
config = Config(overrides={'sudo': {'password': sudo_pass}})
if host in OLD_HOSTS:
c = Connection(host, config=config, connect_kwargs={'disabled_algorithms': {'pubkeys': ['rsa-sha2-256', 'rsa-sha2-512']}})
else:
c = Connection(host, config=config)
c.run(
'cd %s && git pull [email protected]:openstate/%s.git' % (
DIR,
GIT_REPO
)
)
if host in NEW_DOCKER:
c.sudo('bash -c "cd %s && docker compose up -d"' % (DIR))
else:
c.sudo('bash -c "cd %s && docker-compose up -d"' % (DIR))
c.sudo('bash -c "cd %s && ./reload.sh"' % (DIR))
@task
def deploy_certbot(c):
(
"Runs 'git pull', 'docker-compose build c-certbot', 'docker-compose "
"up -d' (required if you update Certbot version) and reloads Nginx"
)
for host in HOSTS:
print('\n\n*** CONNECTING TO: %s' % (host))
config = Config(overrides={'sudo': {'password': sudo_pass}})
if host in OLD_HOSTS:
c = Connection(host, config=config, connect_kwargs={'disabled_algorithms': {'pubkeys': ['rsa-sha2-256', 'rsa-sha2-512']}})
else:
c = Connection(host, config=config)
c.run(
'cd %s && git pull [email protected]:openstate/%s.git' % (
DIR,
GIT_REPO
)
)
if host in NEW_DOCKER:
c.sudo('bash -c "cd %s && docker compose build c-certbot"' % (DIR))
c.sudo('bash -c "cd %s && docker compose up -d"' % (DIR))
else:
c.sudo('bash -c "cd %s && docker-compose build c-certbot"' % (DIR))
c.sudo('bash -c "cd %s && docker-compose up -d"' % (DIR))
c.sudo('bash -c "cd %s && ./reload.sh"' % (DIR))