# 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