Nick Doulgeridis
Nick Doulgeridis

Reputation: 613

GitlabCi deploy on multiple servers

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

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.

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

Upvotes: 11

Views: 11211

Answers (3)

VonC
VonC

Reputation: 1323115

Since 2016, you now have 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.

It does integrates well with Prometheis, and, with GitLab 13.11 (April 2021), you even have:

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.

https://about.gitlab.com/images/13_11/update_deploy_freeze_1.png -- Update a deploy freeze period in the UI

See Documentation and Issue.

As shown in "gitlab-ci.yml deployment on multiple hosts", you can use YAML anchors to trigger parallel deployment on multiple environments, which means "multiple servers".

Upvotes: 0

tmt
tmt

Reputation: 8604

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.

Upvotes: 10

Martin
Martin

Reputation: 3114

Yes there is, just set up two jobs for the same stage:

stages:
  - deploy

deploy:one:
  stage: deploy
  script:
    - echo "Hello CI one"

deploy:two:
  stage: deploy
  script:
    - echo "Hello CI two"

If necessary you can use tags on your runners to choose which one to use.

Upvotes: 2

Related Questions