Skip to content

Instantly share code, notes, and snippets.

@tlrobinson
Last active December 7, 2022 08:15
Show Gist options
  • Save tlrobinson/8035884 to your computer and use it in GitHub Desktop.
Save tlrobinson/8035884 to your computer and use it in GitHub Desktop.
Super simple git post-receive hook for Node.js + nvm + npm + node-foreman + init (Ubuntu) deployment
#!/usr/bin/env bash
set -u
set -e
export GIT_WORK_TREE="/var/www/example.com"
export NODE_VERSION="0.10"
echo "--> Checking out..."
git checkout -f
echo "--> Selecting Node version $NODE_VERSION"
. $HOME/.nvm/nvm.sh
nvm use $NODE_VERSION
echo "--> Installing libraries..."
cd "$GIT_WORK_TREE"
npm install
echo "--> Exporting Foreman files..."
node_modules/.bin/nf export -o /etc/init
echo "--> Restarting..."
stop foreman
start foreman
@jmcbee
Copy link

jmcbee commented Nov 24, 2014

@narqo ermeged, why not try using a bare and a non-bare repo and tell us why we use a bare repo.

@jasonnathan
Copy link

@fbm-static rofl!

@ralyodio
Copy link

I get nvm: command not found in my post-receive hook

it works fine from ssh login

@Ridder90
Copy link

Thanks for this! Unfortunatly i get nvm and npm not found.

@williamjingo
Copy link

Just incase anyone is still getting the npm not found.
after the exit immediately if a command exits with a non-zero status. set -e
add

export NVM_DIR="$HOME/.nvm"
. "$NVM_DIR/nvm.sh"

then you can go a head and set your variables.
export..
I hope this helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment