您可以使用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设置为,
delpoyServer1
并delpoyServer2
在’ http://your.gitlab.server/ci/admin/runners ‘- 当您将代码推送到gitlab时
- gitlab-ci服务器将解析
.gitlab-ci.yml
项目中的文件,选择带有标签的运行器:deployServer1
或deployServer2
; - 在
gitlab-runner
与deployServer1标签将登录到${the_destionation_of_deployServer_IP1}和${the_destionation_of_deployServer_IP2}使用ssh,克隆该项目builds_dir
,然后执行你的脚本:NPM安装&&永远restartall。
链接:
- gitlab-runner注册
- 跑步者



