From 0c6ccc8a47cedf666bc16ced31682c6f50a7c90c Mon Sep 17 00:00:00 2001 From: achmad Date: Mon, 11 May 2026 08:39:54 +0700 Subject: [PATCH] dev: add Docker compose development stack with Air reload --- .air.toml | 13 ++++++++++ Dockerfile.dev | 8 ++++++ Makefile | 21 ++++++++++++++++ compose-dev.yml | 66 +++++++++++++++++++++++++++++++++++++++++++++++++ dev.env | 21 ++++++++++++++++ 5 files changed, 129 insertions(+) create mode 100644 .air.toml create mode 100644 Dockerfile.dev create mode 100644 Makefile create mode 100644 compose-dev.yml create mode 100644 dev.env diff --git a/.air.toml b/.air.toml new file mode 100644 index 0000000..504c64c --- /dev/null +++ b/.air.toml @@ -0,0 +1,13 @@ +root = "." +tmp_dir = "tmp" + +[build] +cmd = "go build -o ./tmp/goyomi ./cmd/server" +bin = "./tmp/goyomi" +include_ext = ["go", "tpl", "tmpl", "html", "yaml", "yml", "json"] +exclude_dir = ["tmp", "vendor", ".git"] +delay = 500 +stop_on_error = true + +[log] +time = true diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 0000000..cbb3219 --- /dev/null +++ b/Dockerfile.dev @@ -0,0 +1,8 @@ +FROM golang:1.26-alpine + +RUN apk add --no-cache git bash build-base +RUN go install github.com/air-verse/air@latest + +WORKDIR /workspace + +CMD ["air", "-c", ".air.toml"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e07d3ab --- /dev/null +++ b/Makefile @@ -0,0 +1,21 @@ +DEV_COMPOSE = docker compose -f compose-dev.yml --env-file dev.env + +.PHONY: dev-up dev-shell dev-down dev-logs dev-build dev-run + +dev-build: + $(DEV_COMPOSE) build dev + +dev-up: + $(DEV_COMPOSE) up -d + +dev-run: + $(DEV_COMPOSE) up dev + +dev-shell: + $(DEV_COMPOSE) exec dev sh + +dev-down: + $(DEV_COMPOSE) down + +dev-logs: + $(DEV_COMPOSE) logs -f --tail=100 diff --git a/compose-dev.yml b/compose-dev.yml new file mode 100644 index 0000000..8413a41 --- /dev/null +++ b/compose-dev.yml @@ -0,0 +1,66 @@ +services: + dev: + build: + context: . + dockerfile: Dockerfile.dev + working_dir: /workspace + command: air -c .air.toml + tty: true + stdin_open: true + env_file: + - dev.env + volumes: + - ./:/workspace + - go_mod_cache:/go/pkg/mod + - go_build_cache:/root/.cache/go-build + ports: + - "8080:8080" + depends_on: + postgres: + condition: service_healthy + flaresolverr: + condition: service_started + networks: + - goyomi_dev + + postgres: + image: postgres:16-alpine + restart: unless-stopped + env_file: + - dev.env + environment: + POSTGRES_DB: ${POSTGRES_DB} + POSTGRES_USER: ${POSTGRES_USER} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} + ports: + - "5432:5432" + volumes: + - postgres_dev_data:/var/lib/postgresql/data + healthcheck: + test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"] + interval: 5s + timeout: 5s + retries: 10 + networks: + - goyomi_dev + + flaresolverr: + image: ghcr.io/flaresolverr/flaresolverr:latest + restart: unless-stopped + env_file: + - dev.env + environment: + LOG_LEVEL: ${FLARESOLVERR_LOG_LEVEL} + ports: + - "8191:8191" + networks: + - goyomi_dev + +networks: + goyomi_dev: + driver: bridge + +volumes: + go_mod_cache: + go_build_cache: + postgres_dev_data: diff --git a/dev.env b/dev.env new file mode 100644 index 0000000..c9f121a --- /dev/null +++ b/dev.env @@ -0,0 +1,21 @@ +# PostgreSQL +POSTGRES_DB=goyomi +POSTGRES_USER=goyomi +POSTGRES_PASSWORD=goyomi + +# App runtime +DATABASE_URL=postgres://goyomi:goyomi@postgres:5432/goyomi?sslmode=disable +FLARESOLVERR_URL=http://flaresolverr:8191 +ADDR=:8080 + +# DB pool +DB_MAX_CONNS=10 +DB_MIN_CONNS=2 + +# Cache TTLs (seconds) +MANGA_LIST_TTL_SECONDS=600 +MANGA_DETAIL_TTL_SECONDS=3600 +CHAPTER_LIST_TTL_SECONDS=600 + +# FlareSolverr +FLARESOLVERR_LOG_LEVEL=info