-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathTiltfile
More file actions
211 lines (185 loc) · 8.07 KB
/
Tiltfile
File metadata and controls
211 lines (185 loc) · 8.07 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
201
202
203
204
205
206
207
208
209
210
211
# Only allow this Tiltfile to run against the local k3d cluster.
# The kubeconfig is written to the project root by local-setup/dev-setup.sh
# and passed in via KUBECONFIG env var when running 'make dev'.
allow_k8s_contexts('k3d-core-dev')
default_registry('k3d-registry.localhost:5001')
NAMESPACE = 'core-local'
# ── Helpers ───────────────────────────────────────────────────────────────────
# Read .env.tilt for developer-specific secrets (OAuth credentials, etc.)
# Copy .env.tilt.example → .env.tilt and fill in the values.
def load_env(content):
env = {}
for line in content.splitlines():
line = line.strip()
if line and not line.startswith('#') and '=' in line:
k, _, v = line.partition('=')
env[k.strip()] = v.strip()
return env
_secrets = load_env(str(read_file('.env.tilt', default = '')))
def secret(key, default = ''):
return _secrets.get(key, default)
# ── Namespace ─────────────────────────────────────────────────────────────────
# local_resource gives a reliable named anchor that other resources can depend on.
# k8s_yaml + k8s_resource(objects=...) is flaky for plain Namespace objects.
local_resource('namespace',
cmd = 'kubectl --kubeconfig kubeconfig.yaml apply -f local-setup/infra/namespace.yaml',
deps = ['local-setup/infra/namespace.yaml'],
labels = ['infra'],
)
# ── Persistent volumes ────────────────────────────────────────────────────────
# local_resource prevents Tilt from deleting PVCs during reconciliation.
local_resource('pvcs',
cmd = 'kubectl --kubeconfig kubeconfig.yaml apply -f local-setup/infra/pvcs.yaml',
deps = ['local-setup/infra/pvcs.yaml'],
resource_deps = ['namespace'],
labels = ['infra'],
)
# ── Databases & messaging ─────────────────────────────────────────────────────
k8s_yaml([
'local-setup/infra/postgres.yaml',
'local-setup/infra/rabbitmq.yaml',
])
k8s_resource('postgres',
port_forwards = ['5432:5432'],
resource_deps = ['pvcs'],
labels = ['infra'],
)
k8s_resource('rabbitmq',
port_forwards = ['5672:5672', '15672:15672'],
resource_deps = ['namespace'],
labels = ['infra'],
)
# ── Object storage (SeaweedFS) ────────────────────────────────────────────────
k8s_yaml([
'local-setup/infra/seaweedfs-config.yaml',
'local-setup/infra/seaweedfs.yaml',
'local-setup/infra/seaweedfs-init.yaml',
'local-setup/infra/s3-proxy.yaml',
])
# Attach the s3 credentials ConfigMap to the seaweedfs workload so Tilt
# applies it before the pod starts (and re-applies it on changes).
k8s_resource('seaweedfs',
port_forwards = [
'9001:9333', # Master UI — http://localhost:9001
'9002:8888', # Filer UI — http://localhost:9002
],
objects = ['seaweedfs-s3-config:ConfigMap:' + NAMESPACE],
resource_deps = ['pvcs'],
labels = ['infra'],
)
# Attach the CORS/policy ConfigMap to the init Job.
k8s_resource('seaweedfs-init',
objects = ['seaweedfs-cors-configs:ConfigMap:' + NAMESPACE],
resource_deps = ['seaweedfs'],
labels = ['infra'],
)
# nginx proxy in front of SeaweedFS S3 — adds Access-Control-Allow-Private-Network: true
# so browsers on public HTTPS origins (e.g. the visualizer) can fetch from localhost:9000.
k8s_resource('s3-proxy',
port_forwards = ['9000:80'], # S3 API — http://localhost:9000
objects = ['s3-proxy-config:ConfigMap:' + NAMESPACE],
resource_deps = ['seaweedfs'],
labels = ['infra'],
)
# ── Backend: API ──────────────────────────────────────────────────────────────
docker_build('api', './api',
dockerfile = './api/Dockerfile.dev',
ignore = ['helm', 'dist', '.env*', '*.md'],
live_update = [
sync('./api/src', '/app/src'),
run(
'cd /app && pnpm install --frozen-lockfile',
trigger = ['./api/package.json', './api/pnpm-lock.yaml'],
),
],
)
k8s_yaml(helm(
'api/helm',
name = 'api',
namespace = NAMESPACE,
values = ['local-setup/local-values/api.yaml'],
set = [
'secrets.CLIENT_GITHUB_SECRET=' + secret('CLIENT_GITHUB_SECRET'),
'secrets.FORTYTWO_CLIENT_SECRET=' + secret('FORTYTWO_CLIENT_SECRET'),
'env.CLIENT_GITHUB_ID=' + secret('CLIENT_GITHUB_ID'),
'env.FORTYTWO_CLIENT_ID=' + secret('FORTYTWO_CLIENT_ID'),
],
))
k8s_resource('api',
port_forwards = ['4000:4000'],
resource_deps = ['postgres', 'rabbitmq'],
labels = ['app'],
)
# ── Backend: github-service ───────────────────────────────────────────────────
docker_build('github-service', './github-service',
dockerfile = './github-service/Dockerfile.dev',
ignore = ['helm', 'dist', '.env*', '*.md'],
live_update = [
sync('./github-service/src', '/app/src'),
run(
'cd /app && pnpm install --frozen-lockfile',
trigger = ['./github-service/package.json', './github-service/pnpm-lock.yaml'],
),
],
)
k8s_yaml(helm(
'github-service/helm',
name = 'github-service',
namespace = NAMESPACE,
values = ['local-setup/local-values/github-service.yaml'],
))
k8s_resource('github-service',
resource_deps = ['rabbitmq'],
labels = ['app'],
)
# ── Backend: k8s-service ──────────────────────────────────────────────────────
# Full Docker rebuild on any change — Go build cache keeps it fast.
docker_build('k8s-service', './k8s-service',
dockerfile = './k8s-service/Dockerfile',
)
k8s_yaml(helm(
'k8s-service/helm',
name = 'k8s-service',
namespace = NAMESPACE,
values = ['local-setup/local-values/k8s-service.yaml'],
))
k8s_resource('k8s-service',
resource_deps = ['rabbitmq', 'seaweedfs-init'],
labels = ['app'],
)
# ── Frontend ──────────────────────────────────────────────────────────────────
docker_build('frontend', './frontend',
dockerfile = './frontend/Dockerfile.dev',
ignore = ['helm', '.next', '.env*'],
live_update = [
sync('./frontend/app', '/app/app'),
sync('./frontend/components', '/app/components'),
sync('./frontend/hooks', '/app/hooks'),
sync('./frontend/layouts', '/app/layouts'),
sync('./frontend/lib', '/app/lib'),
sync('./frontend/styles', '/app/styles'),
sync('./frontend/types', '/app/types'),
sync('./frontend/contexts', '/app/contexts'),
sync('./frontend/config', '/app/config'),
sync('./frontend/public', '/app/public'),
sync('./frontend/content', '/app/content'),
run(
'cd /app && pnpm install --frozen-lockfile',
trigger = ['./frontend/package.json', './frontend/pnpm-lock.yaml'],
),
],
)
k8s_yaml(helm(
'frontend/helm',
name = 'frontend',
namespace = NAMESPACE,
values = ['local-setup/local-values/frontend.yaml'],
set = [
'env.CLIENT_GITHUB_ID=' + secret('CLIENT_GITHUB_ID'),
],
))
k8s_resource('frontend',
port_forwards = ['3000:3000'],
resource_deps = ['api'],
labels = ['app'],
)