Skip to content

Commit

Permalink
[ADD] Docker compose dev env for new UI
Browse files Browse the repository at this point in the history
  • Loading branch information
whikernel committed Jan 9, 2025
1 parent 82f6511 commit 1a62c2c
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .env.model
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions docker-compose.base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 22 additions & 3 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion docker/nginx/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 13 additions & 0 deletions docker/nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down
10 changes: 8 additions & 2 deletions source/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions source/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions tests/data/basic.env
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 1a62c2c

Please sign in to comment.