├── .gitignore ├── .jshintrc ├── .openshift ├── action_hooks │ ├── build │ ├── deploy │ ├── post_deploy │ ├── post_start_nodejs │ ├── post_start_nodejs-0.6 │ ├── post_stop_nodejs │ ├── post_stop_nodejs-0.6 │ ├── pre_build │ ├── pre_start_nodejs │ ├── pre_start_nodejs-0.6 │ ├── pre_stop_nodejs │ └── pre_stop_nodejs-0.6 ├── cron │ ├── README.cron │ ├── daily │ │ └── .gitignore │ ├── hourly │ │ └── .gitignore │ ├── minutely │ │ └── .gitignore │ ├── monthly │ │ └── .gitignore │ └── weekly │ │ ├── README │ │ ├── chrono.dat │ │ ├── chronograph │ │ ├── jobs.allow │ │ └── jobs.deny ├── lib │ ├── setup_custom_nodejs_env │ └── utils └── markers │ ├── NODEJS_VERSION │ └── README ├── LICENSE ├── README ├── README.md ├── app.js ├── node_modules └── read.me ├── npm_global_module_list ├── package.json ├── public └── index.html ├── server.js └── views ├── error.jade └── layout.jade /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules/* 2 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "node": true, 3 | "proto": true, 4 | "strict": true, 5 | } 6 | -------------------------------------------------------------------------------- /.openshift/action_hooks/build: -------------------------------------------------------------------------------- 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 | 33 | -------------------------------------------------------------------------------- /.openshift/action_hooks/deploy: -------------------------------------------------------------------------------- 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 | 17 | -------------------------------------------------------------------------------- /.openshift/action_hooks/post_deploy: -------------------------------------------------------------------------------- 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. 5 | -------------------------------------------------------------------------------- /.openshift/action_hooks/post_start_nodejs: -------------------------------------------------------------------------------- 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 | 42 | -------------------------------------------------------------------------------- /.openshift/action_hooks/post_start_nodejs-0.6: -------------------------------------------------------------------------------- 1 | post_start_nodejs -------------------------------------------------------------------------------- /.openshift/action_hooks/post_stop_nodejs: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /.openshift/action_hooks/post_stop_nodejs-0.6: -------------------------------------------------------------------------------- 1 | post_stop_nodejs -------------------------------------------------------------------------------- /.openshift/action_hooks/pre_build: -------------------------------------------------------------------------------- 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 | 22 | -------------------------------------------------------------------------------- /.openshift/action_hooks/pre_start_nodejs: -------------------------------------------------------------------------------- 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 | 26 | -------------------------------------------------------------------------------- /.openshift/action_hooks/pre_start_nodejs-0.6: -------------------------------------------------------------------------------- 1 | pre_start_nodejs -------------------------------------------------------------------------------- /.openshift/action_hooks/pre_stop_nodejs: -------------------------------------------------------------------------------- 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 | 30 | -------------------------------------------------------------------------------- /.openshift/action_hooks/pre_stop_nodejs-0.6: -------------------------------------------------------------------------------- 1 | pre_stop_nodejs -------------------------------------------------------------------------------- /.openshift/cron/README.cron: -------------------------------------------------------------------------------- 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 | 23 | PLEASE NOTE: The Cron cartridge must be installed in order to run the configured jobs. 24 | -------------------------------------------------------------------------------- /.openshift/cron/daily/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/h4t0n/nodejs-4-lts-openshift/ea23c498d54c9389022bccac5187985f69ca1bc5/.openshift/cron/daily/.gitignore -------------------------------------------------------------------------------- /.openshift/cron/hourly/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/h4t0n/nodejs-4-lts-openshift/ea23c498d54c9389022bccac5187985f69ca1bc5/.openshift/cron/hourly/.gitignore -------------------------------------------------------------------------------- /.openshift/cron/minutely/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/h4t0n/nodejs-4-lts-openshift/ea23c498d54c9389022bccac5187985f69ca1bc5/.openshift/cron/minutely/.gitignore -------------------------------------------------------------------------------- /.openshift/cron/monthly/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/h4t0n/nodejs-4-lts-openshift/ea23c498d54c9389022bccac5187985f69ca1bc5/.openshift/cron/monthly/.gitignore -------------------------------------------------------------------------------- /.openshift/cron/weekly/README: -------------------------------------------------------------------------------- 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 | 17 | -------------------------------------------------------------------------------- /.openshift/cron/weekly/chrono.dat: -------------------------------------------------------------------------------- 1 | Time And Relative D...n In Execution (Open)Shift! 2 | -------------------------------------------------------------------------------- /.openshift/cron/weekly/chronograph: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "`date`: `cat $(dirname \"$0\")/chrono.dat`" 4 | -------------------------------------------------------------------------------- /.openshift/cron/weekly/jobs.allow: -------------------------------------------------------------------------------- 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 | 13 | -------------------------------------------------------------------------------- /.openshift/cron/weekly/jobs.deny: -------------------------------------------------------------------------------- 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 | 8 | -------------------------------------------------------------------------------- /.openshift/lib/setup_custom_nodejs_env: -------------------------------------------------------------------------------- 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 41 | -------------------------------------------------------------------------------- /.openshift/lib/utils: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Utility functions. 4 | # 5 | 6 | 7 | # Returns the configured Node version - defaults to 0.8.24. 8 | function get_node_version() { 9 | marker="$OPENSHIFT_REPO_DIR/.openshift/markers/NODEJS_VERSION" 10 | nodejs_ver=$(egrep -v "^\s*#.*" "$marker" | egrep -v "^\s*$" | tail -1) 11 | echo "${nodejs_ver:-"0.8.24"}" 12 | 13 | } # End of function get_node_version. 14 | 15 | 16 | # Returns the directory where Node is to be installed/is installed. 17 | function get_node_install_dir() { 18 | echo "$OPENSHIFT_DATA_DIR" 19 | 20 | } # End of function get_node_install_dir. 21 | 22 | 23 | # Returns the path to the npm binary. 24 | function get_npm_bin_path() { 25 | ver=${1:-"$(get_node_version)"} 26 | echo "$(get_node_install_dir)/node-v$ver-linux-x64/bin" 27 | 28 | } # End of function get_npm_bin_path. 29 | 30 | 31 | # Returns the path to the node binary. 32 | function get_node_bin_path() { 33 | echo "$(get_npm_bin_path $@)" 34 | 35 | } # End of function get_node_bin_path. 36 | 37 | 38 | # Returns the temporary directory we use for processing. 39 | function get_node_tmp_dir() { 40 | ztmpdir="$OPENSHIFT_DATA_DIR/.nodejs.tmp" 41 | 42 | # Ensure temp directory is created. 43 | [ -d "$ztmpdir" ] || mkdir -p "$ztmpdir" 44 | 45 | echo "$ztmpdir" 46 | 47 | } # End of function get_node_tmp_dir. 48 | 49 | 50 | # 51 | # Download and install the specified Node.js version. 52 | # 53 | function _install_nodejs() { 54 | ver=${1:-"$(get_node_version)"} 55 | 56 | # Sample download links: 57 | # http://nodejs.org/dist/v0.8.24/node-v0.8.24-linux-x64.tar.gz 58 | # http://nodejs.org/dist/v0.10.10/node-v0.10.10-linux-x64.tar.gz 59 | zfile="node-v${ver}-linux-x64.tar.gz" 60 | zlink="http://nodejs.org/dist/v${ver}/${zfile}" 61 | 62 | instdir="$(get_node_install_dir)" 63 | 64 | # Download and extract the gzipped tarball. 65 | dldir="$OPENSHIFT_DATA_DIR/downloads" 66 | mkdir -p "$dldir" 67 | 68 | echo " - Downloading and extracting $zlink ... " 69 | 70 | if ! curl -L -o "$dldir/$zfile" "$zlink"; then 71 | echo " - ERROR -- download failed for $zlink" 72 | echo " - download uri = $dldir/$zfile" 73 | return 1 74 | fi 75 | 76 | (cd "$instdir"; tar -zxf "$dldir/$zfile") 77 | echo " - Done installing Node.js version $ver" 78 | 79 | } # End of function _install_nodejs. 80 | 81 | 82 | # Ensure npm and node symlinks exist in ~/.node_modules/.bin/ directory. 83 | function _ensure_symlinks_in_node_modules_bin_dir() { 84 | zdir="$HOME/.node_modules/.bin/" 85 | if [ -d "$zdir" ]; then 86 | ln -sf "$(get_npm_bin_path)/npm" "$zdir" 87 | ln -sf "$(get_node_bin_path)/node" "$zdir" 88 | fi 89 | 90 | } # End of function _ensure_symlinks_in_node_modules_bin_dir. 91 | 92 | 93 | # Ensure context - this is a bit too hacky. 94 | function _ensure_context_exists() { 95 | zenv="$OPENSHIFT_HOMEDIR/nodejs/configuration/node.env" 96 | if ! egrep '^\s*function\s+nodejs_context' "$zenv" > /dev/null 2>&1; then 97 | echo -e "function nodejs_context() { bash -c \"\$@\"; }\n" >> "$zenv" || : 98 | fi 99 | 100 | } # End of function _ensure_context_exists. 101 | 102 | 103 | # Ensure the shell env setup bits are added to user's .bash_profile. 104 | function _ensure_bash_profile_setup() { 105 | dot_bash_profile=$OPENSHIFT_DATA_DIR/.bash_profile 106 | pattern='\s*source(.*)\.openshift/lib/setup_custom_nodejs_env\s*(.*)\s*' 107 | if ! egrep "$pattern" $dot_bash_profile > /dev/null 2>&1 ; then 108 | 109 | cat >> $dot_bash_profile < 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | Feel free to change or remove this file, it is informational only. 2 | 3 | Repo layout 4 | =========== 5 | node_modules/ - Any Node modules packaged with the app 6 | package.json - npm package descriptor. 7 | .openshift/ - Location for openshift specific files 8 | .openshift/action_hooks/pre_build - Script that gets run every git push before 9 | the build 10 | .openshift/action_hooks/build - Script that gets run every git push as 11 | part of the build process (on the CI 12 | system if available) 13 | .openshift/action_hooks/deploy - Script that gets run every git push after 14 | build but before the app is restarted 15 | .openshift/action_hooks/post_deploy - Script that gets run every git push after 16 | the app is restarted 17 | 18 | Notes about layout 19 | ================== 20 | Please leave the node_modules and .openshift directories but feel free to 21 | create additional directories if needed. 22 | 23 | Note: Every time you push, everything in your remote repo dir gets recreated 24 | please store long term items (like an sqlite database) in the OpenShift 25 | data directory, which will persist between pushes of your repo. 26 | The OpenShift data directory is accessible relative to the remote repo 27 | directory (../data) or via an environment variable OPENSHIFT_DATA_DIR. 28 | 29 | 30 | Environment Variables 31 | ===================== 32 | OpenShift provides several environment variables to reference for ease 33 | of use. The following list are some common variables but far from exhaustive: 34 | process.env.OPENSHIFT_GEAR_NAME - Application name 35 | process.env.OPENSHIFT_GEAR_DIR - Application dir 36 | process.env.OPENSHIFT_DATA_DIR - For persistent storage (between pushes) 37 | process.env.OPENSHIFT_TMP_DIR - Temp storage (unmodified files deleted after 10 days) 38 | 39 | When embedding a database using 'rhc app cartridge add', you can reference environment 40 | variables for username, host and password: 41 | process.env.OPENSHIFT_DB_HOST - DB Host 42 | process.env.OPENSHIFT_DB_PORT - DB Port 43 | process.env.OPENSHIFT_DB_USERNAME - DB Username 44 | process.env.OPENSHIFT_DB_PASSWORD - DB Password 45 | 46 | When embedding a NoSQL database using 'rhc app cartridge add', you can reference environment 47 | variables for username, host and password: 48 | process.env.OPENSHIFT_NOSQL_DB_HOST - NoSQL DB Host 49 | process.env.OPENSHIFT_NOSQL_DB_PORT - NoSQL DB Port 50 | process.env.OPENSHIFT_NOSQL_DB_USERNAME - NoSQL DB Username 51 | process.env.OPENSHIFT_NOSQL_DB_PASSWORD - NoSQL DB Password 52 | 53 | To get a full list of environment variables, simply add a line in your 54 | .openshift/action_hooks/build script that says "export" and push. 55 | 56 | 57 | 58 | Additional information 59 | ====================== 60 | Link to additional information will be here, when we have it :) 61 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Running the latest (4.2.x) LTS Node[.js] version on Red Hat's OpenShift PaaS 2 | This git repository is a sample Node application along with the "orchestration" bits to help you run the latest (or a custom) version of Node on Red Hat's OpenShift PaaS. 3 | 4 | (Current) NodeJS Version: 4.2.6 5 | 6 | ## Steps to get the latest Node.js version running on OpenShift 7 | Create an account at [http://openshift.redhat.com/](http://openshift.redhat.com/) 8 | 9 | Create a namespace, if you haven't already do so 10 | 11 | ``` 12 | rhc domain create 13 | ``` 14 | 15 | Create a nodejs application (you can name it anything via -a, -t here is used to start with the default supported OpenShift nodejs application) 16 | 17 | ``` 18 | rhc app create -a node4 -t nodejs-0.10 19 | ``` 20 | 21 | Add this `github nodejs-4-lts-openshift` repository to the OpenShift git project remote 22 | 23 | ``` 24 | cd node4 25 | git remote add github -m master https://github.com/h4t0n/nodejs-4-lts-openshift.git 26 | ``` 27 | 28 | Get updates from the remote with merge conflicts properly resolved (NB: don't run `git pull github` alone) 29 | 30 | ``` 31 | git pull -s recursive -X theirs github master 32 | ``` 33 | 34 | Push the updates coming from `github nodejs-4-lts-openshift` into the OpenShift git project. 35 | 36 | ``` 37 | git push 38 | ``` 39 | 40 | That's it, you can now checkout your application at: 41 | 42 | [http://node4-$yournamespace.rhcloud.com](http://node4-$yournamespace.rhcloud.com) 43 | ( See env @ [http://node-$yournamespace.rhcloud.com/env](http://node-$yournamespace.rhcloud.com/env) ) 44 | 45 | If you want another version of Node (example v0.12.x), you can change to that by just writing it to the end of the NODEJS_VERSION file and committing that change. 46 | 47 | ``` 48 | echo 0.12.7 >> .openshift/markers/NODEJS_VERSION 49 | # 50 | # Or alternatively, edit the .openshift/markers/NODEJS_VERSION file 51 | # in your favorite editor aka vi ;^) 52 | # 53 | # 54 | git commit . -m 'use Node version 0.12.7' 55 | ``` 56 | 57 | Then push the repo to OpenShift with `git push` 58 | 59 | ## Additional information 60 | This repository is a fork of [Ramr nodejs custom version](https://github.com/ramr/nodejs-custom-version-openshift). See it for documentation about Openshift hooks or if you want additional information. 61 | -------------------------------------------------------------------------------- /app.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var express = require('express'); 4 | var path = require('path'); 5 | var favicon = require('serve-favicon'); 6 | // var logger = require('morgan'); 7 | // var cookieParser = require('cookie-parser'); 8 | var bodyParser = require('body-parser'); 9 | 10 | // var routes = require('./routes/index'); 11 | 12 | var app = express(); 13 | 14 | // view engine setup 15 | app.set('views', path.join(__dirname, 'views')); 16 | app.set('view engine', 'jade'); 17 | 18 | // uncomment after placing your favicon in /public 19 | //app.use(favicon(path.join(__dirname, 'public', 'favicon.ico'))); 20 | // app.use(logger('dev')); 21 | app.use(bodyParser.json()); 22 | app.use(bodyParser.urlencoded({ extended: false })); 23 | // app.use(cookieParser()); 24 | app.use(express.static(path.join(__dirname, 'public'))); 25 | 26 | // app.use('/', routes); 27 | 28 | app.get('/env', function (req, res) { 29 | var content = 'Version: ' + process.version + '\n
\n' + 30 | 'Env: {
\n
';
31 |   //  Add env entries.
32 |   for (var k in process.env) {
33 |     content += '   ' + k + ': ' + process.env[k] + '\n';
34 |   }
35 |   content += '}\n

\n'; 36 | res.send('\n' + 37 | ' Node.js Process Env\n' + 38 | ' \n
\n' + content + '\n'); 39 | }); 40 | 41 | // catch 404 and forward to error handler 42 | app.use(function(req, res, next) { 43 | var err = new Error('Not Found'); 44 | err.status = 404; 45 | next(err); 46 | }); 47 | 48 | // error handlers 49 | 50 | // development error handler 51 | // will print stacktrace 52 | if (app.get('env') === 'development') { 53 | app.use(function(err, req, res, next) { 54 | res.status(err.status || 500); 55 | res.render('error', { 56 | message: err.message, 57 | error: err 58 | }); 59 | }); 60 | } 61 | 62 | // production error handler 63 | // no stacktraces leaked to user 64 | app.use(function(err, req, res, next) { 65 | res.status(err.status || 500); 66 | res.render('error', { 67 | message: err.message, 68 | error: {} 69 | }); 70 | }); 71 | 72 | 73 | module.exports = app; 74 | -------------------------------------------------------------------------------- /node_modules/read.me: -------------------------------------------------------------------------------- 1 | 2 | This directory allows you to package any Node modules (that your application 3 | depends on) along with your application. 4 | 5 | If you just wish to install module(s) from the npm registry (npmjs.org), you 6 | can specify the module name(s) and optionally version in your application's 7 | dependency list file (../deplist.txt). 8 | 9 | -------------------------------------------------------------------------------- /npm_global_module_list: -------------------------------------------------------------------------------- 1 | # 2 | # This file contains a list of globally installed and available npm modules. 3 | # 4 | 5 | # DB drivers. 6 | mongodb 7 | mysql 8 | pg 9 | 10 | # Other modules (including frameworks, middleware etc). 11 | async 12 | connect 13 | express 14 | formidable 15 | generic-pool 16 | hashish 17 | mime 18 | mkdirp 19 | node-static 20 | qs 21 | traverse 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nodejs-4-stable-Sample", 3 | "version": "1.0.0", 4 | "description": "OpenShift Node.js 4 Stable Application", 5 | "keywords": [ 6 | "OpenShift", 7 | "Node.js", 8 | "application", 9 | "openshift", 10 | "express" 11 | ], 12 | "author": { 13 | "name": "Andrea Tarquini", 14 | "email": "tarquiniandreagm@gmail.com", 15 | "url": "https://blog.h4t0n.com" 16 | }, 17 | "homepage": "http://blog.h4t0n.com", 18 | "repository": { 19 | "type": "git", 20 | "url": "https://github.com/h4t0n/nodejs-4-lts-openshift.git" 21 | }, 22 | "engines": { 23 | "node": ">= 4.2.1", 24 | "npm": ">= 1.0.0" 25 | }, 26 | "dependencies": { 27 | "body-parser": "^1.14.1", 28 | "express": "^4.13.3", 29 | "jade": "^1.11.0", 30 | "serve-favicon": "^2.3.0" 31 | }, 32 | "devDependencies": { 33 | "debug": "^2.2.0" 34 | }, 35 | "bundleDependencies": [], 36 | "private": true, 37 | "main": "server.js" 38 | } 39 | -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Welcome NodeJS application from h4t0n 7 | 9 | 10 | 11 |

12 | Welcome to NodeJS 4 Stable Application on OpenShift 13 |

14 |
15 |

16 | (MIT)
17 | Copyright (c) 2015 ramr
18 | Copyright (c) 2015 Andrea Tarquini @h4t0n 19 |

20 |
21 |
22 |

23 | This application use the Express web application framework to show this index and other some useful information. 24 |

25 |
26 |       For example click here to view your Node.js process version and env.
27 |     
28 |
29 |

30 | You can use this base Express application to write your own server, routes, and generally server your content 31 | but remember to remove the /env route for security reason (this avoid to show your environment variables). 32 |

33 |

34 | In order to commit to your new project, go to your projects git repo (created with the rhc app create command). Make your changes, then run: 35 |

36 |
37 |     git commit -a -m 'Some commit message'
38 |     git push
39 |   
40 |

41 | Then reload this page too see changes. 42 |

43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /server.js: -------------------------------------------------------------------------------- 1 | #!/bin/env node 2 | 3 | /** 4 | * Module dependencies. 5 | */ 6 | var app = require('./app'); 7 | var debug = require('debug')('Server'); 8 | var http = require('http'); 9 | 10 | /** 11 | * Get port from environment and store in Express. 12 | */ 13 | 14 | 15 | var ipaddress = process.env.OPENSHIFT_NODEJS_IP || 16 | process.env.OPENSHIFT_INTERNAL_IP; 17 | 18 | var port = process.env.OPENSHIFT_NODEJS_PORT || 19 | process.env.OPENSHIFT_INTERNAL_PORT || 8080; 20 | 21 | if (ipaddress === "undefined") { 22 | // Log errors on OpenShift but continue w/ 127.0.0.1 - this 23 | // allows us to run/test the app locally. 24 | console.warn('No OPENSHIFT_*_IP var, using 127.0.0.1'); 25 | ipaddress = "127.0.0.1"; 26 | } 27 | 28 | app.set('port', port); 29 | 30 | /** 31 | * Create HTTP server. 32 | */ 33 | 34 | var server = http.createServer(app); 35 | 36 | /** 37 | * Listen on provided port, on all network interfaces. 38 | */ 39 | 40 | server.listen(port,ipaddress); 41 | 42 | server.on('error', onError); 43 | server.on('listening', onListening); 44 | 45 | 46 | 47 | /** 48 | * Event listener for HTTP server "error" event. 49 | */ 50 | 51 | function onError(error) { 52 | if (error.syscall !== 'listen') { 53 | throw error; 54 | } 55 | 56 | var bind = typeof port === 'string' ? 'Pipe ' + port : 'Port ' + port; 57 | 58 | // handle specific listen errors with friendly messages 59 | switch (error.code) { 60 | case 'EACCES': 61 | console.error(bind + ' requires elevated privileges'); 62 | process.exit(1); 63 | break; 64 | case 'EADDRINUSE': 65 | console.error(bind + ' is already in use'); 66 | process.exit(1); 67 | break; 68 | default: 69 | throw error; 70 | } 71 | } 72 | 73 | /** 74 | * Event listener for HTTP server "listening" event. 75 | */ 76 | 77 | function onListening() { 78 | var addr = server.address(); 79 | var bind = typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port; 80 | debug('Listening on ' + bind); 81 | } 82 | -------------------------------------------------------------------------------- /views/error.jade: -------------------------------------------------------------------------------- 1 | extends layout 2 | 3 | block content 4 | h1= message 5 | h2= error.status 6 | pre #{error.stack} 7 | -------------------------------------------------------------------------------- /views/layout.jade: -------------------------------------------------------------------------------- 1 | doctype html 2 | html 3 | head 4 | title= "Nodejs 4 Stable" 5 | body 6 | block content 7 | --------------------------------------------------------------------------------