version: '3.7'

services:
  backend:
    build: 
      context: .
      dockerfile: Dockerfile.backend
    container_name: laravel_backend
    restart: always
    working_dir: /var/www/html
    depends_on:
      - backend_laravel_db
    volumes:
      - ./core-api:/var/www/html
    networks:
      - service_network

  backend_access_api_1:
    build:
      context: .
      dockerfile: Dockerfile.backend_access_api
    container_name: access_api_backend_1
    restart: always
    working_dir: /var/www/html
    depends_on:
      - backend_access_api_db_1
    volumes:
      - ./access-api:/var/www/html
    networks:
      - service_network

  backend_access_api_byplus_1:
    build:
      context: .
      dockerfile: Dockerfile.backend_access_api_byplus
    container_name: access_api_byplus_backend_1
    restart: always
    working_dir: /var/www/html
    depends_on:
      - backend_access_api_byplus_db_1
    volumes:
      - ./access-api-byplus:/var/www/html
    networks:
      - service_network

  backend_core_api_byplus_1:
    build:
      context: .
      dockerfile: Dockerfile.core_api_byplus
    container_name: core_api_byplus_backend_1
    restart: always
    working_dir: /var/www/html
    depends_on:
      - backend_laravel_db
    volumes:
      - ./core-api-byplus:/var/www/html
    networks:
      - service_network

  webserver:
    image: nginx:alpine
    container_name: nginx-webserver
    restart: unless-stopped
    ports:
      - 8091:80
    volumes:
      - ./core-api:/var/www/html
      - ./docker-compose/nginx/:/etc/nginx/conf.d/
    depends_on:
      - backend
    networks:
      - service_network

  webserver_access_api_1:
    image: nginx:alpine
    container_name: nginx-webserver_access_api_1
    restart: unless-stopped
    ports:
      - 8093:80
    volumes:
      - ./access-api:/var/www/html
      - ./docker-compose/nginx-access-api/:/etc/nginx/conf.d/
    depends_on:
      - backend_access_api_1
    networks:
      - service_network

  webserver_access_api_byplus_1:
    image: nginx:alpine
    container_name: nginx-webserver_access_api_byplus_1
    restart: unless-stopped
    ports:
      - 8094:80
    volumes:
      - ./access-api-byplus:/var/www/html
      - ./docker-compose/nginx-access-api-byplus/:/etc/nginx/conf.d/
    depends_on:
      - backend_access_api_byplus_1
    networks:
      - service_network

  webserver_core_api_byplus_1:
    image: nginx:alpine
    container_name: nginx-webserver_core_api_byplus_1
    restart: unless-stopped
    ports:
      - 8097:80
    volumes:
      - ./core-api-byplus:/var/www/html
      - ./docker-compose/nginx-core-api-byplus/:/etc/nginx/conf.d/
    depends_on:
      - backend_core_api_byplus_1
    networks:
      - service_network

  backend_laravel_db:
    image: postgres
    container_name: laravel_backend_database
    restart: always
    environment:
      POSTGRES_USER: laradmin
      POSTGRES_PASSWORD: larapwd
      POSTGRES_DB: laravel
    ports:
      - 5433:5432
    volumes:
      - database:/var/lib/postgresql/data
      - ./by_plus_test_db.sql:/by_plus_test_db.sql
      -  ./corenetbyusdb.sql:/corenetbyusdb.sql
      - ../volume-database-backend-1/laravel.sql:/docker-entrypoint-initdb.d/laravel.sql
    networks:
      - service_network

  backend_laravel_test_db:
    image: postgres
    container_name: laravel_backend_test_database
    restart: always
    environment:
      POSTGRES_USER: test_user
      POSTGRES_PASSWORD: test_password
      POSTGRES_DB: test_database
    ports:
      - 5435:5432
    volumes:
      - pg_test_data:/var/lib/postgresql/data
      - ../volume-database-backend-1/test_database.sql:/docker-entrypoint-initdb.d/test_database.sql
    networks:
      - service_network

  backend_access_api_db_1:
    image: postgres
    container_name: access_api_backend_database_1
    restart: always
    environment:
      POSTGRES_USER: access_api_admin
      POSTGRES_PASSWORD: access_api_password
      POSTGRES_DB: access_api_database
    ports:
      - 5437:5432
    volumes:
      - pg_access_api_database_1:/var/lib/postgresql/data
      - ../volume-database-backend-1/access_api_database.sql:/docker-entrypoint-initdb.d/access_api_database.sql
    networks:
      - service_network

  backend_access_api_byplus_db_1:
    image: postgres
    container_name: access_api_byplus_backend_database_1
    restart: always
    environment:
      POSTGRES_USER: access_api_byplus_1_admin
      POSTGRES_PASSWORD: access_api_byplus_1_password
      POSTGRES_DB: access_api_byplus_1_database
    ports:
      - 5438:5432
    volumes:
      - pg_access_api_byplus_database_1:/var/lib/postgresql/data
      - ../volume-database-backend-1/access_api_byplus_1_database.sql:/docker-entrypoint-initdb.d/access_api_byplus_1_database.sql
    networks:
      - service_network

  code-server:
    image: codercom/code-server:latest
    container_name: code-server
    user: 1001:1002
    ports:
      - "8081:8080"
    environment:
      PASSWORD: "ogO8IN28WqIgSHX"
    command: ["code-server", "--bind-addr", "0.0.0.0:8080", "/home/coder/project", "--disable-file-downloads"]
    volumes:
      #  - ./core-api:/home/coder/project/core-api
      - ./access-api:/home/coder/project/access-api
      - ./access-api-byplus:/home/coder/project/access-api-byplus
      - ./core-api-byplus:/home/coder/project/core-api-byplus
      - ./code-server-init.sh:/code-server-init.sh
    networks:
      - service_network

volumes:
  database:
  pg_test_data:
  pg_access_api_database_1:
  pg_access_api_byplus_database_1:

networks:
  service_network:
    driver: bridge
