version: "3.3" 

services:

  nginx:
    image: nginx:alpine
    container_name: nginx
    env_file: .env
    depends_on:
      - api
    ports:
      - 80:80
    volumes:
      - ./conf/nginx.conf:/etc/nginx/conf.d/default.conf
      # - ./containers/frontend:/var/www/html
    networks:
      - pongNetwork

  react_app:
    image: node:latest
    container_name: react_app
    working_dir: /app
    # depends_on:
    #   - nginx
    ports:
      - 8080:8080
    volumes:
    - ./containers/react:/app
      # - ./containers/react:/app
    networks:
      - pongNetwork
    entrypoint: ["sh", "-c" , "npm install && npm run start:dev"]


  api:
    image: node:latest
    container_name: api
    working_dir: /app
    ports:
      - 3000:3000
    env_file: .env
    depends_on:
      - postgresql
    networks:
      - pongNetwork
    volumes:
      - ./containers/api:/app
    entrypoint: ["sh", "-c" , "npm install && npm run start:dev"]

  postgresql:
    image: postgres:14.1-alpine
    restart: unless-stopped
    container_name: postgresql
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
    ports:
      - 5432:5432
    volumes:
      - db:/var/lib/postgresql/data
      - ./conf/init.sql:/docker-entrypoint-initdb.d/create_tables.sql
    networks:
      - pongNetwork

  pong:
    image: node:latest
    container_name: pong
    working_dir: /app
    ports:
      - 4000:4000
    env_file: .env
    networks:
      - pongNetwork
    volumes:
      - ./containers/pong:/app
    entrypoint: ["sh", "-c" , "npm install && npm run start:dev"]

  # chat:
  #   image: node:latest
  #   container_name: chat
  #   working_dir: /app
  #   ports:
  #     - 4001:4001
  #   env_file: .env
  #   networks:
  #     - pongNetwork
  #   volumes:
  #     - ./chat:/app
  #   entrypoint: ["sh", "-c" , "npm install && npm run start:dev"]


networks:
  pongNetwork:
    driver: bridge

volumes:
    # front_files:
    #   driver: local
    #   driver_opts:
    #     type: none
    #     o: 'bind'
    #     device: '/frontend'
    # dbdata:
    #   driver: local
    #   driver_opts:
    #     type: none
    #     o: 'bind'
    #     device: '/home/apommier/data/mariadb'
    # back:
    #   driver: local
    #   driver_opts:
    #     type: none
    #     o: 'bind'
    #     device: '/backend'
    db:
      driver: local