我有一个gitlab CI脚本,该脚本使用Web服务器上的运行程序部署网站。有多个部署(取决于分支)。除了文件复制到的htdocs目录之外,该脚本始终相同。
stages:
- build
- deploy
pages:
stage: build
script:
- hugo
artifacts:
paths:
- public/
deploy_to_test:
stage: deploy
tags:
- web-deploy
script:
- rsync -av --omit-dir-times --no-owner --delete public/ /var/www/wwwtest.my/
- find /var/www/wwwtest.my/ -type f -exec chmod 644 {} \;
- find /var/www/wwwtest.my/ -type d -exec chmod 755 {} \;
environment:
name: test
only:
- develop
deploy_to_prod:
stage: deploy
tags:
- web-deploy
script:
- rsync -av --omit-dir-times --no-owner --delete public/ /var/www/www.my/
- find /var/www/www.my/ -type f -exec chmod 644 {} \;
- find /var/www/www.my/ -type d -exec chmod 755 {} \;
environment:
name: prod
only:
- master
是否有可能坚持DRY原则,仅将htdocs目录设置为分支相关变量并重用部署脚本?