Skip to content

Instantly share code, notes, and snippets.

@Asner
Created March 6, 2019 15:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Asner/baa5a664585fa417b25c64127c90fc2d to your computer and use it in GitHub Desktop.
Save Asner/baa5a664585fa417b25c64127c90fc2d to your computer and use it in GitHub Desktop.
#!/bin/bash
target_branch="master"
working_tree="/home/deploy/icdt-production"
git_tree="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
while read oldrev newrev refname
do
branch=$(git rev-parse --symbolic --abbrev-ref $refname)
if [ -n "$branch" ] && [ "$target_branch" == "$branch" ]; then
NODE_ENV=production # Modo producción.
GIT_WORK_TREE=$working_tree git checkout $target_branch -f
NOW=$(date +"%Y%m%d-%H%M")
# Usar un tag: git tag release_$NOW $target_branch
cd $working_tree
echo "Installing packages"
npm install -s -q
# Cuando npm se comporte raro: npm -s -q --prefix $working_tree install $working_tree
echo "Migrating..."
NODE_ENV=production sequelize db:migrate
echo "Restarting server..."
pm2 restart ICDTProduction # Nombre de la app en pm2
cd $git_tree
echo " /==============================="
echo " | DEPLOYMENT COMPLETED"
echo " | Target branch: $target_branch"
echo " | Target folder: $working_tree"
echo " | Tag name : release_$NOW"
echo " \=============================="
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment