From 1a62c2ced129247c95b2d888ab58cfa45107755e Mon Sep 17 00:00:00 2001 From: whikernel Date: Thu, 9 Jan 2025 15:53:51 +0100 Subject: [PATCH] [ADD] Docker compose dev env for new UI --- .env.model | 3 +++ docker-compose.base.yml | 2 ++ docker-compose.dev.yml | 25 ++++++++++++++++++++++--- docker/nginx/entrypoint.sh | 2 +- docker/nginx/nginx.conf | 13 +++++++++++++ source/app/__init__.py | 10 ++++++++-- source/requirements.txt | 1 + tests/data/basic.env | 3 +++ 8 files changed, 53 insertions(+), 6 deletions(-) diff --git a/.env.model b/.env.model index 164156e81..6806ccc57 100644 --- a/.env.model +++ b/.env.model @@ -33,6 +33,9 @@ IRIS_SECURITY_PASSWORD_SALT=ARandomSalt-NotThisOneEither IRIS_UPSTREAM_SERVER=app IRIS_UPSTREAM_PORT=8000 +IRIS_FRONTEND_SERVER=frontend +IRIS_FRONTEND_PORT=5173 + # -- WORKER CELERY_BROKER=amqp://rabbitmq diff --git a/docker-compose.base.yml b/docker-compose.base.yml index d7e6f5a03..865adc507 100644 --- a/docker-compose.base.yml +++ b/docker-compose.base.yml @@ -108,6 +108,8 @@ services: environment: - IRIS_UPSTREAM_SERVER - IRIS_UPSTREAM_PORT + - IRIS_FRONTEND_SERVER + - IRIS_FRONTEND_PORT - INTERFACE_HTTPS_PORT - SERVER_NAME - CERT_FILENAME diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 4bf00cfdd..16b63050f 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -44,9 +44,28 @@ services: volumes: - ./source/app:/iriswebapp/app - ./ui/dist:/iriswebapp/static - healthcheck: - test: curl --head --fail http://localhost:8000 || exit 1 - start_period: 60s + + frontend: + image: node:18-alpine + container_name: iris_sveltekit_frontend + working_dir: /app + environment: + - IRIS_SVELTEKIT_FRONTEND_DIR=${IRIS_SVELTEKIT_FRONTEND_DIR:-../frontend} + - PUBLIC_EXTERNAL_API_URL=https://127.0.0.1 + - PUBLIC_INTERNAL_API_URL=http://app:8000 + - PUBLIC_USE_MOCK_API_DATA=false + - ORIGIN=https://127.0.0.1 + - PROTOCOL_HEADER=x-forwarded-proto + - HOST_HEADER=x-forwarded-host + volumes: + - ${IRIS_SVELTEKIT_FRONTEND_DIR}:/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 worker: extends: diff --git a/docker/nginx/entrypoint.sh b/docker/nginx/entrypoint.sh index 6b0afe322..58c79278c 100644 --- a/docker/nginx/entrypoint.sh +++ b/docker/nginx/entrypoint.sh @@ -22,7 +22,7 @@ set -e # envsubst will make a substitution on every $variable in a file, since the nginx file contains nginx variable like $host, we have to limit the substitution to this set # otherwise, each nginx variable will be replaced by an empty string -envsubst '${INTERFACE_HTTPS_PORT} ${IRIS_UPSTREAM_SERVER} ${IRIS_UPSTREAM_PORT} ${SERVER_NAME} ${KEY_FILENAME} ${CERT_FILENAME}' < /etc/nginx/nginx.conf > /tmp/nginx.conf +envsubst '${INTERFACE_HTTPS_PORT} ${IRIS_UPSTREAM_SERVER} ${IRIS_UPSTREAM_PORT} ${SERVER_NAME} ${KEY_FILENAME} ${CERT_FILENAME} ${IRIS_FRONTEND_SERVER} ${IRIS_FRONTEND_PORT}' < /etc/nginx/nginx.conf > /tmp/nginx.conf cp /tmp/nginx.conf /etc/nginx/nginx.conf rm /tmp/nginx.conf diff --git a/docker/nginx/nginx.conf b/docker/nginx/nginx.conf index ce84a4503..0f4c2f663 100644 --- a/docker/nginx/nginx.conf +++ b/docker/nginx/nginx.conf @@ -120,6 +120,18 @@ http { add_header Front-End-Https on; location / { + proxy_pass http://${IRIS_FRONTEND_SERVER}:${IRIS_FRONTEND_PORT}; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header Host $host; + proxy_cache_bypass $http_upgrade; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header Origin $http_origin; + } + + location /api/v2/ { proxy_pass http://${IRIS_UPSTREAM_SERVER}:${IRIS_UPSTREAM_PORT}; location ~ ^/(manage/templates/add|manage/cases/upload_files) { @@ -142,6 +154,7 @@ http { proxy_pass http://${IRIS_UPSTREAM_SERVER}:${IRIS_UPSTREAM_PORT}; } } + location /socket.io { proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; diff --git a/source/app/__init__.py b/source/app/__init__.py index 12bae6e0a..bf63eb441 100644 --- a/source/app/__init__.py +++ b/source/app/__init__.py @@ -66,7 +66,9 @@ class AlertsNamespace(Namespace): app = Flask(__name__, static_folder='../static') -CORS(app, supports_credentials=True, origins=["http://localhost:5173", "http://localhost:8000"]) +# CORS(app, +# supports_credentials=True, +# resources={r"/api/*": {"origins": ["http://127.0.0.1:5137", "http://localhost:5173"]}}) def ac_current_user_has_permission(*permissions): @@ -102,7 +104,7 @@ def ac_current_user_has_manage_perms(): app.config.update( SESSION_COOKIE_SECURE=True, SESSION_COOKIE_HTTPONLY=True, - SESSION_COOKIE_SAMESITE='None' + SESSION_COOKIE_SAMESITE='Lax' ) cache = Cache(app) @@ -148,6 +150,10 @@ def shutdown_session(exception=None): @app.after_request def after_request(response): + response.headers.add('Access-Control-Allow-Origin', '*') + response.headers.add('Access-Control-Allow-Credentials', 'true') + response.headers.add('Access-Control-Allow-Headers', 'Content-Type, Authorization') + response.headers.add('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS') return response diff --git a/source/requirements.txt b/source/requirements.txt index ecb4bf0b8..572a98360 100644 --- a/source/requirements.txt +++ b/source/requirements.txt @@ -8,6 +8,7 @@ Flask-SQLAlchemy==3.1.1 Flask-WTF==1.2.2 flask-marshmallow==1.2.1 Flask-Caching==2.3.0 +flask-cors==5.0.0 marshmallow==3.23.1 marshmallow-sqlalchemy==1.1.0 gunicorn==23.0.0 diff --git a/tests/data/basic.env b/tests/data/basic.env index 76a6e035d..c6403b0e5 100644 --- a/tests/data/basic.env +++ b/tests/data/basic.env @@ -20,6 +20,9 @@ IRIS_SECURITY_PASSWORD_SALT=ARandomSalt-NotThisOneEither IRIS_UPSTREAM_SERVER=app IRIS_UPSTREAM_PORT=8000 +IRIS_FRONTEND_SERVER=frontend +IRIS_FRONTEND_PORT=5173 + # -- WORKER CELERY_BROKER=amqp://rabbitmq