-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tiltfile
86 lines (74 loc) · 2.89 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
#########################################################################
#
# Tiltfile logic
#
#########################################################################
# Import required functions from Tilt extensions
load(
"ext://namespace",
"namespace_create",
"namespace_inject"
)
# 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.json . #
# ================================================ #
"""
)
config.define_string_list("allowed_contexts")
config.define_string("default_registry")
config.define_string("environment")
config.define_string_list("microservices")
config.define_string("namespace")
config.define_string_list("port_forwards")
cfg = config.parse()
# Compatibilty setting for ARM arch
os.putenv("DOCKER_DEFAULT_PLATFORM", "linux/amd64")
# 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"):
if "redis" in microservice:
continue
docker_build(
microservice,
# cartservice is an exception regarding source folder path
"src/{}/src".format(microservice) if "cartservice" in microservice else "src/{}".format(microservice)
)
# Create namespace as stated in the tilt_config.json file
namespace_create(cfg.get("namespace"))
# Deploy each microservice as stated in the tilt_config.json file
for microservice in cfg.get("microservices"):
k8s_yaml(
namespace_inject(
read_file("kustomize/base/{}.yaml".format(microservice)),
cfg.get("namespace")
)
)
# 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.: frontend:9090 #
# =================================================== #
"""
)
service = mapping[0]
port = mapping[1]
k8s_resource(service, port_forwards=port)