使用git的进行持续部署
使用git的hook进行持续部署
总结自
安装git
-
Centos
yum install -y git
-
Ubuntu
apt-get -y git
-
windows
https://git-scm.com/ 下载安装
创建git bare仓库
cd /opt
git init repo.git --bare
编写hook文件
cd repo.git/hooks
vim post-receive
---
#!/bin/bash
GIT_DIR=/opt/repo.git
WORK_DIR=/opt/app/
echo 'server: received code push...'
cd ${WORK_DIR}
echo 'server: checkout latest code from git...'
git --git-dir=${GIT_DIR} --work-tree=${WORK_DIR} checkout master -f
echo 'server: build code...'
# build code
---
# 编写完成后保存并赋予执行权限
chmod +x post-receive
# build code demo
# python
if [ -d venv ];then
. venv/bin/activate
else
python3 -m venv venv && . venv/bin/activate
fi
pip install -r requirements.txt
python manage.py run
# java
mvn clean install
cd target
java -jar jar.jar
在本地库上添加远程推送地址
git remote add prod ssh://root@127.0.0.1/opt/repo.git
推送到本地git库
git push prod master