sh 部署com post-receive

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 部署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

以上是关于sh 部署com post-receive的主要内容,如果未能解决你的问题,请参考以下文章

git服务器搭建post-receive 钩子部署服务端代码

python post-receive.py

sh Openshift部署com oc

post-receive in Windows---git hooks trigger Jenkins to build artifcat

git hook 自动部署

编写一个 git post-receive 钩子来处理特定的分支