From 468ea5f252e3cf79bc6a249d2246c0b67856a00f Mon Sep 17 00:00:00 2001 From: francy51 Date: Tue, 24 Feb 2026 14:02:49 -0500 Subject: [PATCH] fix deployment by adding postgres service to base compose --- .env.example | 5 +++++ README.md | 8 ++++++-- docker-compose.override.yml | 22 ---------------------- docker-compose.yml | 21 ++++++++++++++++++++- 4 files changed, 31 insertions(+), 25 deletions(-) diff --git a/.env.example b/.env.example index af836e4..e023cd1 100644 --- a/.env.example +++ b/.env.example @@ -6,7 +6,12 @@ NPM_VERSION=latest APP_PORT=3000 # Better Auth / PostgreSQL +# For app running outside Docker, localhost is typical. +# In Docker Compose deployment, default internal host is: postgres DATABASE_URL=postgres://postgres:postgres@localhost:5432/fiscal_clone +POSTGRES_DB=fiscal_clone +POSTGRES_USER=postgres +POSTGRES_PASSWORD=postgres BETTER_AUTH_SECRET=replace-with-a-long-random-secret BETTER_AUTH_BASE_URL=http://localhost:3000 BETTER_AUTH_ADMIN_USER_IDS= diff --git a/README.md b/README.md index d1392af..00d91cb 100644 --- a/README.md +++ b/README.md @@ -39,8 +39,9 @@ docker compose up --build -d ``` For local Docker, host port mapping comes from `docker-compose.override.yml` (default `http://localhost:3000`, configurable via `APP_PORT`). -The local override also starts PostgreSQL and wires `DATABASE_URL` to `postgres://postgres:postgres@postgres:5432/fiscal_clone`. -For Coolify/remote Docker Compose, only container port `3000` is exposed internally (no fixed host port bind), avoiding host port collisions. +The base Docker Compose now includes an internal PostgreSQL service (`postgres`) used by Better Auth by default. +For Coolify/remote Docker Compose, only app container port `3000` is exposed internally (no fixed host port bind), avoiding host port collisions. +If you use an external Postgres instance, set `DATABASE_URL` explicitly. Runtime data persists in the `app_data` volume (`/app/data` in container). Docker builds install the npm version from `NPM_VERSION` (default `latest`). @@ -52,6 +53,9 @@ Use root `.env` or root `.env.local`: # leave blank for same-origin API NEXT_PUBLIC_API_URL= DATABASE_URL=postgres://postgres:postgres@localhost:5432/fiscal_clone +POSTGRES_DB=fiscal_clone +POSTGRES_USER=postgres +POSTGRES_PASSWORD=postgres BETTER_AUTH_SECRET=replace-with-a-long-random-secret BETTER_AUTH_BASE_URL=http://localhost:3000 BETTER_AUTH_ADMIN_USER_IDS= diff --git a/docker-compose.override.yml b/docker-compose.override.yml index ae026f7..5d6a1ec 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -2,28 +2,6 @@ services: app: ports: - '${APP_PORT:-3000}:3000' - depends_on: - postgres: - condition: service_healthy environment: - DATABASE_URL: ${DATABASE_URL:-postgres://postgres:postgres@postgres:5432/fiscal_clone} BETTER_AUTH_BASE_URL: ${BETTER_AUTH_BASE_URL:-http://localhost:3000} BETTER_AUTH_TRUSTED_ORIGINS: ${BETTER_AUTH_TRUSTED_ORIGINS:-http://localhost:3000} - - postgres: - image: postgres:16-alpine - restart: unless-stopped - environment: - POSTGRES_DB: fiscal_clone - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres - volumes: - - postgres_data:/var/lib/postgresql/data - healthcheck: - test: ['CMD-SHELL', 'pg_isready -U postgres -d fiscal_clone'] - interval: 10s - timeout: 5s - retries: 5 - -volumes: - postgres_data: diff --git a/docker-compose.yml b/docker-compose.yml index 1128af7..9f56e86 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,7 +14,7 @@ services: PORT: 3000 HOSTNAME: 0.0.0.0 NEXT_PUBLIC_API_URL: ${NEXT_PUBLIC_API_URL:-} - DATABASE_URL: ${DATABASE_URL:-} + DATABASE_URL: ${DATABASE_URL:-postgres://postgres:postgres@postgres:5432/fiscal_clone} BETTER_AUTH_SECRET: ${BETTER_AUTH_SECRET:-} BETTER_AUTH_BASE_URL: ${BETTER_AUTH_BASE_URL:-} BETTER_AUTH_ADMIN_USER_IDS: ${BETTER_AUTH_ADMIN_USER_IDS:-} @@ -23,6 +23,9 @@ services: OPENCLAW_API_KEY: ${OPENCLAW_API_KEY:-} OPENCLAW_MODEL: ${OPENCLAW_MODEL:-zeroclaw} SEC_USER_AGENT: ${SEC_USER_AGENT:-Fiscal Clone } + depends_on: + postgres: + condition: service_healthy healthcheck: test: ["CMD-SHELL", "wget -q --spider http://127.0.0.1:3000/api/health || exit 1"] interval: 30s @@ -33,5 +36,21 @@ services: volumes: - app_data:/app/data + postgres: + image: postgres:16-alpine + restart: unless-stopped + environment: + POSTGRES_DB: ${POSTGRES_DB:-fiscal_clone} + POSTGRES_USER: ${POSTGRES_USER:-postgres} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres} + volumes: + - postgres_data:/var/lib/postgresql/data + healthcheck: + test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-postgres} -d ${POSTGRES_DB:-fiscal_clone}"] + interval: 10s + timeout: 5s + retries: 5 + volumes: app_data: + postgres_data: