diff --git a/docker/Dockerfile.common b/docker/Dockerfile.common index ffa7704f..4d720336 100644 --- a/docker/Dockerfile.common +++ b/docker/Dockerfile.common @@ -51,6 +51,7 @@ RUN groupadd trame-user -g 1000 && \ # Copy the apache configuration file into place COPY config/apache/001-trame.conf /etc/apache2/sites-available/001-trame.conf +COPY config/apache/001-trame.tpl /opt/trame/apache.tpl COPY config/default-launcher.json /opt/trame/default-launcher.json # Configure the apache web server diff --git a/docker/README.md b/docker/README.md index 469b9f12..c659f474 100644 --- a/docker/README.md +++ b/docker/README.md @@ -32,6 +32,10 @@ In case you aim the trame application to read/write files on a mounted directory Path iniside docker for checking ownership and remapping that UID/GID to the unpriviledge trame-user within docker. +- __TRAME_URL_PREFIX__ + + Path to serve content from. Rather that serving everything from `/`, when `TRAME_URL_PREFIX` is defined to `/app`, that means you should connect to `/app` in order to get access to the trame content. Same for `/app/launcher` and `/app/api/*`. + ## Building the Server To run your application in a Trame Docker image, a server directory must be present that contains everything required to run the application. This includes the static website (www) that needs to be served, instructions for starting the application (launcher) when a user requests access, and the Python dependencies that are needed to run it (venv). diff --git a/docker/config/apache/001-trame.tpl b/docker/config/apache/001-trame.tpl new file mode 100644 index 00000000..02f8c9ac --- /dev/null +++ b/docker/config/apache/001-trame.tpl @@ -0,0 +1,34 @@ + + DocumentRoot /deploy/server/www + ErrorLog /deploy/server/logs/apache/error.log + CustomLog /deploy/server/logs/apache/access.log combined + + Alias TRAME_URL_PREFIX /deploy/server/www/ + + + Options Indexes FollowSymLinks + AllowOverride None + Require all granted + + + # Set CORS headers + Header set Access-Control-Allow-Origin "*" + + # Handle launcher forwarding + ProxyPass TRAME_URL_PREFIX/launcher http://localhost:9000/paraview + ProxyPassReverse TRAME_URL_PREFIX/launcher http://localhost:9000/paraview + + # Handle paraview forwarding + ProxyPass TRAME_URL_PREFIX/paraview http://localhost:9000/paraview + ProxyPassReverse TRAME_URL_PREFIX/paraview http://localhost:9000/paraview + + # Handle WebSocket forwarding + RewriteEngine On + RewriteMap session-to-port txt:/opt/trame/proxy-mapping.txt + RewriteCond %{QUERY_STRING} ^sessionId=(.*)&path=(.*)$ [NC] + RewriteRule ^TRAME_URL_PREFIX/proxy.*$ ws://${session-to-port:%1}/%2 [P] + + # Handle API forwarding + RewriteRule ^TRAME_URL_PREFIX/api/(.*)/(.*)$ http://${session-to-port:$1}/$2 [P,L] + + diff --git a/docker/scripts/runtime_patch.sh b/docker/scripts/runtime_patch.sh index bbc740f4..d64ec942 100755 --- a/docker/scripts/runtime_patch.sh +++ b/docker/scripts/runtime_patch.sh @@ -23,3 +23,18 @@ then docker_gid=$(stat -c '%g' $dnd_socket) groupmod --gid $docker_gid docker fi + +# Patch Apache configuration to add prefix +if [ -d "$TRAME_URL_PREFIX" ] +then + TEMPLATE_INPUT=/opt/trame/apache.tpl + CONFIG_OUTPUT=/etc/apache2/sites-available/001-trame.conf + + OUTPUT=$(<"${TEMPLATE_INPUT}") + + REPLACEMENT_STRING="TRAME_URL_PREFIX" + OUTPUT="${OUTPUT//$REPLACEMENT_STRING/$TRAME_URL_PREFIX}" + echo -e "$OUTPUT" > "${CONFIG_OUTPUT}" + + systemctl restart apache2 +fi \ No newline at end of file