Compare commits

...

1 Commits

Author SHA1 Message Date
Jon Leopard
d04bfe418b chore: add k8s local development environment with Traefik ingress
Add k8s-based local development setup as an alternative to Sail, providing namespace isolation per branch/worktree.

**Features:**
- K8s namespace per branch with isolated resources (PostgreSQL, Redis, Reverb)
- Traefik ingress for vanity URLs (*.cannabrands.test)
- Vite HMR support through ingress WebSocket routing
- Volume mounts for instant code changes (manual refresh workflow)
- Makefile targets: k-dev, k-vite, k-down, k-seed, k-migrate-fresh

**Changes:**
- Makefile: Add k8s targets for local development
- k8s/local/deployment.yaml: Update volume mounts for project root
- k8s/local/ingress.yaml: Fix Traefik ingress annotations
- vite.config.js: Add HMR config for k8s ingress routing
- package.json: Use vite --host 0.0.0.0 for container compatibility
- .gitignore: Exclude .worktrees/ directory

**Usage:**
```bash
# Create k3d cluster with volume mount
k3d cluster create dev \
  -p "80:80@loadbalancer" \
  -p "443:443@loadbalancer" \
  --volume "\$(pwd):/project-root@server:0"

# Start environment
make k-dev

# Start Vite
make k-vite
```

**Note:** HMR auto-detection doesn't work on macOS + Colima due to filesystem event propagation limitations (same as Sail). Manual browser refresh (Cmd+R) required to see changes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-04 10:20:22 -07:00
6 changed files with 25 additions and 17 deletions

1
.gitignore vendored
View File

@@ -57,3 +57,4 @@ core.*
!resources/**/*.png
!resources/**/*.jpg
!resources/**/*.jpeg
.worktrees/

View File

@@ -10,12 +10,9 @@
# --port "80:80@loadbalancer" \
# --port "443:443@loadbalancer" \
# --volume $(pwd)/.worktrees:/worktrees \
# --volume $(pwd):/project-root \
# --volume k3d-dev-images:/k3d/images \
# --k3s-arg "--disable=traefik@server:0"
# --volume $(pwd):/project-root
#
# Then install nginx ingress:
# kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/cloud/deploy.yaml
# k3d includes Traefik ingress controller by default
# Detect if we're in a worktree or project root
GIT_DIR := $(shell git rev-parse --git-dir 2>/dev/null)
@@ -142,7 +139,7 @@ k-composer: ## Run composer (usage: make k-composer CMD="install")
k-vite: ## Run Vite dev server in k8s pod
@echo "🎨 Starting Vite dev server in pod..."
@echo " Access at: http://vite.$(K8S_HOST)"
@kubectl -n $(K8S_NS) exec deploy/web -- npm run dev
@kubectl -n $(K8S_NS) exec deploy/web -- sh -c "VITE_HMR_HOST=vite.$(K8S_HOST) npm run dev"
k-test: ## Run tests in k8s pod
@echo "🧪 Running tests in k8s pod..."

View File

@@ -81,9 +81,6 @@ spec:
echo "Installing/updating npm dependencies..."
npm install --no-audit --no-fund
echo "Building frontend assets..."
npm run build
echo "Running migrations..."
php artisan migrate --force
@@ -99,25 +96,25 @@ spec:
resources:
requests:
memory: "512Mi"
cpu: "500m"
cpu: "250m"
limits:
memory: "1Gi"
cpu: "1000m"
cpu: "500m"
livenessProbe:
httpGet:
path: /
path: /register
port: 80
initialDelaySeconds: 300
initialDelaySeconds: 90
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 6
readinessProbe:
httpGet:
path: /
path: /register
port: 80
initialDelaySeconds: 240
initialDelaySeconds: 60
periodSeconds: 5
timeoutSeconds: 3
failureThreshold: 6

View File

@@ -4,7 +4,7 @@ metadata:
name: web
namespace: ${NS}
spec:
ingressClassName: nginx
ingressClassName: traefik
rules:
# Main application domain
- host: ${K8S_HOST}

View File

@@ -3,7 +3,7 @@
"type": "module",
"scripts": {
"build": "vite build",
"dev": "vite",
"dev": "vite --host 0.0.0.0",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0 && sed -i.bak 's/\\/commits\\//\\/commit\\//g' CHANGELOG.md && rm CHANGELOG.md.bak"
},
"devDependencies": {

View File

@@ -10,4 +10,17 @@ export default defineConfig({
refresh: true,
}),
],
server: {
host: "0.0.0.0", // Listen on all interfaces (required for Docker/k8s)
port: 5173,
strictPort: false, // Allow fallback port if 5173 is taken
allowedHosts: [".cannabrands.test"], // Allow all subdomains
hmr: {
// K8s mode: use vite subdomain through ingress (port 80)
// Local mode: use localhost:5173
host: process.env.VITE_HMR_HOST || "localhost",
clientPort: process.env.VITE_HMR_HOST ? 80 : 5173,
protocol: "http",
},
},
});