spiff-arena/spiffworkflow-frontend/bin/boot_server_in_docker
jasquat 9147a8db8c
Use vite to build (#1390)
* some base updates for vite w/ burnettk

* i can log in w/ burnettk

* a couple more fixes w/ burnettk

* make sure selectedTabIndex has been set before using it w/ burnettk

* fixed active-users db issue, added type module to package json to fix prerender issues, and various other issues w/ burnettk

* fixed issues with building and running from compiled w/ burnettk

* pyl

* eslint fix is running and removed both inferno and navigationBar warnings

* vim likes the Dockerfile suffix by default

* use process.env.HOME

* probably do not need alias

* a little clean up and fixed font warnings w/ burnettk

* updated elements to remove warnings in the console w/ burnettk

* fixed es lint issues w/ burnettk

* update docker build in frontend w/ burnettk

* set the specific tag of nginx w/ burnettk

* build docker imgaes for this branch to test w/ burnettk

* added vitest and updated Dockerfile to be nginx w/ burnettk

* tests are passing w/ burnettk

* add prefresh and more keys

* added cypress-vite to attempt to get cypress working again

* some coderabbit suggestions

* hopefully there is no reason to use PUBLIC_URL at all when using vite

* use the correct location of the index file in the docker image

* spaces are fine in index.html file variable declaration

---------

Co-authored-by: jasquat <jasquat@users.noreply.github.com>
Co-authored-by: burnettk <burnettk@users.noreply.github.com>
2024-04-15 14:22:34 -04:00

55 lines
2.3 KiB
Bash
Executable File

#!/usr/bin/env bash
function error_handler() {
echo >&2 "Exited with BAD EXIT CODE '${2}' in ${0} script at line: ${1}."
exit "$2"
}
trap 'error_handler ${LINENO} $?' ERR
set -o errtrace -o errexit -o nounset -o pipefail
# sort of like https://lithic.tech/blog/2020-05/react-dynamic-config, but without golang
react_configs=$(env | grep -E "^SPIFFWORKFLOW_FRONTEND_RUNTIME_CONFIG_" || echo '')
if [[ -n "$react_configs" ]]; then
index_html_file="/usr/share/nginx/html/index.html"
if [[ ! -f "$index_html_file" ]]; then
echo >&2 "ERROR: Could not find '${index_html_file}'. Cannot use SPIFFWORKFLOW_FRONTEND_RUNTIME_CONFIG values without it."
exit 1
fi
if ! command -v sed >/dev/null; then
echo >&2 "ERROR: sed command not found. Cannot use SPIFFWORKFLOW_FRONTEND_RUNTIME_CONFIG values without it."
exit 1
fi
if ! command -v perl >/dev/null; then
echo >&2 "ERROR: perl command not found. Cannot use SPIFFWORKFLOW_FRONTEND_RUNTIME_CONFIG values without it."
exit 1
fi
for react_config in $react_configs; do
react_config_without_prefix=$(sed -E 's/^SPIFFWORKFLOW_FRONTEND_RUNTIME_CONFIG_([^=]*)=(.*)/\1=\\"\2\\"/' <<<"${react_config}")
if [[ -z "$react_config_without_prefix" ]]; then
echo >&2 "ERROR: Could not parse react config line: '${react_config}'."
exit 1
fi
escaped_react_config=$(sed -E 's|/|\\/|g' <<<"${react_config_without_prefix}")
# actually do the search and replace to add the js config to the html page
perl -pi -e "s/(window.spiffworkflowFrontendJsenv *= *\{\})/\1;window.spiffworkflowFrontendJsenv.${escaped_react_config}/" "$index_html_file"
if ! grep -Eq "${react_config_without_prefix}" "$index_html_file"; then
echo >&2 "ERROR: Could not find '${react_config_without_prefix}' in '${index_html_file}' after search and replace. It is likely that the assumptions in boot_server_in_docker about the contents of the html page have changed. Fix the glitch in boot_server_in_docker."
exit 1
fi
done
fi
port_to_use="${PORT0:-80}"
if [[ -n "${SPIFFWORKFLOW_FRONTEND_INTERNAL_PORT:-}" ]]; then
port_to_use="$SPIFFWORKFLOW_FRONTEND_INTERNAL_PORT"
fi
perl -p -e "s/{{SPIFFWORKFLOW_FRONTEND_INTERNAL_PORT}}/${port_to_use}/" /var/tmp/nginx.conf.template >/etc/nginx/conf.d/default.conf
exec nginx -g "daemon off;"