Skip to content

Commit cd62867

Browse files
committed
Initial version to allow a user to run a custom version of Node.js on
OpenShift. The user can easily switch between Node versions(e.g. 0.8.9 to 0.9.1) by just editing the .openshift/markers/NODEJS_VERSION file.
1 parent 7e600a7 commit cd62867

30 files changed

+1004
-3
lines changed

.openshift/action_hooks/build

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
# This is a simple build script and will be executed on your CI system if
3+
# available. Otherwise it will execute while your application is stopped
4+
# before the deploy step. This script gets executed directly, so it
5+
# could be python, php, ruby, etc.
6+
7+
8+
# Source utility functions.
9+
source "$OPENSHIFT_REPO_DIR/.openshift/lib/utils"
10+
11+
# Setup path to include the custom Node[.js] version.
12+
_SHOW_SETUP_PATH_MESSAGES="true" setup_path_for_custom_node_version
13+
14+
15+
# So we we moved the package.json file out of the way in pre_build,
16+
# so that the OpenShift git post-receive hook doesn't try and use the
17+
# old npm version to install the dependencies. Move it back in.
18+
tmp_package_json="$(get_node_tmp_dir)/package.json"
19+
if [ -f "$tmp_package_json" ]; then
20+
# Only overlay it if there is no current package.json file.
21+
[ -f "${OPENSHIFT_REPO_DIR}/package.json" ] || \
22+
mv "$tmp_package_json" "${OPENSHIFT_REPO_DIR}/package.json"
23+
fi
24+
25+
26+
# Do npm install with the new npm binary.
27+
if [ -f "${OPENSHIFT_REPO_DIR}"/package.json ]; then
28+
echo " - Installing dependencies w/ new version of npm ... "
29+
echo
30+
(cd "${OPENSHIFT_REPO_DIR}"; export TMPDIR="/tmp"; npm install -d)
31+
fi
32+

.openshift/action_hooks/deploy

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
# This deploy hook gets executed after dependencies are resolved and the
3+
# build hook has been run but before the application has been started back
4+
# up again. This script gets executed directly, so it could be python, php,
5+
# ruby, etc.
6+
7+
8+
# Source utility functions.
9+
source "$OPENSHIFT_REPO_DIR/.openshift/lib/utils"
10+
11+
12+
# On slave/serving gears, need to do the install as part of deploy
13+
# so check if its needed. Just ensure the custom Node[.js] version is
14+
# installed.
15+
ensure_node_is_installed
16+

.openshift/action_hooks/post_deploy

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
# This is a simple post deploy hook executed after your application
3+
# is deployed and started. This script gets executed directly, so
4+
# it could be python, php, ruby, etc.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
3+
# The pre_start_cartridge and pre_stop_cartridge hooks are *SOURCED*
4+
# immediately before (re)starting or stopping the specified cartridge.
5+
# They are able to make any desired environment variable changes as
6+
# well as other adjustments to the application environment.
7+
8+
# The post_start_cartridge and post_stop_cartridge hooks are executed
9+
# immediately after (re)starting or stopping the specified cartridge.
10+
11+
# Exercise caution when adding commands to these hooks. They can
12+
# prevent your application from stopping cleanly or starting at all.
13+
# Application start and stop is subject to different timeouts
14+
# throughout the system.
15+
16+
# Source utility functions.
17+
source "$OPENSHIFT_REPO_DIR/.openshift/lib/utils"
18+
19+
# Get the node version.
20+
ver=$(get_node_version)
21+
22+
23+
# Set URI to the custom sample /env route.
24+
app_uri="http://$OPENSHIFT_GEAR_DNS/env"
25+
26+
# Wait a bit to give the server time to come up.
27+
sleep 5
28+
29+
# Check if the app_uri is available - user code could have removed the
30+
# one in the sample -- we just print this for sanity testing.
31+
zcode=$(curl --write-out %{http_code} -s -o /dev/null "$app_uri")
32+
33+
if [ "$zcode" -eq 200 ]; then
34+
echo ""
35+
echo " - Using Node.js version $ver, checking app URI ... "
36+
echo " - test URI = $app_uri"
37+
echo " - Version from test URI = $(curl -s $app_uri | grep 'Version')"
38+
echo ""
39+
fi
40+
41+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
# The pre_start_cartridge and pre_stop_cartridge hooks are *SOURCED*
4+
# immediately before (re)starting or stopping the specified cartridge.
5+
# They are able to make any desired environment variable changes as
6+
# well as other adjustments to the application environment.
7+
8+
# The post_start_cartridge and post_stop_cartridge hooks are executed
9+
# immediately after (re)starting or stopping the specified cartridge.
10+
11+
# Exercise caution when adding commands to these hooks. They can
12+
# prevent your application from stopping cleanly or starting at all.
13+
# Application start and stop is subject to different timeouts
14+
# throughout the system.

