安装参考
- 安装 https://about.gitlab.com/installation/#centos
- 配置 https://docs.gitlab.com/omnibus/settings/nginx.html
CI自动集成
示例
项目合并到master的tag提交文件自动上传到远程部署
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
stages: - build - test - deploy build-job: script: - uname -a stage: build only: - tags simple-test: script: - php -v stage: test only: - tags deploy-all-server: stage: deploy when: manual # 管理员手动执行 artifacts: paths: - update/ only: - tags script: # - git diff --name-status HEAD^ | awk '$1!="D"{print $2}' > update/`cat .git/HEAD`-files.log - git diff --name-status `git tag | tac | awk 'NR==2{print}'` | awk '$1!="D"{print $2}' > update/`cat .git/HEAD`-files.log - cat update/`cat .git/HEAD`-files.log | xargs -ti /root/.pyenv/versions/py2711/bin/ansible-playbook --check /etc/ansible/play_books/sync_file.yaml -e file={} -vvv |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
git checkout develop git pull # 生成更新的文件列表, 用于线上备份 git diff --name-status 036182eefcda24d2f7^ ef4f1b8c5174525 | awk '{print $2}' > ../update-smrz-update1-files.log ## 生成文件包 git archive --format tar -o ../update-smrz-update1.tar ef4f1b8c5174525 $(git diff --name-status 036182eefcda24d2f7^ ef4f1b8c5174525 | awk '{print $2}') # 复制文件到远程 cd .. scp update-smrz-update1* abak:/home/xnjcw_branch # 远程登录 ssh SERVER-HOST # 备份文件 cd PROJECT-DIR tar -cf ../update-smrz-update1-bak.tar `cat ../update-smrz-update1-files.log` # 更新文件 cd .. tar -xf update-smrz-update1.tar -C newjc001/ # 修复更新文件属主 cd newjc001/ tar -tf ../update-smrz-update1.tar | xargs chown ftp.ftp |