# Full acrate stack, running on a single machine for experimental purposes

x-config:
  ingress_config_dir: &ingress_config_dir "./config/caddy"
  
name: "acrate"

volumes:
  ingress_data:
  ingress_config:
  postgres_data:

services:
  # Public ingress node
  ingress:
    image: "caddy"
    restart: "unless-stopped"
    cap_add:
    - "NET_ADMIN"
    ports:
    - protocol: "tcp"
      target: 80
      published: 80
    - protocol: "tcp"
      target: 443
      published: 443
    - protocol: "udp"
      target: 443
      published: 443
    volumes:
    - type: "volume"
      source: "ingress_data"
      target: "/data"
    - type: "volume"
      source: "ingress_config"
      target: "/config"
    - type: "bind"
      source: *ingress_config_dir
      target: "/etc/caddy"
  
  # Main database
  database:
    image: "postgres"
    restart: "unless-stopped"
    environment:
      # Make sure the password is the same for both client and server tools
      POSTGRES_PASSWORD: &postgres_password "acrate"
      PGUSER: "postgres"
      PGPASS: *postgres_password
    volumes:
    - type: "volume"
      source: "postgres_data"
      target: "/var/lib/postgresql/data"
    expose:
    - 5432
    healthcheck:
      test: ["CMD-SHELL", "pg_isready"]
  
  # Migrations
  migrate:
    build:
      dockerfile: "./Dockerfile"
      additional_contexts:
      - "source=.."
      target: "migrate"
    environment:
      ACRATE_DATABASE_URL: &database_url "postgres:///postgres?host=database&user=postgres&password=acrate"
    depends_on:
      database:
        condition: "service_healthy"
      
  # Resource descriptor server
  rdserver:
    build:
      dockerfile: "./Dockerfile"
      additional_contexts:
      - "source=.."
      target: "rdserver"
    restart: "unless-stopped"
    environment:
      ACRATE_RDSERVER_BIND_ADDRESS: "0.0.0.0:80"
      ACRATE_DATABASE_URL: *database_url
    expose:
    - 80
    depends_on:
      database:
        condition: "service_healthy"
      migrate:
        condition: "service_completed_successfully"
  
  # ActivityPub inbox server
  apub_inbox:
    build:
      dockerfile: "./Dockerfile"
      additional_contexts:
      - "source=.."
      target: "apub_inbox"
    restart: "unless-stopped"
    environment:
      ACRATE_APUB_INBOX_BIND_ADDRESS: "0.0.0.0:80"
      ACRATE_DATABASE_URL: *database_url
    expose:
    - 80
    depends_on:
      database:
        condition: "service_healthy"
      migrate:
        condition: "service_completed_successfully"