.openshift/action_hooks/pre_build

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
# This is a simple script and will be executed on your CI system if
3+
# available. Otherwise it will execute while your application is stopped
4+
# before the build step. This script gets executed directly, so it
5+
# could be python, php, ruby, etc.
6+
7+
8+
# Source utility functions.
9+
source "$OPENSHIFT_REPO_DIR/.openshift/lib/utils"
10+
11+
# Ensure custom node version if not installed.
12+
echo ""
13+
ensure_node_is_installed
14+
15+
16+
# We need to move the package.json file out of the way in pre_build, so
17+
# that the OpenShift git post-receive hook doesn't try and use the old
18+
# npm version to install the dependencies.
19+
mv "${OPENSHIFT_REPO_DIR}/package.json" "$(get_node_tmp_dir)"
20+
21+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
# The pre_start_cartridge and pre_stop_cartridge hooks are *SOURCED*
4+
# immediately before (re)starting or stopping the specified cartridge.
5+
# They are able to make any desired environment variable changes as
6+
# well as other adjustments to the application environment.
7+
8+
# The post_start_cartridge and post_stop_cartridge hooks are executed
9+
# immediately after (re)starting or stopping the specified cartridge.
10+
11+
# Exercise caution when adding commands to these hooks. They can
12+
# prevent your application from stopping cleanly or starting at all.
13+
# Application start and stop is subject to different timeouts
14+
# throughout the system.
15+
16+
17+
# Source utility functions.
18+
source "$OPENSHIFT_REPO_DIR/.openshift/lib/utils"
19+
20+
# Setup path to include the custom Node[.js] version.
21+
ver=$(get_node_version)
22+
echo ""
23+
echo " - pre_start_nodejs: Adding Node.js version $ver binaries to path"
24+
_SHOW_SETUP_PATH_MESSAGES="true" setup_path_for_custom_node_version
25+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
3+
# The pre_start_cartridge and pre_stop_cartridge hooks are *SOURCED*
4+
# immediately before (re)starting or stopping the specified cartridge.
5+
# They are able to make any desired environment variable changes as
6+
# well as other adjustments to the application environment.
7+
8+
# The post_start_cartridge and post_stop_cartridge hooks are executed
9+
# immediately after (re)starting or stopping the specified cartridge.
10+
11+
# Exercise caution when adding commands to these hooks. They can
12+
# prevent your application from stopping cleanly or starting at all.
13+
# Application start and stop is subject to different timeouts
14+
# throughout the system.
15+
16+
17+
# First time in .openshift/lib/utils might not exist, so add a check
18+
# to ensure file exists.
19+
if [ -f "$OPENSHIFT_REPO_DIR/.openshift/lib/utils" ]; then
20+
# Source utility functions.
21+
source "$OPENSHIFT_REPO_DIR/.openshift/lib/utils"
22+
23+
# Setup path to include the custom Node[.js] version.
24+
ver=$(get_node_version)
25+
echo ""
26+
echo " - pre_stop_nodejs: Adding Node.js version $ver binaries to path"
27+
_SHOW_SETUP_PATH_MESSAGES="true" setup_path_for_custom_node_version
28+
fi
29+

