This repository has been archived by the owner on Jul 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 277
/
Tiltfile
157 lines (139 loc) · 4.58 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# https://github.com/tilt-dev/tilt-extensions/tree/master/restart_process
load('ext://restart_process', 'docker_build_with_restart')
config.define_string_list("osm-values", args=True)
cfg = config.parse()
# This configures only the following resources. This way helm doesn't deploy
# cleanup and pre-install jobs
# https://docs.tilt.dev/tiltfile_config.html#run-a-defined-set-of-services
resources = ["osm-bootstrap",
"osm-controller",
"osm-injector",
"controller-compile",
"injector-compile",
"bootstrap-compile",
"wasm-compile",
"demo"]
config.set_enabled_resources(resources)
# The default charts have a restricted security context
# we remove the security context from the charts to enable
# this is done here instead of the helm chart because its a developer tool not something
# we want to disable for general use
def remove_securityContext(yaml_stream):
for item in yaml_stream:
if item["kind"] == "Deployment":
item['spec']['template']['spec']['securityContext'] = None
return yaml_stream
def dockerfile_gen(binary_name, additionalCommands=[]):
tilt_dockerfile_header = """
FROM gcr.io/distroless/base:debug as tilt
WORKDIR /
COPY ./{} /{}
""".format(binary_name, binary_name)
return "\n".join([
tilt_dockerfile_header
] + additionalCommands)
local("kubectl create ns osm-system || true", quiet = True)
osm_values=[ 'image.tag=latest-main',
'osm.controllerLogLevel=trace']
# load user settings
extra_values=cfg.get("osm-values", [])
osm_values.extend(extra_values)
yaml = helm(
'charts/osm',
name='osm-dev',
namespace='osm-system',
# Values to set from the command-line
set=osm_values,
)
yaml_dict = remove_securityContext(decode_yaml_stream(yaml))
k8s_yaml((encode_yaml_stream(yaml_dict)))
# compile binaries
local_resource(
'controller-compile',
'CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ./build/osm-controller ./cmd/osm-controller',
deps=['./cmd/osm-controller/osm-controller.go', 'pkg'],
labels=['compile'],
)
local_resource(
'injector-compile',
'CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ./build/osm-injector ./cmd/osm-injector',
deps=['./cmd/osm-injector/osm-injector.go', 'pkg'],
labels=['compile']
)
local_resource(
'bootstrap-compile',
'CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ./build/osm-bootstrap ./cmd/osm-bootstrap && cp -r ./cmd/osm-bootstrap/crds ./build',
deps=['./cmd/osm-bootstrap/osm-bootstrap.go', 'pkg', './cmd/osm-bootstrap/crds'],
labels=['compile']
)
wasm_compile = """
make buildx-context && \
docker buildx build \
--builder osm --platform=linux/amd64 \
-o type=docker --build-arg GO_BASE_IMAGE=notused \
--build-arg FINAL_BASE_IMAGE=notused --target wasm \
-t osm-wasm -f dockerfiles/Dockerfile.osm-controller . && \\
docker run -v $PWD/pkg/envoy/generator/lds:/updatefolder osm-wasm \
cp /wasm/stats.wasm /updatefolder
"""
local_resource(
'wasm-compile',
wasm_compile,
labels=['compile'],
deps=['./wasm']
)
# wire up redeploys
# https://docs.tilt.dev/example_go.html#step-3-lets-live-update-it
docker_build_with_restart(
'openservicemesh/osm-controller',
context='./build/',
target='tilt',
dockerfile_contents = dockerfile_gen('osm-controller'),
only=[
'osm-controller'
],
entrypoint=['/osm-controller'],
live_update=[
sync('./build/osm-controller', '/osm-controller'),
]
)
docker_build_with_restart(
'openservicemesh/osm-injector',
context='./build/',
target='tilt',
dockerfile_contents = dockerfile_gen('osm-injector'),
only=[
'osm-injector'
],
entrypoint=['/osm-injector'],
live_update=[
sync('./build/osm-injector', '/osm-injector'),
]
)
docker_build_with_restart(
'openservicemesh/osm-bootstrap',
context='./build/',
target='tilt',
dockerfile_contents = dockerfile_gen('osm-bootstrap', ["COPY ./crds/* /osm-crds/"]),
only=[
'osm-bootstrap',
'crds/'
],
entrypoint=['/osm-bootstrap'],
live_update=[
sync('./build/osm-bootstrap', '/osm-bootstrap'),
]
)
# https://docs.tilt.dev/tiltfile_config.html#grouping-services-in-web-ui
k8s_resource(workload = "osm-controller", labels = ["osm"])
k8s_resource(workload = "osm-bootstrap", labels = ["osm"])
k8s_resource(workload = "osm-injector", labels = ["osm"])
# build and deploy the demo images on demand
# you can make changes to the demo and redeploy with this resource
local_resource(
name= "demo",
cmd = "./scripts/deploy-demo-tilt.sh",
auto_init = False,
trigger_mode = TRIGGER_MODE_MANUAL,
labels = ["osm-demo"]
)