Gitlab Ci 部署在多台服务器上
GitlabCi deploy on multiple servers
我使用 Gitlab runner 并且在单个服务器上运行良好。 gitlab-ci.yml 很简单:
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),但它只是随机更新其中一个。
是否有 gitlab Ci 以某种方式被超过 1 个跑步者触发并根据 gitlab-ci.yml 部署所有跑步者?
是的,只需为同一阶段设置两个作业:
stages:
- deploy
deploy:one:
stage: deploy
script:
- echo "Hello CI one"
deploy:two:
stage: deploy
script:
- echo "Hello CI two"
如有必要,您可以在跑步者身上使用 tags
来选择要使用的跑步者。
您可以从不同的服务器注册多个运行器(例如标记为 serverA 和 serverB)并有多个部署作业,每个都执行由不同的跑步者。这是因为您可以在一个作业中设置多个标签,并且只会使用具有所有标签的跑步者。
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
但是,考虑到其中一项部署作业失败的情况 - 这最终会导致您在服务器上拥有两个不同版本的代码。根据您的情况,这可能是问题,也可能不是问题。
自 2016 年以来,您现在 Environments and deployments
Environments describe where code is deployed.
Each time GitLab CI/CD deploys a version of code to an environment, a deployment is created.
GitLab:
- Provides a full history of deployments to each environment.
- Tracks your deployments, so you always know what is deployed on your servers.
确实 integrates well with Prometheis, and, with GitLab 13.11(2021 年 4 月),您甚至有:
Update a deploy freeze period in the UI
In GitLab 13.2, we added the ability to create a deploy freeze period in the project’s CI/CD settings.
This capability helps teams avoid unintentional deployments, reduce uncertainty, and mitigate deployment risks.
However, it was not possible to update deploy freezes.
In GitLab 13.11, we are adding the ability to edit an existing deploy freeze. This way, you can update the freeze period to match your business needs.
See Documentation and Issue.
如“gitlab-ci.yml
deployment on multiple hosts", you can use YAML anchors触发多环境并行部署,即“多台服务器”。
我使用 Gitlab runner 并且在单个服务器上运行良好。 gitlab-ci.yml 很简单:
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),但它只是随机更新其中一个。
是否有 gitlab Ci 以某种方式被超过 1 个跑步者触发并根据 gitlab-ci.yml 部署所有跑步者?
是的,只需为同一阶段设置两个作业:
stages:
- deploy
deploy:one:
stage: deploy
script:
- echo "Hello CI one"
deploy:two:
stage: deploy
script:
- echo "Hello CI two"
如有必要,您可以在跑步者身上使用 tags
来选择要使用的跑步者。
您可以从不同的服务器注册多个运行器(例如标记为 serverA 和 serverB)并有多个部署作业,每个都执行由不同的跑步者。这是因为您可以在一个作业中设置多个标签,并且只会使用具有所有标签的跑步者。
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
但是,考虑到其中一项部署作业失败的情况 - 这最终会导致您在服务器上拥有两个不同版本的代码。根据您的情况,这可能是问题,也可能不是问题。
自 2016 年以来,您现在 Environments and deployments
Environments describe where code is deployed.
Each time GitLab CI/CD deploys a version of code to an environment, a deployment is created.
GitLab:
- Provides a full history of deployments to each environment.
- Tracks your deployments, so you always know what is deployed on your servers.
确实 integrates well with Prometheis, and, with GitLab 13.11(2021 年 4 月),您甚至有:
Update a deploy freeze period in the UI
In GitLab 13.2, we added the ability to create a deploy freeze period in the project’s CI/CD settings.
This capability helps teams avoid unintentional deployments, reduce uncertainty, and mitigate deployment risks.
However, it was not possible to update deploy freezes.
In GitLab 13.11, we are adding the ability to edit an existing deploy freeze. This way, you can update the freeze period to match your business needs.
See Documentation and Issue.
如“gitlab-ci.yml
deployment on multiple hosts", you can use YAML anchors触发多环境并行部署,即“多台服务器”。