-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.py
More file actions
55 lines (40 loc) · 1.29 KB
/
deploy.py
File metadata and controls
55 lines (40 loc) · 1.29 KB
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
#!/usr/bin/env python
import logging
import os
import docker
from kubernetes import client, config
logging.basicConfig(level=logging.INFO)
def build_image(path, image):
logging.info('Building image "%s"...', image)
client = docker.from_env()
image = client.images.build(path=path, tag=image)
logging.info('Done...')
return image
def set_image(name, namespace, image):
logging.info('Setting deployment to "%s"...', image)
config.load_kube_config()
c = client.ExtensionsV1beta1Api()
deployment = c.read_namespaced_deployment(name, namespace)
deployment.spec.template.spec.containers[0].image = image
res = c.patch_namespaced_deployment(
name=name, namespace=namespace, body=deployment
)
logging.info('Done...')
return res
def deploy(name, path, image, namespace='default', env={}):
# Easier to set dockerpy client via envvar.
for k, v in env.items():
os.environ[k] = v
build_image(path, image)
set_image(name, namespace, image)
if __name__ == '__main__':
app_name = ''
app_path = ''
app_image_name = ''
env = {
'DOCKER_TLS_VERIFY': '',
'DOCKER_HOST': '',
'DOCKER_CERT_PATH': '',
'DOCKER_API_VERSION': '',
}
deploy(app_name, app_path, app_image_name, env=env)