diff --git a/.openshift/action_hooks/build b/.openshift/action_hooks/build new file mode 100755 index 0000000..89cf6dd --- /dev/null +++ b/.openshift/action_hooks/build @@ -0,0 +1,32 @@ +#!/bin/bash +# This is a simple build script and will be executed on your CI system if +# available. Otherwise it will execute while your application is stopped +# before the deploy step. This script gets executed directly, so it +# could be python, php, ruby, etc. + + +# Source utility functions. +source "$OPENSHIFT_REPO_DIR/.openshift/lib/utils" + +# Setup path to include the custom Node[.js] version. +_SHOW_SETUP_PATH_MESSAGES="true" setup_path_for_custom_node_version + + +# we moved the package.json file out of the way in pre_build, +# so that the OpenShift git post-receive hook doesn't try and use the +# old npm version to install the dependencies. Move it back in. +tmp_package_json="$(get_node_tmp_dir)/package.json" +if [ -f "$tmp_package_json" ]; then + # Only overlay it if there is no current package.json file. + [ -f "${OPENSHIFT_REPO_DIR}/package.json" ] || \ + mv "$tmp_package_json" "${OPENSHIFT_REPO_DIR}/package.json" +fi + + +# Do npm install with the new npm binary. +if [ -f "${OPENSHIFT_REPO_DIR}"/package.json ]; then + echo " - Installing dependencies w/ new version of npm ... " + echo + (cd "${OPENSHIFT_REPO_DIR}"; export TMPDIR="/tmp"; npm install -d) +fi + diff --git a/.openshift/action_hooks/deploy b/.openshift/action_hooks/deploy new file mode 100755 index 0000000..ab6d097 --- /dev/null +++ b/.openshift/action_hooks/deploy @@ -0,0 +1,16 @@ +#!/bin/bash +# This deploy hook gets executed after dependencies are resolved and the +# build hook has been run but before the application has been started back +# up again. This script gets executed directly, so it could be python, php, +# ruby, etc. + + +# Source utility functions. +source "$OPENSHIFT_REPO_DIR/.openshift/lib/utils" + + +# On slave/serving gears, need to do the install as part of deploy +# so check if its needed. Just ensure the custom Node[.js] version is +# installed. +ensure_node_is_installed + diff --git a/.openshift/action_hooks/post_deploy b/.openshift/action_hooks/post_deploy new file mode 100755 index 0000000..eabd36a --- /dev/null +++ b/.openshift/action_hooks/post_deploy @@ -0,0 +1,4 @@ +#!/bin/bash +# This is a simple post deploy hook executed after your application +# is deployed and started. This script gets executed directly, so +# it could be python, php, ruby, etc. diff --git a/.openshift/action_hooks/pre_build b/.openshift/action_hooks/pre_build new file mode 100755 index 0000000..75c7d3b --- /dev/null +++ b/.openshift/action_hooks/pre_build @@ -0,0 +1,20 @@ +#!/bin/bash +# This is a simple script and will be executed on your CI system if +# available. Otherwise it will execute while your application is stopped +# before the build step. This script gets executed directly, so it +# could be python, php, ruby, etc. + + +# Source utility functions. +source "$OPENSHIFT_REPO_DIR/.openshift/lib/utils" + +# Ensure custom node version if not installed. +echo "" +ensure_node_is_installed + + +# We need to move the package.json file out of the way in pre_build, so +# that the OpenShift git post-receive hook doesn't try and use the old +# npm version to install the dependencies. +mv "${OPENSHIFT_REPO_DIR}/package.json" "$(get_node_tmp_dir)" + diff --git a/.openshift/action_hooks/pre_start_nodejs b/.openshift/action_hooks/pre_start_nodejs new file mode 100755 index 0000000..694faef --- /dev/null +++ b/.openshift/action_hooks/pre_start_nodejs @@ -0,0 +1,24 @@ +#!/bin/bash + +# The pre_start_cartridge and pre_stop_cartridge hooks are *SOURCED* +# immediately before (re)starting or stopping the specified cartridge. +# They are able to make any desired environment variable changes as +# well as other adjustments to the application environment. + +# The post_start_cartridge and post_stop_cartridge hooks are executed +# immediately after (re)starting or stopping the specified cartridge. + +# Exercise caution when adding commands to these hooks. They can +# prevent your application from stopping cleanly or starting at all. +# Application start and stop is subject to different timeouts +# throughout the system. + + +# Source utility functions. +source "$OPENSHIFT_REPO_DIR/.openshift/lib/utils" + +# Setup path to include the custom Node[.js] version. +ver=$(get_node_version) +echo "" +echo " - pre_start_nodejs: Adding Node.js version $ver binaries to path" +_SHOW_SETUP_PATH_MESSAGES="true" setup_path_for_custom_node_version diff --git a/.openshift/cron/README.cron b/.openshift/cron/README.cron new file mode 100644 index 0000000..aad9138 --- /dev/null +++ b/.openshift/cron/README.cron @@ -0,0 +1,22 @@ +Run scripts or jobs on a periodic basis +======================================= +Any scripts or jobs added to the minutely, hourly, daily, weekly or monthly +directories will be run on a scheduled basis (frequency is as indicated by the +name of the directory) using run-parts. + +run-parts ignores any files that are hidden or dotfiles (.*) or backup +files (*~ or *,) or named *.{rpmsave,rpmorig,rpmnew,swp,cfsaved} + +The presence of two specially named files jobs.deny and jobs.allow controls +how run-parts executes your scripts/jobs. + jobs.deny ===> Prevents specific scripts or jobs from being executed. + jobs.allow ===> Only execute the named scripts or jobs (all other/non-named + scripts that exist in this directory are ignored). + +The principles of jobs.deny and jobs.allow are the same as those of cron.deny +and cron.allow and are described in detail at: + http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/ch-Automating_System_Tasks.html#s2-autotasks-cron-access + +See: man crontab or above link for more details and see the the weekly/ + directory for an example. + diff --git a/.openshift/cron/daily/.gitignore b/.openshift/cron/daily/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/.openshift/cron/hourly/.gitignore b/.openshift/cron/hourly/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/.openshift/cron/minutely/.gitignore b/.openshift/cron/minutely/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/.openshift/cron/monthly/.gitignore b/.openshift/cron/monthly/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/.openshift/cron/weekly/README b/.openshift/cron/weekly/README new file mode 100644 index 0000000..7c3e659 --- /dev/null +++ b/.openshift/cron/weekly/README @@ -0,0 +1,16 @@ +Run scripts or jobs on a weekly basis +===================================== +Any scripts or jobs added to this directory will be run on a scheduled basis +(weekly) using run-parts. + +run-parts ignores any files that are hidden or dotfiles (.*) or backup +files (*~ or *,) or named *.{rpmsave,rpmorig,rpmnew,swp,cfsaved} and handles +the files named jobs.deny and jobs.allow specially. + +In this specific example, the chronograph script is the only script or job file +executed on a weekly basis (due to white-listing it in jobs.allow). And the +README and chrono.dat file are ignored either as a result of being black-listed +in jobs.deny or because they are NOT white-listed in the jobs.allow file. + +For more details, please see ../README.cron file. + diff --git a/.openshift/cron/weekly/chrono.dat b/.openshift/cron/weekly/chrono.dat new file mode 100644 index 0000000..fc4abb8 --- /dev/null +++ b/.openshift/cron/weekly/chrono.dat @@ -0,0 +1 @@ +Time And Relative D...n In Execution (Open)Shift! diff --git a/.openshift/cron/weekly/chronograph b/.openshift/cron/weekly/chronograph new file mode 100755 index 0000000..61de949 --- /dev/null +++ b/.openshift/cron/weekly/chronograph @@ -0,0 +1,3 @@ +#!/bin/bash + +echo "`date`: `cat $(dirname \"$0\")/chrono.dat`" diff --git a/.openshift/cron/weekly/jobs.allow b/.openshift/cron/weekly/jobs.allow new file mode 100644 index 0000000..8d32abc --- /dev/null +++ b/.openshift/cron/weekly/jobs.allow @@ -0,0 +1,12 @@ +# +# Script or job files listed in here (one entry per line) will be +# executed on a weekly-basis. +# +# Example: The chronograph script will be executed weekly but the README +# and chrono.dat files in this directory will be ignored. +# +# The README file is actually ignored due to the entry in the +# jobs.deny which is checked before jobs.allow (this file). +# +chronograph + diff --git a/.openshift/cron/weekly/jobs.deny b/.openshift/cron/weekly/jobs.deny new file mode 100644 index 0000000..73c9450 --- /dev/null +++ b/.openshift/cron/weekly/jobs.deny @@ -0,0 +1,7 @@ +# +# Any script or job files listed in here (one entry per line) will NOT be +# executed (read as ignored by run-parts). +# + +README + diff --git a/.openshift/lib/setup_custom_nodejs_env b/.openshift/lib/setup_custom_nodejs_env new file mode 100644 index 0000000..b55b774 --- /dev/null +++ b/.openshift/lib/setup_custom_nodejs_env @@ -0,0 +1,40 @@ +# Utility functions for bash session - sourced in via the user's +# bash profile ($OPENSHIFT_DATA_DIR/.bash_profile). + +# Source utility functions. +source $OPENSHIFT_REPO_DIR/.openshift/lib/utils + + +# Internal function to setup path and remove the wrappers. +function _setup_path_and_remove_wrappers() { + # First invocation of npm or node, so setup the custom path and + # unset the wrappers. Add the custom node binaries to the PATH. + [ -z "$ZDEBUG" ] || echo "Setting path to include custom Node version" + setup_path_for_custom_node_version + unset node + unset npm + unset _setup_path_and_remove_wrappers + +} # End of function _setup_path_and_remove_wrappers. + + +# Temporary wrapper function to setup path before invoking npm. +function npm() { + # Setup path, remove wrappers and reinvoke npm. + _setup_path_and_remove_wrappers + npm "$@" + +} # End of function npm. + + +# Temporary wrapper function to setup path before invoking node. +function node() { + # Setup path, remove wrappers and reinvoke node. + _setup_path_and_remove_wrappers + node "$@" + +} # End of function node. + + +# +# EOF diff --git a/.openshift/lib/utils b/.openshift/lib/utils new file mode 100755 index 0000000..139927d --- /dev/null +++ b/.openshift/lib/utils @@ -0,0 +1,164 @@ +#!/bin/bash +# +# Utility functions. +# + + +# Returns the configured Node version +function get_node_version() { + # read the app's package.json file + package_json="${OPENSHIFT_REPO_DIR}/package.json" + + # attempt to detect the desired node.js version + engine=$(grep "\"node\"" "$package_json" | tail -n 1 | sed -e 's/^.*" *[~=<>]*[=<>]* *v*\([0-9][^" ]*\) *[^"]*".*$/\1/p;d') + + # assume that a deprecated marker value is a reasonable default + marker="${OPENSHIFT_REPO_DIR}.openshift/markers/NODEJS_VERSION" + marker_ver=$(egrep -v "^\s*#.*" "$marker" 2>/dev/null | egrep -v "^\s*$" | tail -1) + + # use the OpenShift cart default of 0.6.20 as a final option: + if [ -z $engine ]; then + echo ${marker_ver-"0.6.20"} + else + echo ${engine} + fi + +} # End of function get_node_version. + + +# Returns the directory where Node is to be installed/is installed. +function get_node_install_dir() { + echo "$OPENSHIFT_DATA_DIR" + +} # End of function get_node_install_dir. + + +# Returns the path to the npm binary. +function get_npm_bin_path() { + ver=${1:-"$(get_node_version)"} + echo "$(get_node_install_dir)/node-v$ver-linux-x64/bin" + +} # End of function get_npm_bin_path. + + +# Returns the path to the node binary. +function get_node_bin_path() { + echo "$(get_npm_bin_path $@)" + +} # End of function get_node_bin_path. + + +# Returns the temporary directory we use for processing. +function get_node_tmp_dir() { + ztmpdir="$OPENSHIFT_DATA_DIR/.nodejs.tmp" + + # Ensure temp directory is created. + [ -d "$ztmpdir" ] || mkdir -p "$ztmpdir" + + echo "$ztmpdir" + +} # End of function get_node_tmp_dir. + + +# +# Download and install the specified Node.js version. +# +function _install_nodejs() { + ver=${1:-"$(get_node_version)"} + + # Sample download links: + # http://nodejs.org/dist/v0.8.9/node-v0.8.9-linux-x64.tar.gz + # http://nodejs.org/dist/v0.9.1/node-v0.9.1-linux-x64.tar.gz + zfile="node-v${ver}-linux-x64.tar.gz" + zlink="http://nodejs.org/dist/v${ver}/${zfile}" + + instdir="$(get_node_install_dir)" + + # Download and extract the gzipped tarball. + dldir="$OPENSHIFT_DATA_DIR/downloads" + mkdir -p "$dldir" + + echo " - Downloading and extracting $zlink ... " + + if ! curl -L -o "$dldir/$zfile" "$zlink"; then + echo " - ERROR -- download failed for $zlink" + echo " - download uri = $dldir/$zfile" + return 1 + fi + + (cd "$instdir"; tar -zxf "$dldir/$zfile") + echo " - Done installing Node.js version $ver" + +} # End of function _install_nodejs. + + + +# Ensure the shell env setup bits are added to user's .bash_profile. +function _ensure_bash_profile_setup() { + dot_bash_profile=$OPENSHIFT_DATA_DIR/.bash_profile + pattern='\s*source(.*)\.openshift/lib/setup_custom_nodejs_env\s*(.*)\s*' + if ! egrep "$pattern" $dot_bash_profile > /dev/null 2>&1 ; then + + cat >> $dot_bash_profile <