networks:
  unluckiest_network:
    driver: bridge

services:

  database:
    build:
      context : ./database
      dockerfile : Dockerfile
    environment:
      - MARIADB_ROOT_PASSWORD=root
      - DB_NAME=unluckiest_db
      - DB_USER=unluckiest_user
      - DB_PASSWORD=_nlckst_prod!
    volumes:
      - unluckiest_database:/var/lib/mysql
    networks:
      - unluckiest_network
    healthcheck:
      test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
      start_period: 15s
      interval: 10s
      timeout: 5s
      retries: 3

  api:
    container_name: api
    build:
      context: ./back
      dockerfile: Dockerfile
    environment:
      DB_URL: mysql://database:3306/unluckiest_db
      DB_USER: unluckiest_user
      DB_PASSWORD: _nlckst_prod!
    ports:
      - "5000:5000"
    networks:
      - unluckiest_network
    depends_on:
      database:
        condition: service_healthy

  webapp:
    container_name : webapp
    build:
      context: ./front
      dockerfile: Dockerfile
    ports:
      - "3000:3000"
    networks:
      - unluckiest_network
    depends_on:
      - api
