Skip to content

Instantly share code, notes, and snippets.

@IskenHuang
Created February 10, 2014 06:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IskenHuang/8911301 to your computer and use it in GitHub Desktop.
Save IskenHuang/8911301 to your computer and use it in GitHub Desktop.
git hooks deploy
#!/bin/sh
echo "Deploy beign"
# 設定 nodejs 環境(如果是用 nvm 管理 nodejs 才需要)
. "$HOME/.nvm/nvm.sh"
# 設定 project 路徑
export PROJECT_DIR=$HOME/PROJECT
# 轉移到 project folder
cd $PROJECT_DIR
unset GIT_DIR
# 更新最新版的 code (此部份可以依照專案來決定,在這邊只是因為方便所以直接更新最新版)
git pull origin master
# 更新 npm package
npm install
# 重起 nodejs process (這邊使用 forever 管理 node process,依照專案使用方式來調整)
"$PROJECT_DIR/node_modules/forever/bin/forever" restartall
echo ""
echo "Deploy success"
echo ""
#!/bin/sh
# go to home
cd $HOME
# 先隨便叫他 deploy.git 並放在 user 個人的資料夾下
git init --bare "$HOME/deploy.git"
# 把 .sample 拿掉,這樣 hooks 才會執行到
mv "$HOME/deploy.git/hooks/post-receive.sample" "$HOME/deploy.git/hooks/post-receive"
# 修改 post-receive 權限
chmod +x "$HOME/deploy.git/hooks/post-receive"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment