-
Notifications
You must be signed in to change notification settings - Fork 9
/
Tiltfile
134 lines (114 loc) · 3.85 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
load("./tilt/cloudapi/Tiltfile", "setup_cloudapi")
load("./tilt/metrics/Tiltfile", "setup_metrics_server")
load("./tilt/utils/Tiltfile", "run_command")
load("ext://color", "color")
load("ext://helm_resource", "helm_repo")
load("ext://uibutton", "cmd_button", "location", "choice_input")
config.define_bool("no-build", False, "Skip building Docker images")
config.define_bool("destroy", False, "Destroy Kind cluster")
config.define_bool("destroy-all", False, "Destroy Kind cluster and delete docker cache")
config.define_bool(
"expose",
False,
"Detect Host IP and set Ingress Domain Name to expose services outside of 'localhost' context",
)
cfg = config.parse()
update_settings(
k8s_upsert_timeout_secs=600,
max_parallel_updates=5,
)
# Restrict to `kind-aries-cloudapi` kube context
kind_cluster_name = "kind-aries-cloudapi"
allow_k8s_contexts([kind_cluster_name])
if config.tilt_subcommand in ("up", "ci"):
print(color.green("Setting up Istio"))
local_resource(
name="istio",
cmd="mise run kind:install:istio",
allow_parallel=True,
labels=["99-networking"],
)
print(color.green("Setting up Ingress Nginx"))
local_resource(
name="ingress-nginx",
cmd="mise run kind:install:nginx",
allow_parallel=True,
labels=["99-networking"],
)
# Setup Metrics Server
setup_metrics_server()
# Validate `didx-xyz/charts` repo has been cloned
charts_dir = "tilt/.charts"
if not os.path.exists(charts_dir):
print(color.yellow("Charts not found, cloning charts repo"))
ssh_result = run_command(
"git clone [email protected]:didx-xyz/charts.git " + charts_dir,
dir=os.path.dirname(__file__),
)
if "fatal" in ssh_result:
print(color.red("Failed to clone charts repo via SSH, retrying with HTTPS"))
https_result = run_command(
"git clone https://github.com/didx-xyz/charts.git "
+ charts_dir
+ " 2>&1 | tee /dev/stdout",
dir=os.path.dirname(__file__),
)
if "fatal" in https_result:
fail(color.red("Failed to clone charts repo"))
print(color.green("Charts repo cloned"))
else:
print(color.green("Charts repo already cloned"))
cmd_button(
name="expose",
icon_name="public", # https://fonts.google.com/icons
text="Expose Ingresses via Tailscale or Local Network",
location=location.NAV,
argv=[
"tilt",
"patch",
"tiltfile",
"(Tiltfile)",
"--patch",
'{"spec": {"args": ["--expose=True"]}}',
],
)
cmd_button(
name="unexpose",
icon_name="public_off",
text="Switch Ingresses back to 'localhost'",
location=location.NAV,
argv=[
"tilt",
"patch",
"tiltfile",
"(Tiltfile)",
"--patch",
'{"spec": {"args": ["--expose=False"]}}',
],
)
# Setup CloudAPI
build_enabled = not cfg.get("no-build")
expose = cfg.get("expose")
setup_cloudapi(build_enabled, expose)
if config.tilt_subcommand not in ("down"):
# _FORCE_ Kube Context to `kind-aries-cloudapi`
local(
"kubectl config use-context " + kind_cluster_name, dir=os.path.dirname(__file__)
)
if config.tilt_subcommand in ("down"):
destroy = config.parse().get("destroy")
destroy_all = config.parse().get("destroy-all")
if destroy_all:
print(color.red("Destroying Kind cluster and deleting docker cache"))
local(
"docker compose -f ./docker-compose-ledger.yaml down -v",
dir=os.path.dirname(__file__),
)
local("mise run kind:destroy:all", dir=os.path.dirname(__file__))
if destroy:
print(color.red("Destroying Kind cluster"))
local(
"docker compose -f ./docker-compose-ledger.yaml down -v",
dir=os.path.dirname(__file__),
)
local("mise run kind:destroy", dir=os.path.dirname(__file__))