#  IRIS Source Code
#  contact@dfir-iris.org
#
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU Lesser General Public
#  License as published by the Free Software Foundation; either
#  version 3 of the License, or (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#  Lesser General Public License for more details.
#
#  You should have received a copy of the GNU Lesser General Public License
#  along with this program; if not, write to the Free Software Foundation,
#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

services:
  rabbitmq:
    extends:
      file: docker-compose.base.yml
      service: rabbitmq

  db:
    extends:
      file: docker-compose.base.yml
      service: db
    build:
      context: docker/db
    image: iriswebapp_db:develop
    ports:
      - "127.0.0.1:5432:5432"

  app:
    extends:
      file: docker-compose.base.yml
      service: app
    build:
      context: .
      dockerfile: docker/webApp/Dockerfile
    image: iriswebapp_app:develop
    ports:
      - "8000:8000"
    volumes:
      - ./source/app:/iriswebapp/app
      - ./ui/dist:/iriswebapp/static
    healthcheck:
      test: curl --head --fail http://localhost:8000 || exit 1
      start_period: 60s

  worker:
    extends:
      file: docker-compose.base.yml
      service: worker
    build:
      context: .
      dockerfile: docker/webApp/Dockerfile
    image: iriswebapp_app:develop
    volumes:
      - ./source/app:/iriswebapp/app

  nginx:
    extends:
      file: docker-compose.base.yml
      service: nginx
    build:
      context: ./docker/nginx
      args:
        NGINX_CONF_GID: 1234
        NGINX_CONF_FILE: ${NGINX_CONF_FILE:-nginx.conf}
    image: iriswebapp_nginx:develop

  frontend:
    image: node:22-alpine
    profiles: ["new-ui"]
    container_name: iris_sveltekit_frontend
    working_dir: /app
    environment:
      - IRIS_SVELTEKIT_FRONTEND_DIR=${IRIS_SVELTEKIT_FRONTEND_DIR:-../iris-frontend}
      - PUBLIC_EXTERNAL_API_URL=${PUBLIC_EXTERNAL_API_URL:-https://127.0.0.1}
      - PUBLIC_INTERNAL_API_URL=http://${IRIS_UPSTREAM_SERVER}:${IRIS_UPSTREAM_PORT}
      - PUBLIC_USE_MOCK_API_DATA=false
      - ORIGIN=https://127.0.0.1
      - PROTOCOL_HEADER=x-forwarded-proto
      - HOST_HEADER=x-forwarded-host
      - NODE_ENV=development
    volumes:
      - ${IRIS_SVELTEKIT_FRONTEND_DIR:-../iris-frontend}:/app # Map the frontend directory dynamically
      - /app/node_modules # Ensure `node_modules` is preserved inside the container
    ports:
      - "5173:5173"
    command: sh -c "npm install && npm run dev -- --host"
    networks:
      - iris_backend
      - iris_frontend

volumes:
  iris-downloads:
  user_templates:
  server_data:
  db_data:

networks:
  iris_backend:
    name: iris_backend
  iris_frontend:
    name: iris_frontend