.openshift/cron/README.cron

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Run scripts or jobs on a periodic basis
2+
=======================================
3+
Any scripts or jobs added to the minutely, hourly, daily, weekly or monthly
4+
directories will be run on a scheduled basis (frequency is as indicated by the
5+
name of the directory) using run-parts.
6+
7+
run-parts ignores any files that are hidden or dotfiles (.*) or backup
8+
files (*~ or *,) or named *.{rpmsave,rpmorig,rpmnew,swp,cfsaved}
9+
10+
The presence of two specially named files jobs.deny and jobs.allow controls
11+
how run-parts executes your scripts/jobs.
12+
jobs.deny ===> Prevents specific scripts or jobs from being executed.
13+
jobs.allow ===> Only execute the named scripts or jobs (all other/non-named
14+
scripts that exist in this directory are ignored).
15+
16+
The principles of jobs.deny and jobs.allow are the same as those of cron.deny
17+
and cron.allow and are described in detail at:
18+
http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/ch-Automating_System_Tasks.html#s2-autotasks-cron-access
19+
20+
See: man crontab or above link for more details and see the the weekly/
21+
directory for an example.
22+

.openshift/cron/daily/.gitignore

Whitespace-only changes.

.openshift/cron/hourly/.gitignore

Whitespace-only changes.

.openshift/cron/minutely/.gitignore

Whitespace-only changes.

.openshift/cron/monthly/.gitignore

Whitespace-only changes.

.openshift/cron/weekly/README

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Run scripts or jobs on a weekly basis
2+
=====================================
3+
Any scripts or jobs added to this directory will be run on a scheduled basis
4+
(weekly) using run-parts.
5+
6+
run-parts ignores any files that are hidden or dotfiles (.*) or backup
7+
files (*~ or *,) or named *.{rpmsave,rpmorig,rpmnew,swp,cfsaved} and handles
8+
the files named jobs.deny and jobs.allow specially.
9+
10+
In this specific example, the chronograph script is the only script or job file
11+
executed on a weekly basis (due to white-listing it in jobs.allow). And the
12+
README and chrono.dat file are ignored either as a result of being black-listed
13+
in jobs.deny or because they are NOT white-listed in the jobs.allow file.
14+
15+
For more details, please see ../README.cron file.
16+

.openshift/cron/weekly/chrono.dat

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Time And Relative D...n In Execution (Open)Shift!

.openshift/cron/weekly/chronograph

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
echo "`date`: `cat $(dirname \"$0\")/chrono.dat`"

.openshift/cron/weekly/jobs.allow

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#
2+
# Script or job files listed in here (one entry per line) will be
3+
# executed on a weekly-basis.
4+
#
5+
# Example: The chronograph script will be executed weekly but the README
6+
# and chrono.dat files in this directory will be ignored.
7+
#
8+
# The README file is actually ignored due to the entry in the
9+
# jobs.deny which is checked before jobs.allow (this file).
10+
#
11+
chronograph
12+

.openshift/cron/weekly/jobs.deny

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#
2+
# Any script or job files listed in here (one entry per line) will NOT be
3+
# executed (read as ignored by run-parts).
4+
#
5+
6+
README
7+
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Utility functions for bash session - sourced in via the user's
2+
# bash profile ($OPENSHIFT_DATA_DIR/.bash_profile).
3+
4+
# Source utility functions.
5+
source $OPENSHIFT_REPO_DIR/.openshift/lib/utils
6+
7+
8+
# Internal function to setup path and remove the wrappers.
9+
function _setup_path_and_remove_wrappers() {
10+
# First invocation of npm or node, so setup the custom path and
11+
# unset the wrappers. Add the custom node binaries to the PATH.
12+
[ -z "$ZDEBUG" ] || echo "Setting path to include custom Node version"
13+
setup_path_for_custom_node_version
14+
unset node
15+
unset npm
16+
unset _setup_path_and_remove_wrappers
17+
18+
} # End of function _setup_path_and_remove_wrappers.
19+
20+
21+
# Temporary wrapper function to setup path before invoking npm.
22+
function npm() {
23+
# Setup path, remove wrappers and reinvoke npm.
24+
_setup_path_and_remove_wrappers
25+
npm "$@"
26+
27+
} # End of function npm.
28+
29+
30+
# Temporary wrapper function to setup path before invoking node.
31+
function node() {
32+
# Setup path, remove wrappers and reinvoke node.
33+
_setup_path_and_remove_wrappers
34+
node "$@"
35+
36+
} # End of function node.
37+
38+
39+
#
40+
# EOF

0 commit comments

Comments
 (0)