version: "1"
services:
  postgres:
    command: "postgres -D /var/lib/postgres"
    env:
      file: "/etc/myapp/database.env"
    restart_policy: "always"
    backoff: "5s"
    hooks:
      on_start:
        success:
          command: "echo 'Postgres started'"
      on_stop:
        error:
          command: "echo 'Postgres crashed'"

  django:
    command: "python manage.py runserver"
    env:
      vars:
        DEBUG: "true"
        DATABASE_URL: "postgres://user:password@localhost:5432/dbname"
    restart_policy: "on-failure"
    backoff: "5s"
    depends_on:
      - "postgres"
    hooks:
      on_start:
        success:
          command: "curl -X POST http://example.com/hook/django-start"
      on_stop:
        error:
          command: "curl -X POST http://example.com/hook/django-error"

  ngrok:
    command: "ngrok http 8000"
    restart_policy: "on-failure"
    backoff: "3s"
    hooks:
      on_start:
        success:
          command: "echo 'ngrok started'"
      on_stop:
        error:
          command: "echo 'ngrok crashed'"
