# Home Space: the database and the server.
# Guide: https://home-space.app/docs/
#
# Put this file in its own directory (e.g. /opt/homespace) next to a .env file holding at least
#   HOMESPACE_DB_PASSWORD   password of the database user: openssl rand -hex 24
#   HOMESPACE_JWT_SECRET    signs the access tokens: openssl rand -base64 48
# and, for two-factor sign-in with an authenticator app,
#   HOMESPACE_SECRETS_KEY   seals the authenticator apps: openssl rand -base64 48
# Every other setting in .env reaches the server too: https://home-space.app/docs/configuration/
#
#   docker compose up -d
#   docker compose exec server homespace-ctl user add me --admin
services:
  db:
    # A new major version cannot read the files of the one before: upgrade deliberately.
    image: docker.io/library/postgres:18
    restart: unless-stopped
    environment:
      POSTGRES_USER: homespace
      POSTGRES_PASSWORD: ${HOMESPACE_DB_PASSWORD:?set HOMESPACE_DB_PASSWORD in .env}
      POSTGRES_DB: homespace
    volumes:
      - db:/var/lib/postgresql
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U homespace -d homespace"]
      interval: 5s
      timeout: 3s
      retries: 30

  server:
    image: docker.io/homespaceapp/home-space:latest
    restart: unless-stopped
    depends_on:
      db:
        condition: service_healthy
    env_file: .env
    environment:
      # No password in the URL: the server reads HOMESPACE_DB_PASSWORD from .env itself.
      DATABASE_URL: postgres://homespace@db:5432/homespace
      HOMESPACE_JWT_SECRET: ${HOMESPACE_JWT_SECRET:?set HOMESPACE_JWT_SECRET in .env}
    # Loopback only: nginx on this machine is the way in.
    ports:
      - "127.0.0.1:${HOMESPACE_PORT:-8080}:8080"
    volumes:
      - files:/data

volumes:
  db:
  files:
