GitlabCi 部署在多台服务器上 [英] GitlabCi deploy on multiple servers

查看:54
本文介绍了GitlabCi 部署在多台服务器上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Gitlab 运行器,并且在单个服务器上运行良好.gitlab-ci.yml 很简单:

I use Gitlab runner and works fine for a single server. The gitlab-ci.yml is simple:

stages:
  - test
  - deploy

test:
  stage: test
  image: php
  tags:
      - docker
  script:
      - echo "Run tests..."
deploy:
    stage: deploy
    tags:
      - shell
    script:
      - sh deploy.sh

正如我所说,这对于单个服务器来说很好,但要在另一台服务器上部署相同的应用程序?我尝试使用相同的 gitlab-runner 配置(相同的 conf.toml),但它只是随机更新其中一个.

As i said this is fine for a single server but to deploy same app on another server? I tried with same gitlab-runner config (same conf.toml) but then it was only updating one of them randomly.

是否有某种方式 gitlab Ci 会被 1 个以上的跑步者触发并根据 gitlab-ci.yml 部署所有这些跑步者?

Is there somehow gitlab Ci to be triggered by more than 1 runner and deploy all of them according gitlab-ci.yml?

推荐答案

您可以从不同的服务器注册多个运行器(例如标记为 serverAserverB)并进行多个部署工作,每个工作由不同的跑步者执行.这是因为您可以在作业中设置多个标签,并且只会使用具有所有标签的跑步者.

You can register several runners (e.g. tagged serverA and serverB) from different servers and have multiple deployment jobs, each of them performed by a different runner. This is because you can set more than one tag in a job and only a runner having all the tags will be used.

stages:
  - test
  - deploy

test:
  stage: test
  image: php
  tags:
      - docker
  script:
      - echo "Run tests..."

deployA:
    stage: deploy
    tags:
      - shell
      - serverA
    script:
      - sh deploy.sh

deployB:
    stage: deploy
    tags:
      - shell
      - serverB
    script:
      - sh deploy.sh

但是,请考虑其中一项部署作业失败的情况 - 这最终会导致您在服务器上拥有两个不同版本的代码.根据您的情况,这可能是也可能不是问题.

However, take into account a situation when one of the deployment jobs fails - this would end up in you having two different versions of the code on the servers. Depending on your situation this might or might not be a problem.

这篇关于GitlabCi 部署在多台服务器上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