-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfabfile.py
89 lines (66 loc) · 2.17 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
import copy, os
from fabric.api import local, prompt
from fabric.contrib.console import confirm
import yaml
from git import Repo
def _image_version(config):
"""
Returns the image and version from a kubernets config
"""
image_version = config['spec']['template']['spec']['containers'][0]['image']
return image_version.split(':') # image, version
def _build(image, version, directory):
"""
Builds docker image from directory after confirmation
"""
tag = image + ':' + str(version)
if confirm('Build new version {v} of {i}?'.format(i=image, v=version)):
print('')
local('docker build -t {t} {d}'.format(t=tag, d=directory))
def _push(image, version):
"""
Pushes image to gcloud
"""
tag = image + ':' + str(version)
if confirm('Push image {t} to gcloud?'.format(t=tag)):
print('')
local('gcloud docker -- push {t}'.format(t=tag))
def _git_tag(version):
"""
Tags the latest commit with the new version
"""
if confirm('Tag latest commit to repo?'):
repo = Repo(os.path.dirname(os.path.abspath(__file__)))
commit = repo.head.commit
repo.create_tag(version, ref=commit)
def _update_config(filename, tag):
"""
Updates the config file for latest tag
"""
with open(filename) as f:
config = yaml.safe_load(f)
new_config = _update_config_image(copy.deepcopy(config), tag)
yaml_config = yaml.dump(new_config, default_flow_style=False)
print('New config:')
print('')
print(yaml_config)
print('')
def deploy():
"""
Deploy updated web, celery, and celery-beat containers to kubernetes
"""
paths = ('k8s/web.yaml', 'k8s/celery.yaml', 'k8s/celery-beat.yaml')
with open(paths[0]) as f:
config = yaml.safe_load(f)
image, version = _image_version(config)
print('Current version {v} for image {i}'.format(v=version, i=image))
new_version = prompt('New version:')
print('')
_build(image, new_version, 'web/')
print('')
_push(image, new_version)
# git tag, push
# sentry release tracking?
# for path in paths:
# write new config
# replace