forked from tilt-dev/tilt-extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tiltfile
93 lines (79 loc) · 3 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
# -*- mode: Python -*-
version_settings(constraint='>=0.23.4')
pulumi_apply_path = os.path.abspath('pulumi-apply-helper.py')
def pulumi_resource(
name,
stack='',
dir='',
deps=[],
image_deps=None,
image_configs=None,
image_selector='',
container_selector='',
live_update=None,
resource_deps=None,
labels=None,
port_forwards=[]):
"""Installs a helm chart to a cluster.
Args:
name: The name of the resource in the Tilt UI.
stack: The Pulumi stack to operate on. Defaults to the current stack.
dir: The directory to run 'pulumi up' in. Defaults to the current working directory.
deps: A list of file dependencies that should trigger a deployment.
release_name: The name of the release. If not specified, defaults to the Tilt UI resource name.
namespace: Install into the specified namespace.
image_deps: A list of images built by Tilt to inject into the chart. If Tilt doesn't know
how to build one of these images, this will be an error.
image_configs: A list of config keys for how to inject images into the Pulumi stack.
Assumes that the stack uses Pulumi's Configuration API for injecting images.
(see the example code).
image_selector: Image reference to determine containers eligible for Live Update.
Only applicable if there are no images in `image_deps`.
container_selector: Container reference to determine containers eligible for Live Update.
Only applicable if there are no images in `image_deps`.
live_update: Live Update steps for images not built by Tilt.
Only applicable if there are no images in `image_deps`.
resource_deps: Tilt resources to depend on. Useful for
adding a dependency on a helm repo install.
labels: Labels for categorizing the resource.
port_forwards: Host port to connect to the pod.
"""
if not dir:
dir=os.getcwd()
if not image_deps:
image_deps = []
if not image_configs:
image_configs = []
if len(image_deps) != len(image_configs):
fail('image_deps and image_configs must have the same length, so that we know how to inject images into the pulumi stack')
apply_cmd = ['python3', pulumi_apply_path]
delete_cmd = ["pulumi", "destroy", "-y"]
flags = []
for i in range(len(image_deps)):
config = image_configs[i]
if type(config) == 'string':
apply_cmd.extend([config])
else:
fail("invalid argument to image_configs at %s: %s" % (i, type(config)))
if stack:
delete_cmd.extend(['--stack', stack])
k8s_custom_deploy(
name,
apply_cmd=apply_cmd,
apply_env={
'STACK': stack,
},
apply_dir=dir,
delete_cmd=delete_cmd,
delete_dir=dir,
deps=deps,
image_deps=image_deps,
image_selector=image_selector,
container_selector=container_selector,
live_update=live_update)
if resource_deps:
k8s_resource(name, resource_deps=resource_deps)
if labels:
k8s_resource(name, labels=labels)
if len(port_forwards):
k8s_resource(name, port_forwards=port_forwards)