-
Notifications
You must be signed in to change notification settings - Fork 91
/
.transpire.py
141 lines (119 loc) · 3.81 KB
/
.transpire.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
from pathlib import Path
from transpire.resources import Deployment, Ingress, Secret, Service
from transpire.types import Image
from transpire.utils import get_image_tag, get_revision
name = "ocfweb"
auto_sync = True
def images():
yield Image(name="web", path=Path("/"), target="web")
yield Image(name="worker", path=Path("/"), target="worker")
yield Image(name="static", path=Path("/"), target="static")
def add_ocfweb_common(dep):
dep.obj.spec.template.spec.dns_policy = "ClusterFirst"
dep.obj.spec.template.spec.dns_config = {"searches": ["ocf.berkeley.edu"]}
dep.obj.spec.template.spec.volumes = [
{"name": "etc", "emptyDir": {}},
{"name": "secrets", "secret": {"secretName": "ocfweb"}},
]
dep.obj.spec.template.spec.containers.append(
{
"name": "sync-etc",
"image": "harbor.ocf.berkeley.edu/ocf/etc/sync:4c3eb1f6ba456ec30a2fbf21423364eaf0ae40bd",
"args": ["/etc/ocf", "--repeat-delay", "60"],
"volumeMounts": [{"name": "etc", "mountPath": "/etc/ocf"}],
}
)
dep.obj.spec.template.spec.containers[0].volume_mounts = [
{"name": "etc", "mountPath": "/etc/ocf"},
{"name": "secrets", "mountPath": "/etc/ocfweb"},
]
dep.obj.spec.template.spec.containers[0].env = [
{"name": "PUPPET_CERT_DIR", "value": "/etc/ocfweb"},
{"name": "OCFWEB_TESTING", "value": "0"},
{"name": "OCFWEB_PROD_VERSION", "value": get_revision()},
]
def add_probes(dep, path="/"):
dep.obj.spec.template.spec.containers[0].readiness_probe = {
"httpGet": {
"path": path,
"port": 8000,
"httpHeaders": [{"name": "Host", "value": "www.ocf.berkeley.edu"}],
},
"initialDelaySeconds": 5,
"periodSeconds": 5,
}
dep.obj.spec.template.spec.containers[0].liveness_probe = {
"httpGet": {
"path": path,
"port": 8000,
"httpHeaders": [{"name": "Host", "value": "www.ocf.berkeley.edu"}],
},
"initialDelaySeconds": 10,
"timeoutSeconds": 3,
"failureThreshold": 6,
}
def objects():
yield Secret(
name="ocfweb",
string_data={
"metrics.htpasswd": "",
"ocfweb.conf": "",
"puppet-ca.pem": "",
"puppet-cert.pem": "",
"puppet-private.pem": "",
"puppet-public.pem": "",
"puppet-signed.pem": "",
},
).build()
dep_web = Deployment(
name="ocfweb",
image=get_image_tag("web"),
ports=[8000],
)
add_ocfweb_common(dep_web)
add_probes(dep_web)
yield dep_web.build()
dep_worker = Deployment(
name="ocfweb-worker",
image=get_image_tag("worker"),
ports=[8000],
)
add_ocfweb_common(dep_worker)
yield dep_worker.build()
dep_static = Deployment(
name="ocfweb-static",
image=get_image_tag("static"),
ports=[8000],
)
add_ocfweb_common(dep_static)
add_probes(dep_static, path="/js/site.js")
yield dep_static.build()
svc_web = Service(
name="ocfweb",
selector=dep_web.get_selector(),
port_on_pod=8000,
port_on_svc=80,
)
yield svc_web.build()
svc_static = Service(
name="ocfweb-static",
selector=dep_static.get_selector(),
port_on_pod=8000,
port_on_svc=80,
)
yield svc_static.build()
ing_web = Ingress.from_svc(
svc=svc_web,
host="www.ocf.berkeley.edu",
path_prefix="/",
)
ing_web.obj.metadata.annotations[
"ingress.kubernetes.io/force-ssl-redirect"
] = "false"
yield ing_web.build()
ing_static = Ingress.from_svc(
svc=svc_static,
host="static.ocf.berkeley.edu",
path_prefix="/",
)
yield ing_static.build()