This repository has been archived by the owner on May 9, 2024. It is now read-only.
forked from artefactual-sdps/enduro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tiltfile
177 lines (160 loc) · 5.58 KB
/
Tiltfile
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
version_settings(constraint=">=0.22.2")
secret_settings(disable_scrub=True)
load("ext://uibutton", "cmd_button", "text_input")
load('ext://dotenv', 'dotenv')
# Load tilt env file if it exists
dotenv_path = ".tilt.env"
if os.path.exists(dotenv_path):
dotenv(fn=dotenv_path)
# Get preservation system (default: 'a3m')
PRES_SYS = os.environ.get('ENDURO_PRES_SYSTEM', 'a3m')
if PRES_SYS not in ("a3m", "am"):
fail("Invalid ENDURO_PRES_SYSTEM: {pres_sys}.".format(pres_sys=PRES_SYS))
true = ("true", "1", "yes", "t", "y")
LOCAL_A3M = os.environ.get("LOCAL_A3M", "").lower() in true
# Docker images
custom_build(
ref="enduro:dev",
command=["hack/build_docker.sh", "enduro"],
deps=["."],
)
if PRES_SYS == 'am':
custom_build(
ref="enduro-am-worker:dev",
command=["hack/build_docker.sh", "enduro-am-worker"],
deps=["."],
)
else:
custom_build(
ref="enduro-a3m-worker:dev",
command=["hack/build_docker.sh", "enduro-a3m-worker"],
deps=["."],
)
if LOCAL_A3M:
docker_build("ghcr.io/artefactual-labs/a3m", context="../a3m")
docker_build(
"enduro-dashboard:dev",
context="dashboard",
# Comment the following line to serve the app with Nginx instead of the Vite
# dev server
target="builder",
live_update=[
fall_back_on("dashboard/vite.config.js"),
sync("dashboard/", "/app/"),
run(
"npm set cache /app/.npm && npm install-clean",
trigger=[
"dashboard/package.json",
"dashboard/package-lock.json",
"dashboard/.env*",
]
),
]
)
# Get kube overlay path
KUBE_OVERLAY = 'hack/kube/overlays/dev-a3m'
if PRES_SYS == 'am':
KUBE_OVERLAY = 'hack/kube/overlays/dev-am'
# Load Kustomize YAML
yaml = kustomize(KUBE_OVERLAY)
# Preprocessing
PREPROCESSING_PATH = os.environ.get("PREPROCESSING_PATH", "")
if PREPROCESSING_PATH != "":
# Load preprocessing Tiltfile for Enduro
load_dynamic(PREPROCESSING_PATH + "/Tiltfile.enduro")
# Get Enduro a3m/am worker k8s manifest
if PRES_SYS == "a3m":
pres_yaml, yaml = filter_yaml(yaml, name="^enduro-a3m$", kind="StatefulSet")
else:
pres_yaml, yaml = filter_yaml(yaml, name="^enduro-am$", kind="Deployment")
# Append preprocessing volume and volume mount to worker container,
# this will only work in single node k8s cluster deployments
volume = {"name": "shared-dir", "persistentVolumeClaim": {"claimName": "preprocessing-pvc"}}
volume_mount = {"name": "shared-dir", "mountPath": "/home/enduro/preprocessing"}
pres_obj = decode_yaml(pres_yaml)
if "volumes" not in pres_obj["spec"]["template"]["spec"]:
pres_obj["spec"]["template"]["spec"]["volumes"] = []
pres_obj["spec"]["template"]["spec"]["volumes"].append(volume)
for container in pres_obj["spec"]["template"]["spec"]["containers"]:
if container["name"] in ["enduro-a3m-worker", "enduro-am-worker"]:
container["volumeMounts"].append(volume_mount)
pres_yaml = encode_yaml(pres_obj)
yaml = [yaml, pres_yaml]
# Load Kubernetes resources
k8s_yaml(yaml)
# Configure trigger mode
trigger_mode = TRIGGER_MODE_MANUAL
if os.environ.get('TRIGGER_MODE_AUTO', '').lower() in true:
trigger_mode = TRIGGER_MODE_AUTO
# Enduro resources
k8s_resource("enduro", labels=["Enduro"], trigger_mode=trigger_mode)
k8s_resource("enduro-internal", port_forwards="9000", labels=["Enduro"], trigger_mode=trigger_mode)
k8s_resource("enduro-dashboard", port_forwards="8080:80", labels=["Enduro"], trigger_mode=trigger_mode)
if PRES_SYS == 'am':
k8s_resource("enduro-am", labels=["Enduro"], trigger_mode=trigger_mode)
else:
k8s_resource("enduro-a3m", labels=["Enduro"], trigger_mode=trigger_mode)
# Other resources
k8s_resource("dex", port_forwards="5556", labels=["Others"])
k8s_resource("ldap", labels=["Others"])
k8s_resource("mysql", port_forwards="3306", labels=["Others"])
k8s_resource(
"minio",
port_forwards=["7460:9001",
"0.0.0.0:7461:9000"],
labels=["Others"]
)
k8s_resource("redis", labels=["Others"])
k8s_resource("temporal", labels=["Others"])
k8s_resource("temporal-ui", port_forwards="7440:8080", labels=["Others"])
# Tools
k8s_resource("minio-setup-buckets", labels=["Tools"])
k8s_resource("mysql-create-locations", labels=["Tools"])
# Observability
k8s_resource("grafana-agent", labels=["Observability"])
k8s_resource("grafana-tempo", labels=["Observability"])
k8s_resource("grafana", port_forwards="7490:3000", labels=["Observability"])
# Buttons
cmd_button(
"minio-upload",
argv=[
"sh",
"-c",
"docker run --rm \
--add-host=host-gateway:host-gateway \
--entrypoint=/bin/bash \
-v $HOST_PATH:/sampledata/$OBJECT_NAME \
minio/mc -c ' \
mc alias set enduro http://host-gateway:7461 minio minio123; \
mc cp -r /sampledata/$OBJECT_NAME enduro/sips/$OBJECT_NAME; \
' \
",
],
location="nav",
icon_name="cloud_upload",
text="Minio upload",
inputs=[
text_input("HOST_PATH", label="Host path"),
text_input("OBJECT_NAME", label="Object name"),
]
)
cmd_button(
"flush",
argv=[
"sh",
"-c",
"kubectl config set-context --current --namespace enduro-sdps; \
kubectl delete job --all; \
kubectl create -f hack/kube/tools/mysql-recreate-databases-job.yaml; \
kubectl create -f hack/kube/tools/minio-recreate-buckets-job.yaml; \
kubectl wait --for=condition=complete --timeout=120s job --all; \
kubectl rollout restart deployment temporal; \
kubectl rollout restart deployment enduro; \
kubectl rollout restart statefulset enduro-{pres_sys}; \
kubectl rollout restart deployment dex; \
kubectl create -f hack/kube/base/mysql-create-locations-job.yaml;".format(pres_sys=PRES_SYS),
],
location="nav",
icon_name="delete",
text="Flush"
)