Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(docker): separate out build and run steps
This also updates the README with new relevant instructions. Signed-off-by: Patrick Avery <patrick.avery@kitware.com>
- Loading branch information
Showing
8 changed files
with
184 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,63 @@ | ||
#!/usr/bin/env bash | ||
|
||
if [ ! -d /deploy/setup ]; then | ||
echo "ERROR: The 'setup' directory must be present in the container at '/deploy/setup'" | ||
exit 1 | ||
fi | ||
|
||
# Put any arguments into the `TRAME_BUILD` variable | ||
# This is so you can do things like `/opt/trame/build.sh no_www venv`, etc. | ||
export TRAME_BUILD="$*" | ||
export TRAME_BUILD_ONLY=1 | ||
# This is so you can do things like `/opt/trame/build.sh no_www venv`, etc., | ||
# or "build no_www venv" via the default entrypoint. | ||
TRAME_BUILD="$*" | ||
|
||
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. | ||
# We will do this every time, because it is needed in both the launcher | ||
# step and the www step. | ||
python /opt/trame/yaml_to_json.py /deploy/setup/apps.yml /opt/trame/apps.json | ||
|
||
# launcher | ||
# Build if it does not exist, or if "launcher" is in `TRAME_BUILD` | ||
if [[ ! -f $LAUNCHER_OUTPUT_PATH || $TRAME_BUILD == *"launcher"* ]]; then | ||
# Generate the launcher config | ||
python /opt/trame/generate_launcher_config.py | ||
fi | ||
|
||
# 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 | ||
. /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 | ||
|
||
# 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 the www directory | ||
python /opt/trame/generate_www.py | ||
|
||
/opt/trame/entrypoint.sh | ||
# Merge any user-created www directories with the generated one | ||
if [[ -d /deploy/setup/www ]]; then | ||
cp -r /deploy/setup/www/* /deploy/server/www | ||
fi | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,22 @@ | ||
#!/usr/bin/env bash | ||
|
||
if [ ! -d /deploy/server ] && [ ! -d /deploy/setup ] | ||
then | ||
echo "ERROR: The deploy directory must be mounted into the container at /deploy" | ||
exit 1 | ||
fi | ||
|
||
# Fix any uid/gid mismatch | ||
/opt/trame/fix_uid_gid.sh | ||
# The entrypoint provides some branching logic as to what we | ||
# are going to do. By default, it runs the server. | ||
# If the first argument is "build", however, it will build the | ||
# server instead, and forward any extra args to the build script. | ||
|
||
# Ensure the needed directories exist | ||
gosu trame-user /opt/trame/make_directories.sh | ||
# First, perform initial setup | ||
. /opt/trame/setup.sh | ||
|
||
# Restart apache | ||
service apache2 restart | ||
|
||
# Start the server | ||
gosu trame-user /opt/trame/server.sh | ||
if [[ "$1" == "build" ]]; then | ||
# Run the build | ||
# Forward all arguments after `build`, so the user can pass things | ||
# like `www venv launcher` etc. | ||
echo "Running build..." | ||
gosu trame-user /opt/trame/build.sh ${@:2} | ||
echo "Build complete" | ||
else | ||
# Start the server | ||
echo "Starting server..." | ||
gosu trame-user /opt/trame/run.sh | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/usr/bin/env bash | ||
|
||
# This script is used to start the trame server. | ||
# If the `TRAME_USE_HOST` environment variable is set, this | ||
# will replace `USE_HOST` in the launcher json file. If it contains | ||
# `://`, it will replace `ws://USE_HOST` instead. | ||
|
||
if [ ! -d /deploy/server ]; then | ||
echo "ERROR: The the server directory must be in the container at '/deploy/server'" | ||
exit 1 | ||
fi | ||
|
||
# First, activate the venv | ||
. /opt/trame/activate_venv.sh | ||
|
||
# We will copy the launcher and make any needed edits to it | ||
LAUNCHER_TEMPLATE_PATH=/deploy/server/launcher.json | ||
LAUNCHER_PATH=/opt/trame/config.json | ||
|
||
OUTPUT=$(<"${LAUNCHER_TEMPLATE_PATH}") | ||
|
||
if [[ -n $TRAME_USE_HOST ]]; then | ||
REPLACEMENT_STRING="USE_HOST" | ||
if [[ $TRAME_USE_HOST == *"://"* ]]; then | ||
# If the string contains "://", then we are replacing the "ws://" at | ||
# the beginning as well | ||
REPLACEMENT_STRING="ws://$REPLACEMENT_STRING" | ||
fi | ||
OUTPUT="${OUTPUT//$REPLACEMENT_STRING/$TRAME_USE_HOST}" | ||
fi | ||
|
||
echo -e "$OUTPUT" > "${LAUNCHER_PATH}" | ||
|
||
# Run the launcher in the foreground so this script doesn't end | ||
echo "Starting the wslink launcher at" | ||
python -m wslink.launcher ${LAUNCHER_PATH} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/env bash | ||
|
||
if [ ! -d /deploy/server ] && [ ! -d /deploy/setup ] | ||
then | ||
echo "ERROR: The deploy directory must be mounted into the container at /deploy" | ||
exit 1 | ||
fi | ||
|
||
# Fix any uid/gid mismatch | ||
/opt/trame/fix_uid_gid.sh | ||
|
||
# Ensure the needed directories exist | ||
gosu trame-user /opt/trame/make_directories.sh | ||
|
||
# Restart apache | ||
service apache2 restart |
Oops, something went wrong.