version: "3.8"

networks:
  tripify-network:
    driver: bridge

services:
  authentication:
    build:
      context: ./services/authentication
    container_name: tripify-auth
    restart: always
    depends_on:
      - db
    environment:
      NODE_ENV: development
    ports:
      - "3001:3000"
    networks:
      - tripify-network
    volumes:
      - ./services/authentication:/app
    command: ["node", "src/index.js"]

  gateway:
    build:
      context: ./services/gateway
    container_name: tripify-gateway
    restart: always
    depends_on:
      - authentication
      - db
    environment:
      NODE_ENV: production
      AUTH_SERVICE_URL: http://authentication:3000
    ports:
      - "3000:3000" # Expose gateway service on port 3000
    networks:
      - tripify-network
    volumes:
      - ./services/gateway:/app
    command: ["node", "src/index.js"]

  db:
    image: mysql:8
    container_name: tripify-db
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: tripify
      MYSQL_USER: tripify_user
      MYSQL_PASSWORD: tripify_pass
    ports:
      - "3307:3306" # Exposing MySQL container on port 3307
    networks:
      - tripify-network
    volumes:
      - mysql_data:/var/lib/mysql
      - ./database/init.sql:/docker-entrypoint-initdb.d/init.sql

volumes:
  mysql_data:
