Files
backend_fiesta/docker-compose.local.yml
2026-09-02 10:49:46 +05:30

115 lines
4.6 KiB
YAML

# A local stack to develop Fiesta against, so a change can be tried before it is
# deployed.
#
# Named `.local` because it is NOT the deployment compose. Nothing here should
# ever run on a server: the passwords are literals, the ports are published to
# the host, and the whole point is that the data is disposable.
#
# docker compose -f docker-compose.local.yml up -d
#
# ── READ THIS FIRST ─────────────────────────────────────────────────────────
#
# An EMPTY database is not enough to boot Fiesta. `main.go` runs migrations on
# startup, and most of them assume tables that nothing in this repository
# creates — `ALTER TABLE products`, `ALTER TABLE productlocations`. AutoMigrate
# covers only stockrequests, the POS order tables and staffshifts. Against a
# blank database the first ALTER fails and `log.Fatal` stops the process.
#
# So load the schema before the first run:
#
# pg_dump --schema-only --no-owner --no-privileges \
# -h <live-host> -p 5433 -U <user> -d nearledb \
# > init/nearledb/01-schema.sql
#
# Anything in ./init/nearledb is applied, in filename order, the first time the
# volume is created. To reload after changing it, drop the volume:
#
# docker compose -f docker-compose.local.yml down -v
#
# ── Why bother ──────────────────────────────────────────────────────────────
#
# Because pointing `DB_HOST` at production is not local testing — it is
# production with a local UI. `go run .` there creates real tenants and real
# logins, and runs those same schema migrations against live data.
services:
# The main database. Port 5433 on the host, matching production's DB_PORT, so
# the only line that changes between the two is DB_HOST.
nearledb:
image: postgres:16-alpine
container_name: nearle-db-local
environment:
POSTGRES_DB: nearledb
POSTGRES_USER: nearle
POSTGRES_PASSWORD: localdev
# Asia/Kolkata to match the DSN Fiesta builds. Timestamps written here
# otherwise differ from production by five and a half hours, which is the
# sort of thing that looks like a bug in the code being tested.
TZ: Asia/Kolkata
PGTZ: Asia/Kolkata
ports:
- '5433:5432'
volumes:
- nearledb-data:/var/lib/postgresql/data
- ./init/nearledb:/docker-entrypoint-initdb.d:ro
healthcheck:
# `go run .` fails hard if the database is not up yet, so the compose
# waits for a real connection rather than for the container to exist.
test: ['CMD-SHELL', 'pg_isready -U nearle -d nearledb']
interval: 5s
timeout: 3s
retries: 20
# The catalogue database, kept separate exactly as it is in production — the
# comment on `db.CatalogueDB` is explicit that catalogue work must never touch
# nearledb, and one container per database is the cheapest way to keep that
# true locally too.
#
# The pgvector image rather than plain postgres: the live catalogue is a
# pgvector database. Nothing in Fiesta's Go code uses a vector column today —
# it reads the per-brand tables — but a schema dump from the real one will
# carry `CREATE EXTENSION vector`, and that fails on a stock image.
#
# 5434 on the host, not 5432: a developer machine usually already has
# something on 5432, and a silent connection to the wrong database is worse
# than a refused one.
cataloguedb:
image: pgvector/pgvector:pg16
container_name: nearle-catalogue-local
environment:
POSTGRES_DB: cataloguedb
POSTGRES_USER: nearle
POSTGRES_PASSWORD: localdev
TZ: Asia/Kolkata
PGTZ: Asia/Kolkata
ports:
- '5434:5432'
volumes:
- cataloguedb-data:/var/lib/postgresql/data
- ./init/cataloguedb:/docker-entrypoint-initdb.d:ro
healthcheck:
test: ['CMD-SHELL', 'pg_isready -U nearle -d cataloguedb']
interval: 5s
timeout: 3s
retries: 20
# POS terminal presence, under a TTL.
#
# Optional in the same way it is optional in production: `db.InitRedis()`
# failing costs the till health board and nothing else, because losing a sale
# matters and losing a dashboard does not. Included because it is one line.
redis:
image: redis:7-alpine
container_name: nearle-redis-local
ports:
- '6379:6379'
healthcheck:
test: ['CMD', 'redis-cli', 'ping']
interval: 5s
timeout: 3s
retries: 10
volumes:
nearledb-data:
cataloguedb-data: