Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 119 additions & 17 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,7 @@ tasks:
cmds:
- tilt logs

# Development tasks
dev:items-service:
desc: Run items-service in development mode with hot reload
dir: apps/items-service
cmds:
- bun install && bun run dev

dev:items-service:postgres:
desc: Run items-service locally with PostgreSQL connection (requires port-forward)
dir: apps/items-service
cmds:
Expand All @@ -77,6 +70,65 @@ tasks:
cmds:
- bun install && bun run dev

dev:semcache-service:
desc: Run semcache-service locally with Air + K8s PostgreSQL (auto port-forwards)
dir: apps/semcache-service
cmds:
- |
echo "🔥 Starting semcache-service with Air hot reload + K8s PostgreSQL..."
echo "📝 Edit any .go file and see changes in ~1 second!"
echo ""

# Check if port-forward is already running
if lsof -Pi :5432 -sTCP:LISTEN -t >/dev/null 2>&1; then
echo "✅ PostgreSQL port-forward already running on localhost:5432"
else
echo "🔌 Starting PostgreSQL port-forward in background..."
kubectl port-forward svc/postgres 5432:5432 > /dev/null 2>&1 &
PF_PID=$!
echo " Port-forward PID: $PF_PID"
sleep 2

# Verify port-forward is working
if ! lsof -Pi :5432 -sTCP:LISTEN -t >/dev/null 2>&1; then
echo "❌ Failed to start port-forward"
exit 1
fi
echo "✅ Port-forward established"
fi

echo ""
if ! command -v air &> /dev/null; then
echo "Installing Air..."
go install github.com/air-verse/air@latest
fi

set -a
source ../../.env
set +a
export PORT=8090
export DB_HOST=localhost
export DB_PORT=5432
export DB_USER=$POSTGRES_USER
export DB_PASSWORD=$POSTGRES_PASSWORD
export DB_NAME=$POSTGRES_DB
export DB_SSLMODE=disable
export OTEL_ENABLED=false

echo "🚀 Starting Air hot reload on port 8090..."
echo " http://localhost:8090/health"
echo " http://localhost:8090/v1/greetings"
echo ""
air -c .air.toml

# dev:stop-port-forwards:
# desc: Stop all kubectl port-forward processes
# cmds:
# - |
# echo "🛑 Stopping all kubectl port-forward processes..."
# pkill -f "kubectl port-forward" || echo "No port-forwards running"
# echo "✅ Done"

# Docker tasks
docker:build:items-service:
desc: Build Docker image for items-service
Expand All @@ -88,11 +140,17 @@ tasks:
cmds:
- docker build -t website-app:local ./apps/website-app

docker:build:semcache-service:
desc: Build Docker image for semcache-service
cmds:
- docker build -t semcache-service:local ./apps/semcache-service

docker:build:all:
desc: Build Docker images for all apps
cmds:
- task: docker:build:items-service
- task: docker:build:website-app
- task: docker:build:semcache-service

docker:run:items-service:
desc: Run items-service Docker container locally
Expand All @@ -104,6 +162,11 @@ tasks:
cmds:
- docker run --rm -p 8080:8080 website-app:local

docker:run:semcache-service:
desc: Run semcache-service Docker container locally
cmds:
- docker run --rm -p 8080:8080 semcache-service:local

# Terraform tasks
tf:init:
desc: Initialize Terraform
Expand Down Expand Up @@ -205,6 +268,11 @@ tasks:
cmds:
- kubectl --kubeconfig={{.KUBECONFIG}} logs -l app=website-app --tail=100 -f

k8s:logs:semcache-service:
desc: Get logs from semcache-service
cmds:
- kubectl --kubeconfig={{.KUBECONFIG}} logs -l app=semcache-service --tail=100 -f

k8s:describe:items-service:
desc: Describe items-service deployment
cmds:
Expand All @@ -215,6 +283,11 @@ tasks:
cmds:
- kubectl --kubeconfig={{.KUBECONFIG}} describe deployment website-app

k8s:describe:semcache-service:
desc: Describe semcache-service deployment
cmds:
- kubectl --kubeconfig={{.KUBECONFIG}} describe deployment semcache-service

# Deployment tasks
deploy:items-service:
desc: Deploy items-service to Kubernetes
Expand All @@ -229,6 +302,14 @@ tasks:
cmds:
- kubectl --kubeconfig={{.KUBECONFIG}} apply -f {{.K8S_DIR}}/apps/website-app-deployment.yaml

deploy:semcache-service:
desc: Deploy semcache-service to Kubernetes
cmds:
- kubectl --kubeconfig={{.KUBECONFIG}} apply -f {{.K8S_DIR}}/apps/semcache-service-deployment.yaml
- echo "✅ semcache-service deployed"
- echo "Waiting for rollout to complete..."
- kubectl --kubeconfig={{.KUBECONFIG}} rollout status deployment/semcache-service --timeout=120s

deploy:headlamp-readonly:
desc: Deploy Headlamp Kubernetes Dashboard (Read-Only Public)
cmds:
Expand All @@ -242,6 +323,7 @@ tasks:
cmds:
- task: deploy:items-service
- task: deploy:website-app
- task: deploy:semcache-service
- task: deploy:headlamp-readonly

deploy:items-service:with-postgres:
Expand Down Expand Up @@ -335,6 +417,11 @@ tasks:
cmds:
- kubectl --kubeconfig={{.KUBECONFIG}} rollout restart deployment/website-app

rollout:restart:semcache-service:
desc: Restart semcache-service deployment
cmds:
- kubectl --kubeconfig={{.KUBECONFIG}} rollout restart deployment/semcache-service

rollout:status:items-service:
desc: Check rollout status for items-service
cmds:
Expand All @@ -345,6 +432,11 @@ tasks:
cmds:
- kubectl --kubeconfig={{.KUBECONFIG}} rollout status deployment/website-app

rollout:status:semcache-service:
desc: Check rollout status for semcache-service
cmds:
- kubectl --kubeconfig={{.KUBECONFIG}} rollout status deployment/semcache-service

# DNS and networking tasks
dns:clear-cache:
desc: Clear DNS cache (macOS)
Expand All @@ -369,21 +461,31 @@ tasks:
cmds:
- curl -s https://roussev.com/health | jq

health:semcache-service:
desc: Check health of semcache-service (local)
cmds:
- curl -s https://app.roussev.com/semcache/v1/health | jq

clean:docker:
desc: Clean Docker images
cmds:
- docker rmi items-service:local website-app:local || true
- docker rmi items-service:local website-app:local semcache-service:local || true

# Port forwarding tasks
port-forward:items-service:
desc: Port forward to items-service pod
cmds:
- kubectl --kubeconfig={{.KUBECONFIG}} port-forward svc/items-service 8080:80

port-forward:website-app:
desc: Port forward to website-app pod
cmds:
- kubectl --kubeconfig={{.KUBECONFIG}} port-forward svc/website-app 8080:80
# port-forward:items-service:
# desc: Port forward to items-service pod
# cmds:
# - kubectl --kubeconfig={{.KUBECONFIG}} port-forward svc/items-service 8080:80

# port-forward:website-app:
# desc: Port forward to website-app pod
# cmds:
# - kubectl --kubeconfig={{.KUBECONFIG}} port-forward svc/website-app 8080:80

# port-forward:semcache-service:
# desc: Port forward to semcache-service pod
# cmds:
# - kubectl --kubeconfig={{.KUBECONFIG}} port-forward svc/semcache-service 8080:80

# SSH tasks
ssh:
Expand Down
34 changes: 34 additions & 0 deletions Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,37 @@ k8s_resource(
]
)

# ============================================================================
# Semcache Service (Go + Echo)
# ============================================================================

# Build Docker image for semcache-service (using dev Dockerfile with hot reload)
docker_build(
'semcache-service',
context='./apps/semcache-service',
dockerfile='./apps/semcache-service/Dockerfile.dev',
live_update=[
sync('./apps/semcache-service', '/app'),
]
)

# Deploy semcache-service
k8s_yaml('infra/k8s/local/semcache-service-local.yaml')

# Configure semcache-service resource
k8s_resource(
'semcache-service',
port_forwards='8083:8080',
labels=['apps'],
resource_deps=['postgres', 'jaeger', 'prometheus'],
links=[
link('http://localhost:8083/docs', 'API Documentation (Swagger UI)'),
link('http://localhost:8083/health', 'Health Check'),
link('http://localhost:8083/v1/create', 'API - Create (POST)'),
link('http://localhost:8083/v1/search', 'API - Search (POST)'),
]
)

# ============================================================================
# Headlamp Kubernetes Dashboard (Read-Only)
# ============================================================================
Expand Down Expand Up @@ -217,6 +248,9 @@ Services will be available at:
- Metrics: http://localhost:8081/metrics
🌐 Website App: http://localhost:8082
- Health: http://localhost:8082/health
👋 Hello Service: http://localhost:8083
- Health: http://localhost:8083/health
- API: http://localhost:8083/v1/greetings
👁️ Headlamp: http://localhost:8084 (Read-Only)

📊 Observability:
Expand Down
45 changes: 45 additions & 0 deletions apps/semcache-service/.air.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
root = "."
testdata_dir = "testdata"
tmp_dir = "tmp"

[build]
args_bin = []
bin = "./tmp/main"
cmd = "go build -o ./tmp/main ./cmd/server"
delay = 500 # Faster delay for local dev (500ms vs 1000ms)
exclude_dir = ["assets", "tmp", "vendor", "testdata"]
exclude_file = []
exclude_regex = ["_test.go"]
exclude_unchanged = false
follow_symlink = false
full_bin = ""
include_dir = []
include_ext = ["go", "tpl", "tmpl", "html"]
include_file = []
kill_delay = "0s"
log = "build-errors.log"
poll = false
poll_interval = 0
rerun = false
rerun_delay = 500
send_interrupt = false
stop_on_error = false

[color]
app = ""
build = "yellow"
main = "magenta"
runner = "green"
watcher = "cyan"

[log]
main_only = false
time = true

[misc]
clean_on_exit = false

[screen]
clear_on_rebuild = true # Clear screen on rebuild for cleaner output
keep_scroll = true

38 changes: 38 additions & 0 deletions apps/semcache-service/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool
*.out

# Go workspace file
go.work

# Dependency directories
vendor/

# Air temporary files
tmp/
build-errors.log

# IDE
.idea/
.vscode/
*.swp
*.swo
*~

# OS
.DS_Store
Thumbs.db

# Environment variables
.env
.env.local

40 changes: 40 additions & 0 deletions apps/semcache-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Build stage
FROM golang:1.25-alpine AS builder

WORKDIR /app

# Install build dependencies
RUN apk add --no-cache git

# Copy go mod files
COPY go.mod go.sum* ./

# Download dependencies
RUN go mod download

# Copy source code
COPY . .

# Build the application
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o server ./cmd/server

# Runtime stage
FROM alpine:3.19

# Install ca-certificates for HTTPS
RUN apk --no-cache add ca-certificates

WORKDIR /app

# Copy binary from builder
COPY --from=builder /app/server .

# Expose port
EXPOSE 8080

# Set environment variables
ENV PORT=8080

# Run the application
CMD ["./server"]

Loading