-
Notifications
You must be signed in to change notification settings - Fork 12
/
fabfile.py
112 lines (88 loc) · 1.81 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
import time
from fabric.api import (
local,
settings,
task
)
from fabric.state import env
SWARM101_NETWORK = 'swarm101'
SERVICES = [
(
'zkan/bangkok',
'services/bangkok/Dockerfile',
'services/bangkok'
),
(
'zkan/munich',
'services/munich/Dockerfile',
'services/munich'
),
(
'zkan/tokyo',
'services/tokyo/Dockerfile',
'services/tokyo'
),
(
'zkan/nyc',
'services/nyc/Dockerfile',
'services/nyc'
),
(
'zkan/front_gateway',
'services/front_gateway/Dockerfile',
'services/front_gateway'
),
]
@task
def localhost():
env.run = local
@task
def swarm_init():
env.run('docker swarm init')
@task
def leave_swarm():
with settings(warn_only=True):
env.run('docker swarm leave --force')
@task
def build_images():
for name, dockerfile, path in SERVICES:
command = 'docker build -t ' + name + ':latest -f ' + \
dockerfile + ' ' + path
env.run(command)
@task
def push():
for name, _, _ in SERVICES:
command = f'docker push {name}'
env.run(command)
@task
def deploy():
command = 'docker stack deploy swarm101 -c swarm/docker-compose.yml'
env.run(command)
@task
def setup_swarm():
swarm_init()
build_images()
deploy()
def deploy_k8s(create=True):
services = [
'bangkok',
'tokyo',
'nyc',
'munich',
'front-gateway',
]
if create:
action = 'create'
else:
action = 'delete'
for each in services:
command = f'kubectl {action} -f k8s/{each}-deployment.yml'
env.run(command)
@task
def setup_k8s():
build_images()
push()
deploy_k8s()
@task
def delete_k8s():
deploy_k8s(create=False)