-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathjustfile
More file actions
416 lines (357 loc) · 16 KB
/
justfile
File metadata and controls
416 lines (357 loc) · 16 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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
# Catnip Development Container Management
# Container Build System:
# - Set BUILDER=container to use Apple Container SDK instead of Docker
# - Use 'build-container' for flexible building (Docker by default, Apple Container SDK with BUILDER=container)
# - Use 'build-apple' as a convenience alias for Apple Container SDK
# - Use 'container-start/stop/status' to manage Apple Container system
# Build the keepalive container for CloudFlare Workers
build-keepalive:
@echo "🫀 Building keepalive container..."
docker build -f containers/keepalive/Dockerfile -t keepalive:latest containers/keepalive
@echo "✅ Keepalive container built successfully!"
@echo " Tag: keepalive:latest"
@echo " Test with: docker run --rm -p 8080:8080 keepalive:latest"
# Build the catnip container for the current platform - supports both Docker and Apple Container SDK
# Usage: just build-container [TAG] [CPUS] [MEMORY] [ARGS...]
# Examples:
# just build-container # Use defaults (includes ghcr.io tag)
# just build-container catnip:dev # Custom tag (local only)
# just build-container catnip:dev 8 8192MB # Custom resources
# BUILDER=container just build-container # Use Apple Container SDK
build-container TAG="catnip:latest" CPUS="4" MEMORY="4096MB" *ARGS="":
#!/usr/bin/env bash
set -euo pipefail
# Determine if we should add remote registry tags
# Only add ghcr.io tag for production builds (catnip:latest)
if [ "{{TAG}}" = "catnip:latest" ]; then
REMOTE_TAG="-t ghcr.io/wandb/catnip:latest"
echo "🏷️ Including remote registry tag: ghcr.io/wandb/catnip:latest"
else
REMOTE_TAG=""
echo "📍 Local build only, no remote registry tags"
fi
if [ "${BUILDER:-}" = "container" ]; then
echo "🍎 Building with Apple Container SDK..."
echo " Tag: {{TAG}}"
echo " CPUs: {{CPUS}}"
echo " Memory: {{MEMORY}}"
echo " Args: {{ARGS}}"
container build -f container/Dockerfile -t "{{TAG}}" $REMOTE_TAG --cpus {{CPUS}} --memory {{MEMORY}} {{ARGS}} .
else
echo "🐳 Building with Docker..."
echo " Tag: {{TAG}}"
echo " Args: {{ARGS}}"
docker build -f container/Dockerfile -t "{{TAG}}" $REMOTE_TAG {{ARGS}} .
fi
echo "✅ Build complete! Run with: docker run -it {{TAG}}"
# Build using Apple Container SDK (convenience alias)
build-apple TAG="catnip:latest" CPUS="4" MEMORY="4096MB" *ARGS="":
#!/usr/bin/env bash
set -euo pipefail
export BUILDER=container
just build-container "{{TAG}}" "{{CPUS}}" "{{MEMORY}}" {{ARGS}}
# Build for local development (no remote registry tags)
build-local TAG="catnip:dev" CPUS="4" MEMORY="4096MB" *ARGS="":
#!/usr/bin/env bash
set -euo pipefail
echo "🏠 Building for local development only..."
export BUILDER=container
just build-container "{{TAG}}" "{{CPUS}}" "{{MEMORY}}" {{ARGS}}
# Build with Docker and transfer to Apple Container SDK
build-docker-to-apple TAG="catnip:base" *ARGS="":
#!/usr/bin/env bash
set -euo pipefail
echo "🐳→🍎 Building with Docker and transferring to Apple Container SDK..."
# Build with Docker
echo "🐳 Building with Docker..."
docker build -f container/Dockerfile -t "{{TAG}}" {{ARGS}} .
# Save to tar
echo "💾 Saving Docker image to tar..."
docker save "{{TAG}}" -o "/tmp/{{TAG}}.tar"
# Load into Apple Container SDK
echo "🍎 Loading into Apple Container SDK..."
container images load --input "/tmp/{{TAG}}.tar"
# Clean up
rm "/tmp/{{TAG}}.tar"
echo "✅ Image {{TAG}} now available in Apple Container SDK!"
# Start the Apple Container system service
container-start:
@echo "🍎 Starting Apple Container system service..."
container system start
# Stop the Apple Container system service
container-stop:
@echo "🍎 Stopping Apple Container system service..."
container system stop
# Check Apple Container system status
container-status:
@echo "🍎 Apple Container system status:"
container system status
# List local container images
container-images:
@echo "📦 Local container images:"
container images list
# Update language versions to latest stable and rebuild
update-versions:
@echo "🔄 Updating language versions..."
./scripts/update-versions.sh
# Build for multiple architectures (requires buildx)
build-multi:
@echo "🏗️ Building catnip container for multiple architectures..."
docker buildx build -f container/Dockerfile --platform linux/amd64,linux/arm64 -t catnip:latest --load .
@echo "✅ Multi-arch build complete!"
# Run the container interactively
run:
@echo "🚀 Starting catnip container..."
docker run -it --rm -v catnip-state:/volume -e ANTHROPIC_API_KEY=$ANTHROPIC_API_KEY -p 8080:8080 catnip-dev
# Run the container in development mode with hot reloading (interactive)
run-dev: build-dev
@echo "🚀 Starting catnip full-stack development environment..."
@echo " 📱 Frontend: http://localhost:5173"
@echo " 🔧 Backend: http://localhost:6369"
@echo " 📚 API Docs: http://localhost:6369/swagger/"
@echo " Press Ctrl+C to stop both servers"
docker run -it --rm \
--name catnip-dev \
-v catnip-state:/volume \
-v ~/.claude/ide:/volume/.claude/ide \
-v $(pwd):/live/catnip \
-v catnip-dev-node-modules:/live/catnip/node_modules \
-e CLAUDE_CODE_IDE_HOST_OVERRIDE=host.docker.internal \
-e CATNIP_SESSION=catnip \
-e CATNIP_USERNAME=$USER \
-e ANTHROPIC_API_KEY=$ANTHROPIC_API_KEY \
-p 6369:6369 \
-p 5173:5173 \
catnip-dev:dev
# Run the container in development mode (non-interactive, for testing)
test-dev: build-dev
@echo "🧪 Testing catnip development environment..."
docker run --rm \
-v $(pwd):/live/catnip \
-v catnip-dev-node-modules:/live/catnip/node_modules \
-e ANTHROPIC_API_KEY=$ANTHROPIC_API_KEY \
-p 8080:8080 \
-p 5173:5173 \
catnip-dev:dev &
@echo "✅ Development servers started in background"
# Build development container with Air support
build-dev:
#!/usr/bin/env bash
set -euo pipefail
echo "🏗️ Building catnip development container..."
if [ "${BUILDER:-}" = "container" ]; then
# Check if catnip:base exists in Apple Container SDK
if ! container images list | grep -q "^catnip.*base"; then
echo "❌ catnip:base not found in Apple Container SDK"
echo "💡 Run: just build-docker-to-apple catnip:base"
echo " This will build catnip:base with Docker and transfer it to Apple Container SDK"
exit 1
fi
echo "✅ Found catnip:base in Apple Container SDK"
echo "🍎 Building dev container with Apple Container SDK..."
container build -f container/Dockerfile.dev -t catnip-dev:dev --build-arg BUILDKIT_INLINE_CACHE=1 .
else
echo "🐳 Building base catnip image with Docker..."
just build-container catnip:base
echo "🐳 Building dev container with Docker..."
docker build -f container/Dockerfile.dev -t catnip-dev:dev --build-arg BUILDKIT_INLINE_CACHE=1 .
fi
echo "✅ Development build complete!"
# Clean development node_modules volume
clean-dev-volumes:
@echo "🧹 Cleaning up development volumes..."
docker volume rm catnip-dev-node-modules 2>/dev/null || true
@echo "✅ Development volumes cleaned!"
# Force rebuild development container (clears cache layers)
rebuild-dev: clean-containers clean-dev-volumes
#!/usr/bin/env bash
set -euo pipefail
echo "🔄 Force rebuilding development container..."
if [ "${BUILDER:-}" = "container" ]; then
# Check if catnip:base exists in Apple Container SDK
if ! container images list | grep -q "^catnip.*base"; then
echo "❌ catnip:base not found in Apple Container SDK"
echo "💡 Run: just build-docker-to-apple catnip:base"
echo " This will build catnip:base with Docker and transfer it to Apple Container SDK"
exit 1
fi
echo "✅ Found catnip:base in Apple Container SDK"
echo "🍎 Force rebuilding dev container with Apple Container SDK..."
container build --no-cache -f container/Dockerfile.dev -t catnip-dev:dev .
else
echo "🐳 Force rebuilding base catnip image with Docker..."
just build-container catnip:base 4 4096MB --no-cache
echo "🐳 Force rebuilding dev container with Docker..."
docker build --no-cache -f container/Dockerfile.dev -t catnip-dev:dev .
fi
echo "✅ Development container rebuilt!"
# Run the container with a custom command
run-cmd CMD:
@echo "🚀 Running command in catnip container: {{CMD}}"
docker run -it --rm catnip-dev {{CMD}}
# Format all TypeScript/JavaScript files
format-ts:
pnpm format
# Format only changed TypeScript/JavaScript files
format-ts-changed:
pnpm format:changed
# Format all Go files in container
format-go:
cd container && just format-go
# Format only changed Go files in container
format-go-changed:
cd container && just format-go-changed
# Format all code (TypeScript and Go)
format-all: format-ts format-go
@echo "✅ All code formatted!"
# Format only changed files (TypeScript and Go)
format-changed: format-ts-changed format-go-changed
@echo "✅ Changed files formatted!"
# Clean up container images
clean-containers:
@echo "🧹 Cleaning up catnip container images..."
docker rmi catnip-dev catnip-dev:dev 2>/dev/null || true
@echo "✅ Cleanup complete!"
# Clean everything (containers + dev volumes)
clean-all: clean-containers clean-dev-volumes
@echo "✅ Complete cleanup finished!"
# Show container information
info:
@echo "📋 Catnip Container Information:"
@echo " Image: catnip-dev"
@echo " Platform: $(uname -m)"
@echo " Build context: ./container/"
@echo ""
@echo "Available commands:"
@echo ""
@echo "Container Management:"
@echo " just build-container - Build production container (Docker by default)"
@echo " just build-apple - Build with Apple Container SDK"
@echo " just build-local - Build for local dev only (no remote registry)"
@echo " just run - Run container interactively"
@echo " just container-start - Start Apple Container system service"
@echo " just container-stop - Stop Apple Container system service"
@echo " just container-status - Check Apple Container system status"
@echo " just container-images - List local container images"
@echo ""
@echo "Development:"
@echo " just dev - Local dev mode (frontend + backend with port allocation)"
@echo " just run-dev - Full-stack dev (interactive, Ctrl+C to stop)"
@echo " just test-dev - Test development environment (background)"
@echo " just build-dev - Build development container (with pre-warmed cache)"
@echo " just rebuild-dev - Force rebuild dev container (clears cache)"
@echo ""
@echo "Go Server (use container:: prefix):"
@echo " just container::build - Build Go server binary"
@echo " just container::dev - Run Go server locally with Air"
@echo " just container::test - Run Go tests"
@echo ""
@echo "Code Formatting:"
@echo " just format-all - Format all TypeScript and Go files"
@echo " just format-changed - Format only changed files"
@echo " just format-ts - Format all TypeScript/JavaScript files"
@echo " just format-ts-changed - Format only changed TS/JS files"
@echo " just format-go - Format all Go files"
@echo " just format-go-changed - Format only changed Go files"
@echo ""
@echo "Release Management:"
@echo " just release - Create minor release (local tag)"
@echo " just release --patch - Create patch release"
@echo " just release --major - Create major release"
@echo " just release --dev - Create dev release"
@echo " just release-extension - Create VS Code extension release"
@echo " just release-extension --push - Create and publish extension"
@echo " Add --push --message=\"...\" to actually release (binary)"
@echo ""
@echo "Cleanup:"
@echo " just clean-containers - Remove container images"
@echo " just clean-dev-volumes - Remove development volumes"
@echo " just clean-all - Clean everything"
# Release management (defaults to minor version bump)
release *ARGS="":
@echo "🚀 Creating release..."
pnpm tsx scripts/release.ts {{ARGS}}
# VS Code extension release management
release-extension *ARGS="":
@echo "🚀 Creating VS Code extension release..."
pnpm tsx scripts/release-extension.ts {{ARGS}}
# Development mode - runs both frontend and backend with proper port allocation
dev:
#!/usr/bin/env bash
set -euo pipefail
# Extract first port from PORTZ if available, otherwise use default
if [ -n "${PORTZ:-}" ]; then
VITE_PORT=$(echo "$PORTZ" | jq -r '.[0] // 5173')
echo "🌐 Using VITE_PORT=$VITE_PORT from PORTZ array"
else
VITE_PORT=5173
echo "🌐 Using default VITE_PORT=$VITE_PORT (no PORTZ found)"
fi
if [ -f /opt/catnip/catnip.pid ]; then
echo "🔄 catnip.pid file found, stopping catnip server..."
bash "/opt/catnip/bin/catnip-stop.sh"
fi
# Show port info
echo "🔗 Backend PORT: ${PORT:-6369}"
echo "🔗 Frontend VITE_PORT: $VITE_PORT"
echo ""
# Export VITE_PORT for both processes
export VITE_PORT=$VITE_PORT
export VITE_DEV_SERVER=http://localhost:$VITE_PORT
# Function to cleanup background processes
cleanup() {
echo "🛑 Stopping development servers..."
kill $(jobs -p) 2>/dev/null || true
wait
echo "✅ Development servers stopped"
}
# Set up signal handlers
trap cleanup EXIT INT TERM
# Start pnpm dev (frontend) in background
echo "🚀 Starting pnpm dev (frontend) on port $VITE_PORT..."
pnpm dev &
PNPM_PID=$!
# Give vite a moment to start
sleep 2
# Start Air (backend) in background
echo "🚀 Starting Air (backend) on port ${PORT:-6369}..."
export CATNIP_DEV=true
cd container && air &
AIR_PID=$!
# Display helpful info
echo ""
echo "🎉 Development servers started!"
echo " 📱 Frontend: http://localhost:$VITE_PORT"
echo " 🔧 Backend: http://localhost:${PORT:-6369}"
echo " 📚 API Docs: http://localhost:${PORT:-6369}/docs/"
echo ""
echo "Press Ctrl+C to stop both servers"
echo ""
# Wait for either process to exit
wait
# Upgrade container image to latest version and update wrangler.jsonc
upgrade-image:
#!/usr/bin/env bash
set -euo pipefail
# Get latest version from git tags
VERSION=$(git describe --tags --abbrev=0 2>/dev/null | sed 's/^v//' || echo "0.1.0")
echo "🏷️ Latest version: $VERSION"
# Push container to Cloudflare registry
echo "🚀 Pushing wandb/catnip:$VERSION to Cloudflare registry..."
wrangler containers push wandb/catnip:$VERSION
# Get the new registry URL
NEW_IMAGE_URL="registry.cloudflare.com/0081e9dfbeb0e1a212ec5101e3c8768a/wandb/catnip:$VERSION"
echo "📝 New image URL: $NEW_IMAGE_URL"
# Update wrangler.jsonc with new image URL
echo "🔄 Updating wrangler.jsonc..."
# Create a temporary file for the updated content
TMP_FILE=$(mktemp)
# Use sed to replace all image URLs in wrangler.jsonc
sed "s|registry\.cloudflare\.com/0081e9dfbeb0e1a212ec5101e3c8768a/wandb/catnip:[^\"]*|$NEW_IMAGE_URL|g" wrangler.jsonc > "$TMP_FILE"
# Replace the original file
mv "$TMP_FILE" wrangler.jsonc
echo "✅ Updated container image references in wrangler.jsonc to version $VERSION"
echo "🔍 Review changes with: git diff wrangler.jsonc"
# Default recipe
default:
@just --list