-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Customized S2I script run to use the default community version for th…
…is image
- Loading branch information
1 parent
c0ba295
commit fbcff44
Showing
1 changed file
with
83 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#!/bin/bash | ||
|
||
# S2I run script for the 'nodejs' image. | ||
# The run script executes the server that runs your application. | ||
# | ||
# For more information see the documentation: | ||
# https://github.com/openshift/source-to-image/blob/master/docs/builder_image.md | ||
# | ||
|
||
set -e | ||
|
||
if [ -e "/opt/app-root/etc/generate_container_user" ]; then | ||
source /opt/app-root/etc/generate_container_user | ||
fi | ||
|
||
# Runs the nodejs application server. If the container is run in development mode, | ||
# hot deploy and debugging are enabled. | ||
run_node() { | ||
echo -e "Environment: \n\tDEV_MODE=${DEV_MODE}\n\tNODE_ENV=${NODE_ENV}\n\tDEBUG_PORT=${DEBUG_PORT}" | ||
if [ "$DEV_MODE" == true ]; then | ||
echo "Launching via nodemon..." | ||
exec nodemon --inspect="$DEBUG_PORT" | ||
elif [ -n "$NODE_CMD" ] && [ "$INIT_WRAPPER" == true ]; then | ||
echo "launching via init wrapper..." | ||
exec ${STI_SCRIPTS_PATH}/init-wrapper $NODE_CMD | ||
elif [ -n "$NODE_CMD" ] && [ "$INIT_WRAPPER" == false ]; then | ||
echo "Launching via ${NODE_CMD}" | ||
exec $NODE_CMD | ||
elif [ ! -n "$NODE_CMD" ] && [ "$INIT_WRAPPER" == true ]; then | ||
|
||
package_json_start=$(sed -n 's/\s*"start"\s*:\s*"\(.*\)".*/\1/p' package.json) | ||
package_json_main=$(sed -n 's/\s*"main"\s*:\s*"\(.*\)".*/\1/p' package.json) | ||
|
||
if [ -n "$package_json_start" ]; then | ||
start_command=$package_json_start | ||
elif [ -n $package_json_main ]; then | ||
start_command="node ." | ||
elif [ -f "server.js" ]; then | ||
start_command="node server.js" | ||
else | ||
echo "Failed to find file for starting the Node.js application" | ||
exit 1 | ||
fi | ||
echo "launching via init wrapper..." | ||
exec ${STI_SCRIPTS_PATH}/init-wrapper $start_command | ||
else | ||
echo "Launching via npm..." | ||
exec npm run -d $NPM_RUN | ||
fi | ||
} | ||
|
||
#Set the debug port to 5858 by default. | ||
if [ -z "$DEBUG_PORT" ]; then | ||
export DEBUG_PORT=5858 | ||
fi | ||
|
||
# Set the environment to development by default. | ||
if [ -z "$DEV_MODE" ]; then | ||
export DEV_MODE=false | ||
fi | ||
|
||
# If NODE_ENV is not set by the user, then NODE_ENV is determined by whether | ||
# the container is run in development mode. | ||
if [ -z "$NODE_ENV" ]; then | ||
if [ "$DEV_MODE" == true ]; then | ||
export NODE_ENV=development | ||
else | ||
export NODE_ENV=production | ||
fi | ||
fi | ||
|
||
# If the official dockerhub node image is used, skip the SCL setup below | ||
# and just run the nodejs server | ||
if [ -d "/usr/src/app" ]; then | ||
run_node | ||
fi | ||
|
||
# Allow users to inspect/debug the builder image itself, by using: | ||
# $ docker run -i -t openshift/centos-nodejs-builder --debug | ||
# | ||
[ "$1" == "--debug" ] && exec /bin/bash | ||
|
||
run_node |