Skip to content

Commit

Permalink
fix(docker): add additional build options
Browse files Browse the repository at this point in the history
This allows the user to separate out building the venv, launcher, and www.

The default behavior is that all will build if they do not exist. If they do exist,
then they will not be built.

However, the user can now select some options via a `TRAME_BUILD` environment variable.
If this string contains (single or any combination of) "venv", "launcher", or "www",
then those respective parts will be re-built, even if they already exist.

Additionally, a "no_www" can be specified in the `TRAME_BUILD` environment variable,
which indicates to skip the `www` generation, even if it does not exist.

Signed-off-by: Patrick Avery <[email protected]>
  • Loading branch information
psavery authored and jourdain committed Dec 11, 2022
1 parent 0d06739 commit 8ad6f44
Showing 1 changed file with 31 additions and 13 deletions.
44 changes: 31 additions & 13 deletions docker/scripts/server.sh
Original file line number Diff line number Diff line change
@@ -1,34 +1,52 @@
#!/usr/bin/env bash

if [ ! -d $TRAME_VENV ]
then
# We have access to PyYAML in the root python environment.
# Convert the apps.yml file to json and put it in the right place.
python /opt/trame/yaml_to_json.py /deploy/setup/apps.yml /opt/trame/apps.json
LAUNCHER_OUTPUT_PATH=/deploy/server/launcher.json
WWW_PATH=/deploy/server/www

# Convert the apps.yml file to json and put it in the right place.
# This needs PyYAML, which is in the root python environment, so
# we must do this before activating the venv.
python /opt/trame/yaml_to_json.py /deploy/setup/apps.yml /opt/trame/apps.json

# venv
# Build if it does not exist, or if "venv" is in `TRAME_BUILD`
if [[ ! -d $TRAME_VENV || $TRAME_BUILD == *"venv"* ]]; then
# In case we are doing a force rebuild, make sure the directory is deleted
rm -rf $TRAME_VENV

# Create (and activate) the venv
. /opt/trame/create_venv.sh

# Run the initialize script (if it exists)
if [ -f /deploy/setup/initialize.sh ]
then
if [[ -f /deploy/setup/initialize.sh ]]; then
. /deploy/setup/initialize.sh
fi

# Install any specified requirements
. /opt/trame/install_requirements.sh
else
# Activate it if we skipped building it
. /opt/trame/activate_venv.sh
fi

# Generate launcher.json and the www directory
# launcher
# Build if it does not exist, or if "launcher" is in `TRAME_BUILD`
if [[ ! -f $LAUNCHER_OUTPUT_PATH || $TRAME_BUILD == *"launcher"* ]]; then
python /opt/trame/generate_launcher_config.py
fi

# www
# This must be done after activating the venv.
# This directory should already exist.
# Build if "no_www" is not in `TRAME_BUILD` and either it is empty or "www" is in `TRAME_BUILD`
if [[ $TRAME_BUILD != *"no_www"* ]] && [[ -z "$(ls -A $WWW_PATH)" || $TRAME_BUILD == *"www"* ]]; then
# Generate launcher.json and the www directory
python /opt/trame/generate_www.py

# Merge any user-created www directories with the generated one
if [ -d /deploy/setup/www ]
then
if [[ -d /deploy/setup/www ]]; then
cp -r /deploy/setup/www/* /deploy/server/www
fi
else
. /opt/trame/activate_venv.sh
fi

if [[ $TRAME_BUILD_ONLY == 1 ]]; then
Expand All @@ -42,7 +60,7 @@ fi
# that the user doing the "docker run ..." has set up an external directory
# containing a "server/launcher.json" filepath and mounts that path as
# "/deploy".
cp /deploy/server/launcher.json /opt/trame/config-template.json
cp $LAUNCHER_OUTPUT_PATH /opt/trame/config-template.json

# This performs replacements on the launcher-template.json copied into place
# above, based on the presence of environment variables passed with "-e" to the
Expand Down

0 comments on commit 8ad6f44

Please sign in to comment.