您可以使用gitlab-ci和gitlab-runner [runners.ssh]来部署到单个或多个服务器 .
流程:
(git_project with yml file) --> (gitlab && gitlab-ci) --> (gitlabrunner) ---runners.ssh---> (deployed_server,[deploye_server2])
你需要将gitlab-runner注册到gitlab-ci并在gitlab web上将标签设置为delpoyServer . /etc/gitlab-runner/config.toml:
[[runners]]
url = "http://your.gitlab.server/ci"
token = "1ba879596cf3ff778ee744e6decedd"
name = "deployServer1"
limit = 1
executor = "ssh"
builds_dir = "/data/git_build"
[runners.ssh]
user = "you_user_name"
host = "${the_destionation_of_deployServer_IP1}"
port = "22"
identity_file = "/home/you_user_name/.ssh/id_rsa"
[[runners]]
url = "http://your.gitlab.server/ci"
token = "1ba879596cf3ff778ee744e6decedd"
name = "deployServer2"
limit = 1
executor = "ssh"
builds_dir = "/data/git_build"
[runners.ssh]
user = "you_user_name"
host = "${the_destionation_of_deployServer_IP2}"
port = "22"
identity_file = "/home/you_user_name/.ssh/id_rsa"
runner.ssh表示,跑步者将登录 ${the_destionation_of_deployServer_IP1} 和 ${the_destionation_of_deployServer_IP2} ,然后将项目克隆为 builds_dir .
编写yml文件,例如:.gitlab-ci.yml
job_deploy:
stage: deploy
tags: delpoyServer1
script:
- npm install && forever restartall
job_deploy:
stage: deploy
tags: delpoyServer2
script:
- npm install && forever restartall
将你的gitlab-runner设置为'http://your.gitlab.server/ci/admin/runners'中的 delpoyServer1 和 delpoyServer2 标签
当你将代码推送到gitlab时
gitlab-ci服务器将解析您项目中的 .gitlab-ci.yml 文件,选择带有标签的跑步者: deployServer1 或 deployServer2 ;
带有deployServer1标签的 gitlab-runner 将使用ssh登录 ${the_destionation_of_deployServer_IP1} 和 ${the_destionation_of_deployServer_IP2} ,将项目克隆为 builds_dir ,然后执行脚本:npm install && forever restartall .
链接: