Skip to content

Commit

Permalink
ci(docker): try to get docker prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
jourdain committed Jun 27, 2024
1 parent 10ff703 commit 52ecb18
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions docker/Dockerfile.common
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
34 changes: 34 additions & 0 deletions docker/config/apache/001-trame.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<VirtualHost *:80>
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/

<Directory /deploy/server/www>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>

# 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]

</VirtualHost>
15 changes: 15 additions & 0 deletions docker/scripts/runtime_patch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

4 comments on commit 52ecb18

@Rafaelrr5
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now when I run my server with my trame/paraview app the error "no module named 'trame'" comes. What do I have to do to adapt to these changes?

@jourdain
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change listed should not affect anything ParaView or not. So the real question is: what is your setup/config that leads to the fact that the venv is not loaded within pvpython.

@Rafaelrr5
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was working fine and after the image commit it stopped running my server. I am running a docker server with the singlefile config. The only change I had to make with the new commit it was to change permissions for /tmp folder because of an error on "apt update": RUN chmod 1777 /tmp on Dockerfile
image

@jourdain
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, that's interesting, and thanks for sharing your findings. I'm not sure what the cause could be. Maybe it's related to an update in the Ubuntu base layer.

Otherwise, I'm not sure why you have those 2 last args. Normally if you set PV_VENV environment variable and you have the following import import paraview.web.venv as first line in your app.py, it should just work.

Please sign in to comment.