forked from tilt-dev/bazel_example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTiltfile
75 lines (57 loc) · 1.94 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
BAZEL_RUN_CMD = "bazel run --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 %s %s"
BAZEL_SOURCES_CMD = """
bazel query 'filter("^//", kind("source file", deps(set(%s))))' --order_output=no
""".strip()
BAZEL_BUILDFILES_CMD = """
bazel query 'filter("^//", buildfiles(deps(set(%s))))' --order_output=no
""".strip()
def bazel_labels_to_files(labels):
files = {}
for l in labels:
if l.startswith("//external/") or l.startswith("//external:"):
continue
elif l.startswith("//"):
l = l[2:]
path = l.replace(":", "/")
if path.startswith("/"):
path = path[1:]
files[path] = None
return files.keys()
def watch_labels(labels):
watched_files = []
for l in labels:
if l.startswith("@"):
continue
elif l.startswith("//external/") or l.startswith("//external:"):
continue
elif l.startswith("//"):
l = l[2:]
path = l.replace(":", "/")
if path.startswith("/"):
path = path[1:]
watch_file(path)
watched_files.append(path)
return watched_files
def bazel_k8s(target):
build_deps = str(local(BAZEL_BUILDFILES_CMD % target)).splitlines()
source_deps = str(local(BAZEL_SOURCES_CMD % target)).splitlines()
watch_labels(build_deps)
watch_labels(source_deps)
return local("bazel run %s" % target)
def bazel_build(image, target, options=''):
build_deps = str(local(BAZEL_BUILDFILES_CMD % target)).splitlines()
watch_labels(build_deps)
source_deps = str(local(BAZEL_SOURCES_CMD % target)).splitlines()
source_deps_files = bazel_labels_to_files(source_deps)
custom_build(
image,
BAZEL_RUN_CMD % (target, options),
source_deps_files,
tag="image",
)
k8s_yaml(bazel_k8s(":snack-server"))
k8s_yaml(bazel_k8s(":vigoda-server"))
bazel_build('bazel/snack', "//snack:image", "-- --norun")
bazel_build('bazel/vigoda', "//vigoda:image", "-- --norun")
k8s_resource('varowner-snack', port_forwards=9000)
k8s_resource('varowner-vigoda', port_forwards=9001)