forked from agentgateway/agentgateway
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTiltfile
More file actions
200 lines (179 loc) · 6.97 KB
/
Copy pathTiltfile
File metadata and controls
200 lines (179 loc) · 6.97 KB
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# Tiltfile for AgentGateway development
# This deploys both control plane (Go) and data plane (Rust) to Kind with live updates
load('ext://restart_process', 'docker_build_with_restart')
load('ext://helm_resource', 'helm_resource', 'helm_repo')
# Configuration
version = 'v1.0.1-dev'
cluster_name = 'kind'
install_namespace = k8s_namespace()
image_registry = 'localhost:5000'
# Detect host architecture for cross-compilation
host_os = str(local('uname -s', quiet=True)).strip()
host_arch = str(local('uname -m', quiet=True)).strip()
if host_arch in ['arm64', 'aarch64']:
rust_target = 'aarch64-unknown-linux-gnu'
else:
rust_target = 'x86_64-unknown-linux-gnu'
cross_env = ''
if host_os == 'Darwin' and host_arch in ['arm64', 'aarch64']:
cross_env = 'CROSS_CONTAINER_OPTS="${CROSS_CONTAINER_OPTS:+$CROSS_CONTAINER_OPTS }--platform linux/amd64" '
if str(local('command -v cross >/dev/null 2>&1; echo $?', quiet=True)).strip() != '0':
fail('cross is required for Tilt dataplane builds. Install it with: cargo install cross')
# Ensure Kind cluster exists
allow_k8s_contexts('kind-' + cluster_name)
# Helper to run Make targets
def run_make(target, cwd='.'):
return local('make -C ' + cwd + ' ' + target)
def run_controller_make(target):
return run_make(target, cwd='./controller')
# =============================================================================
# Setup: Ensure cluster is ready
# =============================================================================
# Check if kind cluster exists, create if not
if str(local('kind get clusters 2>/dev/null | grep -c "^' + cluster_name + '$" || true')).strip() == '0':
print('No kind cluster! create one and restart tilt after doing so. You can use this command:')
print('ctlptl create cluster kind --name kind-' + cluster_name + ' --registry=ctlptl-registry')
fail("started kind cluster. Create one and run tilt again")
print('Installing Gateway API CRDs...')
run_controller_make('gw-api-crds')
run_controller_make('gie-crds')
# Install CRDs
print('Installing AgentGateway CRDs...')
helm_resource(
'agentgateway-crds',
'controller/install/helm/agentgateway-crds',
namespace=install_namespace,
flags=['--set=version=' + version],
)
# =============================================================================
# Control Plane (Go-based controller)
# =============================================================================
local_resource(
'go-compile-controller',
'make -C ./controller VERSION=' + version + ' GCFLAGS=all="-N -l" agentgateway-controller && mv ./controller/_output/pkg/agentgateway/agentgateway-linux-$(go env GOARCH) ./tools/tilt/agentgateway-controller',
deps=['./controller/'],
ignore=['./controller/_output/'],
)
# Build control plane Docker image
docker_build_with_restart(
image_registry + '/agentgateway-controller',
context='./tools/tilt/',
entrypoint='/usr/local/bin/agentgateway-controller',
# Run as non-root while ensuring Tilt can do in-place updates of the Go binary
dockerfile_contents="""
FROM ubuntu:24.04
RUN useradd -r -U -u 65532 -s /usr/sbin/nologin agentgateway
RUN chown agentgateway:agentgateway /usr/local/bin
COPY --chown=agentgateway:agentgateway agentgateway-controller /usr/local/bin/agentgateway-controller
USER 65532
ENTRYPOINT /usr/local/bin/agentgateway-controller
""",
# Live update: sync Go binaries
live_update=[
# Sync Go code changes
sync('./tools/tilt/agentgateway-controller', '/usr/local/bin/agentgateway-controller'),
],
only=[
'./agentgateway-controller',
],
)
# =============================================================================
# Deploy via Helm
# =============================================================================
# Deploy AgentGateway via Helm
k8s_yaml(helm(
'controller/install/helm/agentgateway',
name='agentgateway',
namespace=install_namespace,
set=[
'image.registry=' + image_registry,
'image.tag=' + version,
'image.pullPolicy=IfNotPresent',
'controller.image.repository=agentgateway-controller',
'controller.image.tag=' + version,
'controller.replicaCount=1',
'controller.logLevel=debug',
'proxy.image.repository=agentgateway',
'proxy.image.tag=' + version,
],
values=[config.main_dir + '/controller/hack/helm/dev.yaml'] if os.path.exists(config.main_dir + '/controller/hack/helm/dev.yaml') else [],
))
k8s_resource('agentgateway',
resource_deps=['go-compile-controller'])
# =============================================================================
# Data Plane (Rust-based proxy)
# =============================================================================
# Use cross to consistently build a Linux binary (which can run on Kind)
# regardless of whether the local machine is Linux or macOS
local_resource(
'rust-compile-dataplane',
cross_env + 'cross build --target ' + rust_target +
' && if [ -f "./tools/tilt/agentgateway" ]; then rm "./tools/tilt/agentgateway"; fi' +
' && mv ./target/' + rust_target + '/debug/agentgateway ./tools/tilt/agentgateway',
deps=['./crates',
'./Cargo.toml',
'./Cargo.lock',
'./.cargo'])
#
# Build data plane Docker image
docker_build(
'agentgateway',
context='./tools/tilt/',
dockerfile_contents="""
FROM ubuntu:24.04
COPY start.sh /scripts/start.sh
COPY restart.sh /scripts/restart.sh
COPY agentgateway /usr/local/bin/
ENTRYPOINT ["/scripts/start.sh", "/usr/local/bin/agentgateway"]
""",
live_update=[
sync('./tools/tilt/agentgateway', '/usr/local/bin/agentgateway'),
run('/scripts/restart.sh'),
],
only=[
'./agentgateway',
'./start.sh',
'./restart.sh',
],
)
k8s_kind('AgentgatewayParameters', image_object={'json_path': '{.spec.image}', 'repo_field': 'repository', 'tag_field': 'tag'})
k8s_kind('Gateway', pod_readiness='wait')
k8s_yaml(blob("""
apiVersion: agentgateway.dev/v1alpha1
kind: AgentgatewayParameters
metadata:
name: dataplane-dev-gwparams
spec:
image:
registry: "" # tilt will fill in the registry in the repository field, so leave it blank here (othewise it will be duplicated)
repository: agentgateway
tag: """ + version + """
deployment:
spec:
template:
spec:
containers:
# Delete container-level securityContext so that Tilt can apply live updates
# (need root user, and file system to be writable for live updates)
- name: agentgateway
securityContext:
$patch: delete
---
kind: Gateway
apiVersion: gateway.networking.k8s.io/v1
metadata:
name: tilt-gw
spec:
gatewayClassName: agentgateway
infrastructure:
parametersRef:
group: agentgateway.dev
kind: AgentgatewayParameters
name: dataplane-dev-gwparams
listeners:
- name: http
protocol: HTTP
port: 8080
"""))
k8s_resource(workload='dataplane-dev-gwparams', extra_pod_selectors={"gateway.networking.k8s.io/gateway-name":"tilt-gw"},
resource_deps=['rust-compile-dataplane'])