diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index 870bbf7..e02442f 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -47,5 +47,5 @@ jobs: context: . push: true tags: | - latest - ${{ github.sha }} + ${{ secrets.DOCKER_USERNAME }}/trip-planner:latest + ${{ secrets.DOCKER_USERNAME }}/trip-planner:${{ github.sha }} diff --git a/CLAUDE.md b/CLAUDE.md index a153f19..28c96cc 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -76,6 +76,35 @@ go fmt ./... go vet ./... ``` +## Deployment + +### Docker Deployment + +The project uses a multi-stage Dockerfile: +- **Builder stage**: `golang:1.22-alpine` to build `api` and `cron` binaries +- **Runtime stage**: `alpine:latest` with minimal footprint (~27MB) + +### Docker Compose + +The `docker-compose.yml` includes: +- `api` service: Go HTTP server on port 8080 +- `cron` service: Go cron binary for reference data updates and station status detection +- `postgres`: PostgreSQL 15-alpine with `postgres_data` volume +- `redis`: Redis 7-alpine with `redis_data` volume +- `watchtower`: nickfedor/watchtower for automatic container updates (interval: 60s) + +### CI/CD Pipeline + +Gitea Actions workflow (`.gitea/workflows/deploy.yml`) provides: +- Checkout code +- Setup Go 1.22+ +- Go modules cache +- Lint with golangci-lint v1.54.2 +- Run tests with race detector: `go test -v -race ./...` +- Docker Buildx setup +- Docker login to registry +- Build and push Docker image with tags: `latest` and commit SHA + ### API Endpoints (from specification) - `GET /v1/cities?query=` — City autocomplete diff --git a/Dockerfile b/Dockerfile index 53d7282..cf6602c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Builder stage -FROM golang:1.26-alpine AS builder +FROM golang:1.22-alpine AS builder WORKDIR /app diff --git a/cmd/api/main.go b/cmd/api/main.go index 9afbea0..b3990cc 100644 --- a/cmd/api/main.go +++ b/cmd/api/main.go @@ -86,8 +86,12 @@ func main() { // initRedis initializes a Redis client connection. func initRedis() *redis.Client { + redisAddr := os.Getenv("REDIS_ADDR") + if redisAddr == "" { + redisAddr = "localhost:6379" + } rdb := redis.NewClient(&redis.Options{ - Addr: "localhost:6379", + Addr: redisAddr, Password: "", DB: 0, })