version: '3'

services:
  nginx:
    container_name: infisical-dev-nginx
    image: nginx
    restart: always
    ports:
      - 8080:80
    volumes:
      - ./nginx/default.dev.conf:/etc/nginx/conf.d/default.conf:ro
    depends_on:
      - frontend
      - backend
    networks:
      - infisical-dev

  backend:
    container_name: infisical-dev-backend
    restart: unless-stopped
    depends_on:
      - mongo
      - smtp-server
    build:
      context: ./backend
      dockerfile: Dockerfile
    volumes:
      - ./backend/src:/app/src
      - ./backend/nodemon.json:/app/nodemon.json
      - /app/node_modules
    command: npm run dev
    env_file: .env
    environment:
      - NODE_ENV=development
    networks:
      - infisical-dev

  frontend:
    container_name: infisical-dev-frontend
    restart: unless-stopped
    depends_on:
      - backend
    build:
      context: ./frontend
      dockerfile: Dockerfile.dev
    volumes:
      - ./frontend/pages:/app/pages
      - ./frontend/public:/app/public
      - ./frontend/styles:/app/styles
      - ./frontend/components:/app/components
    env_file: .env
    environment:
      - NEXT_PUBLIC_ENV=development
      - INFISICAL_TELEMETRY_ENABLED=${TELEMETRY_ENABLED}
      - NEXT_PUBLIC_STRIPE_PRODUCT_PRO=${STRIPE_PRODUCT_PRO}
      - NEXT_PUBLIC_STRIPE_PRODUCT_STARTER=${STRIPE_PRODUCT_STARTER}
    networks:
      - infisical-dev

  mongo:
    image: mongo
    container_name: infisical-dev-mongo
    restart: always
    env_file: .env
    environment:
      - MONGO_INITDB_ROOT_USERNAME=${MONGO_USERNAME}
      - MONGO_INITDB_ROOT_PASSWORD=${MONGO_PASSWORD}
    volumes:
      - mongo-data:/data/db
    networks:
      - infisical-dev

  mongo-express:
    container_name: infisical-dev-mongo-express
    image: mongo-express
    restart: always
    depends_on:
      - mongo
    env_file: .env
    environment:
      - ME_CONFIG_MONGODB_ADMINUSERNAME=${MONGO_USERNAME}
      - ME_CONFIG_MONGODB_ADMINPASSWORD=${MONGO_PASSWORD}
      - ME_CONFIG_MONGODB_URL=mongodb://${MONGO_USERNAME}:${MONGO_PASSWORD}@mongo:27017/
    ports:
      - 8081:8081
    networks:
      - infisical-dev

  smtp-server:
    container_name: infisical-dev-smtp-server
    image: mailhog/mailhog
    restart: always
    logging:
      driver: 'none' # disable saving logs
    ports:
      - 1025:1025 # SMTP server
      - 8025:8025 # Web UI
    networks:
      - infisical-dev

volumes:
  mongo-data:
    driver: local

networks:
  infisical-dev:
