services:
  database:
    container_name: stockhome-mysql
    image: mysql:8.0
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
      MYSQL_DATABASE: stockhome
      TZ: Europe/Berlin
    volumes:
      - ./.docker/volumes/stockhome_mysql:/var/lib/mysql
      - ./mysql-timezone.cnf:/etc/mysql/conf.d/timezone.cnf:ro
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
      interval: 5s
      timeout: 3s
      retries: 20

  backend:
    container_name: stockhome-backend
    build:
      context: ./backend
      dockerfile: Dockerfile
    ports:
      - "8004:8004"
    environment:
      DB_HOST: stockhome-mysql
      DB_USER: root
      DB_NAME: stockhome
      DB_PASSWORD: ${MYSQL_ROOT_PASSWORD}
      SECRET_KEY: ${AUTH_SIGNATURE}
      NODE_ENV: production
    depends_on:
      database:
        condition: service_healthy
    restart: unless-stopped

  frontend:
    container_name: stockhome-frontend
    ports:
      - "80:80"
    build: ./frontend
    environment:
      BACKEND_HOST: ${BACKEND_HOST}
    depends_on:
      - backend
    restart: unless-stopped
