This commit is contained in:
parent
7a71cc0e8f
commit
9bd1eb243f
@ -9,6 +9,33 @@ clone:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
# COMPONENT_STEPS_BELOW
|
# COMPONENT_STEPS_BELOW
|
||||||
|
|
||||||
|
# Woodpecker CI step for api service
|
||||||
|
# Add this step to your .woodpecker.yml
|
||||||
|
|
||||||
|
build-api:
|
||||||
|
image: woodpeckerci/plugin-kaniko
|
||||||
|
settings:
|
||||||
|
registry: registry.threesix.ai
|
||||||
|
repo: testgo1/api
|
||||||
|
tags:
|
||||||
|
- latest
|
||||||
|
- ${CI_COMMIT_SHA:0:8}
|
||||||
|
context: .
|
||||||
|
dockerfile: services/api/Dockerfile
|
||||||
|
cache: true
|
||||||
|
skip-tls-verify: true
|
||||||
|
when:
|
||||||
|
branch: main
|
||||||
|
event: push
|
||||||
|
|
||||||
|
deploy-api:
|
||||||
|
image: bitnami/kubectl:latest
|
||||||
|
commands:
|
||||||
|
- kubectl set image deployment/testgo1-api api=registry.threesix.ai/testgo1/api:${CI_COMMIT_SHA:0:8} -n projects || echo "Deployment not found, skipping"
|
||||||
|
when:
|
||||||
|
branch: main
|
||||||
|
event: push
|
||||||
# Do not remove the marker above - component steps are inserted here
|
# Do not remove the marker above - component steps are inserted here
|
||||||
|
|
||||||
verify:
|
verify:
|
||||||
|
|||||||
@ -46,4 +46,7 @@ testgo1/
|
|||||||
|
|
||||||
## Components
|
## Components
|
||||||
|
|
||||||
<!-- Components will be listed here as they're added -->
|
| Component | Type | Path |
|
||||||
|
|-----------|------|------|
|
||||||
|
| **api** | API service | `services/api/` |
|
||||||
|
|
||||||
|
|||||||
1
Procfile
1
Procfile
@ -1,2 +1,3 @@
|
|||||||
# Local development processes
|
# Local development processes
|
||||||
# Components will be added below as they're created
|
# Components will be added below as they're created
|
||||||
|
api: cd services/api && make run
|
||||||
|
|||||||
1
go.work
1
go.work
@ -1,4 +1,5 @@
|
|||||||
go 1.23
|
go 1.23
|
||||||
|
|
||||||
use ./pkg
|
use ./pkg
|
||||||
|
use ./services/api
|
||||||
// Component modules will be added below
|
// Component modules will be added below
|
||||||
|
|||||||
17
services/api/.env.example
Normal file
17
services/api/.env.example
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# api Service Configuration
|
||||||
|
|
||||||
|
# Server
|
||||||
|
SERVER_PORT=8001
|
||||||
|
SERVER_HOST=0.0.0.0
|
||||||
|
|
||||||
|
# App
|
||||||
|
APP_NAME=api
|
||||||
|
APP_ENVIRONMENT=development
|
||||||
|
APP_DEBUG=true
|
||||||
|
|
||||||
|
# Logging
|
||||||
|
LOG_LEVEL=debug
|
||||||
|
LOG_FORMAT=text
|
||||||
|
|
||||||
|
# Database (if needed)
|
||||||
|
DATABASE_URL=postgres://dev:dev@localhost:5432/testgo1?sslmode=disable
|
||||||
27
services/api/Dockerfile
Normal file
27
services/api/Dockerfile
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
# Build stage
|
||||||
|
FROM golang:1.23-alpine AS builder
|
||||||
|
|
||||||
|
RUN apk add --no-cache git
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy go workspace and all source (workspace deps are local)
|
||||||
|
COPY go.work go.work.sum* ./
|
||||||
|
COPY pkg/ ./pkg/
|
||||||
|
COPY services/api/ ./services/api/
|
||||||
|
|
||||||
|
# Build (go will download external deps automatically)
|
||||||
|
RUN cd services/api && CGO_ENABLED=0 go build -o /api ./cmd/server
|
||||||
|
|
||||||
|
# Production stage
|
||||||
|
FROM alpine:3.19
|
||||||
|
|
||||||
|
RUN apk add --no-cache ca-certificates tzdata
|
||||||
|
|
||||||
|
WORKDIR /
|
||||||
|
|
||||||
|
COPY --from=builder /api /api
|
||||||
|
|
||||||
|
EXPOSE 8001
|
||||||
|
|
||||||
|
ENTRYPOINT ["/api"]
|
||||||
34
services/api/Makefile
Normal file
34
services/api/Makefile
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
.PHONY: build run test lint fmt docker-build clean
|
||||||
|
|
||||||
|
SERVICE := api
|
||||||
|
BINARY := bin/$(SERVICE)
|
||||||
|
GO_MODULE := github.com/jordan/testgo1
|
||||||
|
|
||||||
|
# Build the service binary
|
||||||
|
build:
|
||||||
|
go build -o $(BINARY) ./cmd/server
|
||||||
|
|
||||||
|
# Run the service locally
|
||||||
|
run:
|
||||||
|
go run ./cmd/server
|
||||||
|
|
||||||
|
# Run tests
|
||||||
|
test:
|
||||||
|
go test -v ./...
|
||||||
|
|
||||||
|
# Run linter
|
||||||
|
lint:
|
||||||
|
golangci-lint run ./...
|
||||||
|
|
||||||
|
# Format code
|
||||||
|
fmt:
|
||||||
|
gofmt -w .
|
||||||
|
goimports -w -local $(GO_MODULE) .
|
||||||
|
|
||||||
|
# Build Docker image (run from monorepo root)
|
||||||
|
docker-build:
|
||||||
|
docker build -t $(SERVICE):latest -f Dockerfile ../..
|
||||||
|
|
||||||
|
# Clean build artifacts
|
||||||
|
clean:
|
||||||
|
rm -rf bin/
|
||||||
18
services/api/cmd/server/main.go
Normal file
18
services/api/cmd/server/main.go
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
// Package main is the entry point for the api service.
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/jordan/testgo1/pkg/app"
|
||||||
|
"github.com/jordan/testgo1/services/api/internal/api"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
// Create application
|
||||||
|
application := app.New("api", app.WithDefaultPort(8001))
|
||||||
|
|
||||||
|
// Register routes
|
||||||
|
api.RegisterRoutes(application)
|
||||||
|
|
||||||
|
// Start server
|
||||||
|
application.Run()
|
||||||
|
}
|
||||||
9
services/api/component.yaml
Normal file
9
services/api/component.yaml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
name: api
|
||||||
|
type: service
|
||||||
|
port: 8001
|
||||||
|
path: services/api
|
||||||
|
dependencies: []
|
||||||
|
# Add dependencies as needed:
|
||||||
|
# - postgres
|
||||||
|
# - redis
|
||||||
|
# - other-service
|
||||||
5
services/api/go.mod
Normal file
5
services/api/go.mod
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
module github.com/jordan/testgo1/services/api
|
||||||
|
|
||||||
|
go 1.23
|
||||||
|
|
||||||
|
require github.com/jordan/testgo1/pkg v0.0.0
|
||||||
26
services/api/internal/api/handlers/health.go
Normal file
26
services/api/internal/api/handlers/health.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package handlers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/jordan/testgo1/pkg/httpresponse"
|
||||||
|
"github.com/jordan/testgo1/pkg/logging"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Health handles health check endpoints.
|
||||||
|
type Health struct {
|
||||||
|
logger *logging.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewHealth creates a new Health handler.
|
||||||
|
func NewHealth(logger *logging.Logger) *Health {
|
||||||
|
return &Health{logger: logger}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check returns the service health status.
|
||||||
|
func (h *Health) Check(w http.ResponseWriter, r *http.Request) {
|
||||||
|
httpresponse.OK(w, r, map[string]string{
|
||||||
|
"service": "api",
|
||||||
|
"status": "healthy",
|
||||||
|
})
|
||||||
|
}
|
||||||
21
services/api/internal/api/routes.go
Normal file
21
services/api/internal/api/routes.go
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
// Package api provides HTTP routing and handlers for the api service.
|
||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/jordan/testgo1/pkg/app"
|
||||||
|
"github.com/jordan/testgo1/services/api/internal/api/handlers"
|
||||||
|
)
|
||||||
|
|
||||||
|
// RegisterRoutes registers all HTTP routes for the service.
|
||||||
|
func RegisterRoutes(application *app.App) {
|
||||||
|
logger := application.Logger()
|
||||||
|
|
||||||
|
// Initialize handlers
|
||||||
|
healthHandler := handlers.NewHealth(logger)
|
||||||
|
|
||||||
|
// Register API routes
|
||||||
|
application.Route("/api/v1", func(r app.Router) {
|
||||||
|
r.Get("/health", healthHandler.Check)
|
||||||
|
// Add more routes here
|
||||||
|
})
|
||||||
|
}
|
||||||
32
services/api/internal/config/config.go
Normal file
32
services/api/internal/config/config.go
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
// Package config provides service-specific configuration.
|
||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/jordan/testgo1/pkg/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Config extends the base config with api-specific settings.
|
||||||
|
type Config struct {
|
||||||
|
config.AppConfig
|
||||||
|
Server config.ServerConfig
|
||||||
|
Database config.DatabaseConfig
|
||||||
|
Logging config.LoggingConfig
|
||||||
|
// Add service-specific config fields here
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load reads configuration from environment variables.
|
||||||
|
func Load() (*Config, error) {
|
||||||
|
if err := config.Init(config.Options{
|
||||||
|
AppName: "api",
|
||||||
|
DefaultPort: 8001,
|
||||||
|
}); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &Config{
|
||||||
|
AppConfig: config.ReadAppConfig(),
|
||||||
|
Server: config.ReadServerConfig(),
|
||||||
|
Database: config.ReadDatabaseConfig(),
|
||||||
|
Logging: config.ReadLoggingConfig(),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
0
services/api/migrations/.gitkeep
Normal file
0
services/api/migrations/.gitkeep
Normal file
Loading…
Reference in New Issue
Block a user