services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: {{ project_slug }}_app
    ports:
      - "8000:8000"
    environment:
      - APP_ENV=production
      - DEBUG=false
{% if has_database %}
{% if database.value == "PostgreSQL" %}
      - DATABASE_URL=postgresql+psycopg://myuser:mypassword@postgres:5432/mydb
{% elif database.value == "MySQL" %}
      - DATABASE_URL=mysql+asyncmy://myuser:mypassword@mysql:3306/mydb
{% elif database.value == "SQLite" %}
      - DATABASE_URL=sqlite+aiosqlite:///./app.db
{% endif %}
{% endif %}
    env_file:
      - .env
{% if database.value == "PostgreSQL" %}
    depends_on:
      postgres:
        condition: service_healthy
{% elif database.value == "MySQL" %}
    depends_on:
      mysql:
        condition: service_healthy
{% endif %}
    restart: unless-stopped

{% if database.value == "PostgreSQL" %}
  postgres:
    image: postgres:17-alpine
    container_name: {{ project_slug }}_postgres
    environment:
      POSTGRES_DB: mydb
      POSTGRES_USER: myuser
      POSTGRES_PASSWORD: mypassword
    volumes:
      - postgres_data:/var/lib/postgresql/data
    ports:
      - "5432:5432"
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U myuser -d mydb"]
      interval: 10s
      timeout: 5s
      retries: 5
    restart: unless-stopped
{% elif database.value == "MySQL" %}
  mysql:
    image: mysql:8.0
    container_name: {{ project_slug }}_mysql
    environment:
      MYSQL_DATABASE: mydb
      MYSQL_USER: myuser
      MYSQL_PASSWORD: mypassword
      MYSQL_ROOT_PASSWORD: rootpassword
    volumes:
      - mysql_data:/var/lib/mysql
    ports:
      - "3306:3306"
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
      interval: 10s
      timeout: 5s
      retries: 5
    restart: unless-stopped
{% endif %}

{% if database.value == "PostgreSQL" %}
volumes:
  postgres_data: {}
{% elif database.value == "MySQL" %}
volumes:
  mysql_data: {}
{% endif %}
