Ответ 1
Вы можете использовать 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 и установить тег delpoyServer на gitlab web. /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
, а затем выполнит script: npm install && & & forever restartall.
ссылка: