Skip to content

Instantly share code, notes, and snippets.

@thiagobraga
Last active November 6, 2018 17:02
Show Gist options
  • Save thiagobraga/8cfd96eff2cbcd2725205ef5533f5126 to your computer and use it in GitHub Desktop.
Save thiagobraga/8cfd96eff2cbcd2725205ef5533f5126 to your computer and use it in GitHub Desktop.
Deploy com post-receive

Deploy com post-receive

No artigo a seguir, vou adotar a seguinte estrutura de pastas:

  • TODO: Utilizar tree para gerar estrutura de pastas.

Criando repositório bare

  • Executar o script git-init-bare.sh
  • Copiar o conteúdo de post-receive.sh para /var/www/html/project/.git/hooks/post-receive

Testando deploy

#/bin/bash
ROOT='/var/www/html/'
PROJECT='coletivoboitata.com.br'
mkdir -p ${ROOT}/${PROJECT}
cd ${ROOT}/${PROJECT}
mkdir .git && cd .git
git init --bare
cd hooks
/bin/rm -rf ./*
touch post-receive
chmod +x post-receive
#/bin/bash
read -r OLDREV NEWREV REFNAME
BRANCH=$(git rev-parse --symbolic --abbrev-ref "$REFNAME")
PROJECT='project'
PROJECT_PATH="/var/www/html/$PROJECT"
BARE_REPOSITORY="${PROJECT_PATH}/.git"
if [ ! -d "$PROJECT_PATH/$BRANCH" ]; then
git clone $BARE_REPOSITORY -b "$BRANCH" "$PROJECT_PATH/$BRANCH"
cd "$PROJECT_PATH/$BRANCH" || exit
else
cd "$PROJECT_PATH/$BRANCH" || exit
unset GIT_DIR
git checkout -f "$BRANCH" && git pull origin "$BRANCH"
fi
cd "$PROJECT_PATH/$BRANCH" || exit
export NVM_DIR=$HOME/.nvm
export NODE_VERSION=8.12.0
. $HOME/.nvm/nvm.sh
nvm install $NODE_VERSION
nvm use $NODE_VERSION
npm i
npm run prod
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment