Skip to content

Commit 827b5e8

Browse files
Merge pull request #19 from nextinterfaces/go-service-01
Adds Semcache go service
2 parents 61ade0f + fc78cab commit 827b5e8

File tree

19 files changed

+1919
-20
lines changed

19 files changed

+1919
-20
lines changed

Taskfile.yml

Lines changed: 119 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,7 @@ tasks:
4747
cmds:
4848
- tilt logs
4949

50-
# Development tasks
5150
dev:items-service:
52-
desc: Run items-service in development mode with hot reload
53-
dir: apps/items-service
54-
cmds:
55-
- bun install && bun run dev
56-
57-
dev:items-service:postgres:
5851
desc: Run items-service locally with PostgreSQL connection (requires port-forward)
5952
dir: apps/items-service
6053
cmds:
@@ -77,6 +70,65 @@ tasks:
7770
cmds:
7871
- bun install && bun run dev
7972

73+
dev:semcache-service:
74+
desc: Run semcache-service locally with Air + K8s PostgreSQL (auto port-forwards)
75+
dir: apps/semcache-service
76+
cmds:
77+
- |
78+
echo "🔥 Starting semcache-service with Air hot reload + K8s PostgreSQL..."
79+
echo "📝 Edit any .go file and see changes in ~1 second!"
80+
echo ""
81+
82+
# Check if port-forward is already running
83+
if lsof -Pi :5432 -sTCP:LISTEN -t >/dev/null 2>&1; then
84+
echo "✅ PostgreSQL port-forward already running on localhost:5432"
85+
else
86+
echo "🔌 Starting PostgreSQL port-forward in background..."
87+
kubectl port-forward svc/postgres 5432:5432 > /dev/null 2>&1 &
88+
PF_PID=$!
89+
echo " Port-forward PID: $PF_PID"
90+
sleep 2
91+
92+
# Verify port-forward is working
93+
if ! lsof -Pi :5432 -sTCP:LISTEN -t >/dev/null 2>&1; then
94+
echo "❌ Failed to start port-forward"
95+
exit 1
96+
fi
97+
echo "✅ Port-forward established"
98+
fi
99+
100+
echo ""
101+
if ! command -v air &> /dev/null; then
102+
echo "Installing Air..."
103+
go install github.com/air-verse/air@latest
104+
fi
105+
106+
set -a
107+
source ../../.env
108+
set +a
109+
export PORT=8090
110+
export DB_HOST=localhost
111+
export DB_PORT=5432
112+
export DB_USER=$POSTGRES_USER
113+
export DB_PASSWORD=$POSTGRES_PASSWORD
114+
export DB_NAME=$POSTGRES_DB
115+
export DB_SSLMODE=disable
116+
export OTEL_ENABLED=false
117+
118+
echo "🚀 Starting Air hot reload on port 8090..."
119+
echo " http://localhost:8090/health"
120+
echo " http://localhost:8090/v1/greetings"
121+
echo ""
122+
air -c .air.toml
123+
124+
# dev:stop-port-forwards:
125+
# desc: Stop all kubectl port-forward processes
126+
# cmds:
127+
# - |
128+
# echo "🛑 Stopping all kubectl port-forward processes..."
129+
# pkill -f "kubectl port-forward" || echo "No port-forwards running"
130+
# echo "✅ Done"
131+
80132
# Docker tasks
81133
docker:build:items-service:
82134
desc: Build Docker image for items-service
@@ -88,11 +140,17 @@ tasks:
88140
cmds:
89141
- docker build -t website-app:local ./apps/website-app
90142

143+
docker:build:semcache-service:
144+
desc: Build Docker image for semcache-service
145+
cmds:
146+
- docker build -t semcache-service:local ./apps/semcache-service
147+
91148
docker:build:all:
92149
desc: Build Docker images for all apps
93150
cmds:
94151
- task: docker:build:items-service
95152
- task: docker:build:website-app
153+
- task: docker:build:semcache-service
96154

97155
docker:run:items-service:
98156
desc: Run items-service Docker container locally
@@ -104,6 +162,11 @@ tasks:
104162
cmds:
105163
- docker run --rm -p 8080:8080 website-app:local
106164

165+
docker:run:semcache-service:
166+
desc: Run semcache-service Docker container locally
167+
cmds:
168+
- docker run --rm -p 8080:8080 semcache-service:local
169+
107170
# Terraform tasks
108171
tf:init:
109172
desc: Initialize Terraform
@@ -205,6 +268,11 @@ tasks:
205268
cmds:
206269
- kubectl --kubeconfig={{.KUBECONFIG}} logs -l app=website-app --tail=100 -f
207270

271+
k8s:logs:semcache-service:
272+
desc: Get logs from semcache-service
273+
cmds:
274+
- kubectl --kubeconfig={{.KUBECONFIG}} logs -l app=semcache-service --tail=100 -f
275+
208276
k8s:describe:items-service:
209277
desc: Describe items-service deployment
210278
cmds:
@@ -215,6 +283,11 @@ tasks:
215283
cmds:
216284
- kubectl --kubeconfig={{.KUBECONFIG}} describe deployment website-app
217285

286+
k8s:describe:semcache-service:
287+
desc: Describe semcache-service deployment
288+
cmds:
289+
- kubectl --kubeconfig={{.KUBECONFIG}} describe deployment semcache-service
290+
218291
# Deployment tasks
219292
deploy:items-service:
220293
desc: Deploy items-service to Kubernetes
@@ -229,6 +302,14 @@ tasks:
229302
cmds:
230303
- kubectl --kubeconfig={{.KUBECONFIG}} apply -f {{.K8S_DIR}}/apps/website-app-deployment.yaml
231304

305+
deploy:semcache-service:
306+
desc: Deploy semcache-service to Kubernetes
307+
cmds:
308+
- kubectl --kubeconfig={{.KUBECONFIG}} apply -f {{.K8S_DIR}}/apps/semcache-service-deployment.yaml
309+
- echo "✅ semcache-service deployed"
310+
- echo "Waiting for rollout to complete..."
311+
- kubectl --kubeconfig={{.KUBECONFIG}} rollout status deployment/semcache-service --timeout=120s
312+
232313
deploy:headlamp-readonly:
233314
desc: Deploy Headlamp Kubernetes Dashboard (Read-Only Public)
234315
cmds:
@@ -242,6 +323,7 @@ tasks:
242323
cmds:
243324
- task: deploy:items-service
244325
- task: deploy:website-app
326+
- task: deploy:semcache-service
245327
- task: deploy:headlamp-readonly
246328

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

420+
rollout:restart:semcache-service:
421+
desc: Restart semcache-service deployment
422+
cmds:
423+
- kubectl --kubeconfig={{.KUBECONFIG}} rollout restart deployment/semcache-service
424+
338425
rollout:status:items-service:
339426
desc: Check rollout status for items-service
340427
cmds:
@@ -345,6 +432,11 @@ tasks:
345432
cmds:
346433
- kubectl --kubeconfig={{.KUBECONFIG}} rollout status deployment/website-app
347434

435+
rollout:status:semcache-service:
436+
desc: Check rollout status for semcache-service
437+
cmds:
438+
- kubectl --kubeconfig={{.KUBECONFIG}} rollout status deployment/semcache-service
439+
348440
# DNS and networking tasks
349441
dns:clear-cache:
350442
desc: Clear DNS cache (macOS)
@@ -369,21 +461,31 @@ tasks:
369461
cmds:
370462
- curl -s https://roussev.com/health | jq
371463

464+
health:semcache-service:
465+
desc: Check health of semcache-service (local)
466+
cmds:
467+
- curl -s https://app.roussev.com/semcache/v1/health | jq
468+
372469
clean:docker:
373470
desc: Clean Docker images
374471
cmds:
375-
- docker rmi items-service:local website-app:local || true
472+
- docker rmi items-service:local website-app:local semcache-service:local || true
376473

377474
# Port forwarding tasks
378-
port-forward:items-service:
379-
desc: Port forward to items-service pod
380-
cmds:
381-
- kubectl --kubeconfig={{.KUBECONFIG}} port-forward svc/items-service 8080:80
382-
383-
port-forward:website-app:
384-
desc: Port forward to website-app pod
385-
cmds:
386-
- kubectl --kubeconfig={{.KUBECONFIG}} port-forward svc/website-app 8080:80
475+
# port-forward:items-service:
476+
# desc: Port forward to items-service pod
477+
# cmds:
478+
# - kubectl --kubeconfig={{.KUBECONFIG}} port-forward svc/items-service 8080:80
479+
480+
# port-forward:website-app:
481+
# desc: Port forward to website-app pod
482+
# cmds:
483+
# - kubectl --kubeconfig={{.KUBECONFIG}} port-forward svc/website-app 8080:80
484+
485+
# port-forward:semcache-service:
486+
# desc: Port forward to semcache-service pod
487+
# cmds:
488+
# - kubectl --kubeconfig={{.KUBECONFIG}} port-forward svc/semcache-service 8080:80
387489

388490
# SSH tasks
389491
ssh:

Tiltfile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,37 @@ k8s_resource(
181181
]
182182
)
183183

184+
# ============================================================================
185+
# Semcache Service (Go + Echo)
186+
# ============================================================================
187+
188+
# Build Docker image for semcache-service (using dev Dockerfile with hot reload)
189+
docker_build(
190+
'semcache-service',
191+
context='./apps/semcache-service',
192+
dockerfile='./apps/semcache-service/Dockerfile.dev',
193+
live_update=[
194+
sync('./apps/semcache-service', '/app'),
195+
]
196+
)
197+
198+
# Deploy semcache-service
199+
k8s_yaml('infra/k8s/local/semcache-service-local.yaml')
200+
201+
# Configure semcache-service resource
202+
k8s_resource(
203+
'semcache-service',
204+
port_forwards='8083:8080',
205+
labels=['apps'],
206+
resource_deps=['postgres', 'jaeger', 'prometheus'],
207+
links=[
208+
link('http://localhost:8083/docs', 'API Documentation (Swagger UI)'),
209+
link('http://localhost:8083/health', 'Health Check'),
210+
link('http://localhost:8083/v1/create', 'API - Create (POST)'),
211+
link('http://localhost:8083/v1/search', 'API - Search (POST)'),
212+
]
213+
)
214+
184215
# ============================================================================
185216
# Headlamp Kubernetes Dashboard (Read-Only)
186217
# ============================================================================
@@ -217,6 +248,9 @@ Services will be available at:
217248
- Metrics: http://localhost:8081/metrics
218249
🌐 Website App: http://localhost:8082
219250
- Health: http://localhost:8082/health
251+
👋 Hello Service: http://localhost:8083
252+
- Health: http://localhost:8083/health
253+
- API: http://localhost:8083/v1/greetings
220254
👁️ Headlamp: http://localhost:8084 (Read-Only)
221255
222256
📊 Observability:

apps/semcache-service/.air.toml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
root = "."
2+
testdata_dir = "testdata"
3+
tmp_dir = "tmp"
4+
5+
[build]
6+
args_bin = []
7+
bin = "./tmp/main"
8+
cmd = "go build -o ./tmp/main ./cmd/server"
9+
delay = 500 # Faster delay for local dev (500ms vs 1000ms)
10+
exclude_dir = ["assets", "tmp", "vendor", "testdata"]
11+
exclude_file = []
12+
exclude_regex = ["_test.go"]
13+
exclude_unchanged = false
14+
follow_symlink = false
15+
full_bin = ""
16+
include_dir = []
17+
include_ext = ["go", "tpl", "tmpl", "html"]
18+
include_file = []
19+
kill_delay = "0s"
20+
log = "build-errors.log"
21+
poll = false
22+
poll_interval = 0
23+
rerun = false
24+
rerun_delay = 500
25+
send_interrupt = false
26+
stop_on_error = false
27+
28+
[color]
29+
app = ""
30+
build = "yellow"
31+
main = "magenta"
32+
runner = "green"
33+
watcher = "cyan"
34+
35+
[log]
36+
main_only = false
37+
time = true
38+
39+
[misc]
40+
clean_on_exit = false
41+
42+
[screen]
43+
clear_on_rebuild = true # Clear screen on rebuild for cleaner output
44+
keep_scroll = true
45+

apps/semcache-service/.gitignore

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
8+
# Test binary, built with `go test -c`
9+
*.test
10+
11+
# Output of the go coverage tool
12+
*.out
13+
14+
# Go workspace file
15+
go.work
16+
17+
# Dependency directories
18+
vendor/
19+
20+
# Air temporary files
21+
tmp/
22+
build-errors.log
23+
24+
# IDE
25+
.idea/
26+
.vscode/
27+
*.swp
28+
*.swo
29+
*~
30+
31+
# OS
32+
.DS_Store
33+
Thumbs.db
34+
35+
# Environment variables
36+
.env
37+
.env.local
38+

apps/semcache-service/Dockerfile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Build stage
2+
FROM golang:1.25-alpine AS builder
3+
4+
WORKDIR /app
5+
6+
# Install build dependencies
7+
RUN apk add --no-cache git
8+
9+
# Copy go mod files
10+
COPY go.mod go.sum* ./
11+
12+
# Download dependencies
13+
RUN go mod download
14+
15+
# Copy source code
16+
COPY . .
17+
18+
# Build the application
19+
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o server ./cmd/server
20+
21+
# Runtime stage
22+
FROM alpine:3.19
23+
24+
# Install ca-certificates for HTTPS
25+
RUN apk --no-cache add ca-certificates
26+
27+
WORKDIR /app
28+
29+
# Copy binary from builder
30+
COPY --from=builder /app/server .
31+
32+
# Expose port
33+
EXPOSE 8080
34+
35+
# Set environment variables
36+
ENV PORT=8080
37+
38+
# Run the application
39+
CMD ["./server"]
40+

0 commit comments

Comments
 (0)