-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTiltfile
72 lines (62 loc) · 2.66 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
#########################################################################
#
# Tiltfile logic
#
#########################################################################
# Import required functions from Tilt extensions
load(
"ext://namespace",
"namespace_create",
"namespace_inject"
)
# Set default platform
os.putenv("DOCKER_DEFAULT_PLATFORM", "linux/amd64")
# Import settings from tilt_config.json
if not os.path.exists("./tilt_config.json"):
fail(
"""
# ===================================================================== #
# Tilt config file not found in current directory! #
# Please copy a template from tilt-resources dir. #
# #
# E.g.: #
# cp tilt-resources/local/tilt_config_local.json tilt_config.json #
# ==================================================================== #
"""
)
config.define_string_list("allowed_contexts")
config.define_string("default_registry")
config.define_string_list("microservices")
config.define_string("namespace")
config.define_string_list("port_forwards")
cfg = config.parse()
# Allow default K8S context as stated in the tilt_config.json file
allow_k8s_contexts(cfg.get("allowed_contexts"))
# Set default registry as stated in the tilt_config.json file
if cfg.get("default_registry") != "":
default_registry(cfg.get("default_registry"))
# Build each microservice image as stated in the tilt_config.json file
for microservice in cfg.get("microservices"):
docker_build(
microservice,'pkg/app'
)
# Deploy each microservice image as stated in the tilt_config.json file
for microservice in cfg.get("microservices"):
k8s_yaml(helm('chart', microservice, values='tilt-resources/local/tilt-helm-local-values.yaml'))
# Port forwards as stated in the tilt_config.json file
for port_forward in cfg.get("port_forwards"):
mapping = port_forward.split(":")
if (len(mapping) != 2):
fail(
"""
# =================================================== #
# Invalid port forward specified in tilt_config.json! #
# Should be <resource>:<port_number>. #
# #
# E.g.: bots:8080 #
# =================================================== #
"""
)
service = mapping[0]
port = mapping[1]
k8s_resource(service, objects=['bots:ServiceAccount'], port_forwards=port)