services:
  db:
    image: docker.arvancloud.ir/library/mariadb:11
    container_name: biztaghavi_db
    restart: unless-stopped
    environment:
      MARIADB_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
      MARIADB_DATABASE: ${DB_NAME:-biztaghavi}
      MARIADB_USER: ${DB_USER:-biztaghavi}
      MARIADB_PASSWORD: ${DB_PASSWORD}
    volumes:
      - db-data:/var/lib/mysql
    networks:
      - app-internal
    healthcheck:
      test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
      interval: 10s
      timeout: 5s
      retries: 20

  next-app:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: biztaghavi_app
    restart: unless-stopped
    depends_on:
      db:
        condition: service_healthy
    env_file: .env
    environment:
      NODE_ENV: production
      DATABASE_URL: mysql://${DB_USER:-biztaghavi}:${DB_PASSWORD}@db:3306/${DB_NAME:-biztaghavi}
    ports:
      - "127.0.0.1:3009:3000"
    volumes:
      - uploads:/app/public/uploads
    networks:
      - app-internal
      - nodecloud-net

volumes:
  db-data:
  uploads:

networks:
  app-internal:
    driver: bridge
  nodecloud-net:
    external: true
