version: '3.9'
services:
  db:
    image: mysql:8.4
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: ${DB_NAME:-digitalsubs}
      MYSQL_USER: ${DB_USER:-digitalsubs}
      MYSQL_PASSWORD: ${DB_PASSWORD:-digitalsubs}
    command: ["--default-authentication-plugin=mysql_native_password"]
    ports:
      - '3306:3306'
    healthcheck:
      test: ['CMD-SHELL', 'mysqladmin ping -h localhost -uroot -proot']
      interval: 5s
      timeout: 10s
      retries: 10
  mailhog:
    image: mailhog/mailhog
    ports:
      - '8025:8025'
      - '1025:1025'
  storefront:
    build: ./apps/storefront
    env_file: .env
    environment:
      DATABASE_URL: ${DATABASE_URL}
      STRIPE_SECRET_KEY: ${STRIPE_SECRET_KEY}
      STRIPE_WEBHOOK_SECRET: ${STRIPE_WEBHOOK_SECRET}
      NEXTAUTH_SECRET: ${NEXTAUTH_SECRET}
      NEXTAUTH_URL: http://localhost:3000
    ports:
      - '3000:3000'
    depends_on:
      db:
        condition: service_healthy
  admin:
    build: ./apps/admin
    env_file: .env
    environment:
      DATABASE_URL: ${DATABASE_URL}
      NEXTAUTH_SECRET: ${NEXTAUTH_SECRET}
      NEXTAUTH_URL: http://localhost:3001
    ports:
      - '3001:3000'
    depends_on:
      db:
        condition: service_healthy
