---
services:
  init:
    image: busybox
    restart: "no"
    command:
      - sh
      - -c
      - |
        set -eux
        chown -R 10000:10000 /etc/canopy /var/opt/checksec/canopy/ /logs/ || true
        cp /license /etc/canopy/license || true
    volumes:
      - ${PWD}/license:/license:ro
      - ${PWD}/config/:/etc/canopy/
      - ${PWD}/data/:/var/opt/checksec/canopy/
      - ${PWD}/logs/:/logs/
  canopy:
    restart: always
    image: containers.checksec.com/canopy/canopy:stable
    user: "10000:10000"
    command:
      - sh
      - -c
      - |
        set -eux
        exec /main.sh
    ports:
      - "80:8080"
      - "443:8443"
    environment:
      - DATABASE_URL=postgres://canopy:canopy@postgres/canopy
      - DOCSERVER_URL=http://docserver:8181/docxserver
      - PDFSERVER_URL=http://docserver:8181/convert/
      - CELERY_BROKER=amqp://guest:guest@rabbitmq:5672/
    networks:
      - app-network
    depends_on:
      init:
        condition: service_completed_successfully
      postgres:
        condition: service_started
      rabbitmq:
        condition: service_started
    volumes:
      - ${PWD}/config/:/etc/canopy/
      - ${PWD}/certs/:/etc/caddy/certs
      - ${PWD}/data/:/var/opt/checksec/canopy/
      - ${PWD}/logs/:/logs/

  postgres:
    image: postgres:16-bullseye
    restart: always
    environment:
      - POSTGRES_USER=canopy
      - POSTGRES_PASSWORD=canopy
      - POSTGRES_DB=canopy
    volumes:
      - ${PWD}/postgresql-data/:/var/lib/postgresql/data/
    networks:
      - app-network

  rabbitmq:
    image: rabbitmq:4
    restart: always
    networks:
      - app-network

  docserver:
    image: containers.checksec.com/canopy/docserver:stable
    restart: always
    networks:
      - app-network

networks:
  app-network:
