Gitlab-Runner Deploy to multiple servers

Viewed 5961

I got following environment and setup:

  • 3 load balanced production servers and
  • one development server
  • a working auto deployment to my development server with
    • one gitlab-runner which connects by ssh to my dev-server and pulls the dev-branch and
    • a gitlab-ci.yml which is limited to my dev-branch

How can I achieve:

  • further auto-deploy to my development server if I push into my dev-branch
  • auto deploy to my 3 production servers if I push into my master-branch

The question is based on my current setup where following questions came up

  • can I let a gitlab-runner run just locally (also not in a docker container because I havn't installed one) so that its just up to the gitlab-ci.yml to differ on branches and deploy to the specific servers or
  • can I install multiple gitlab-runners which are taking aktion on just specific branches?

or is there another solution which lets me achieve my plans?

1 Answers

"Can I let a gitlab-runner run just locally (also not in a docker container because I havn't installed one) so that its just up to the gitlab-ci.yml to differ on branches and deploy to the specific servers"

Yes, register local runners as specific runners with Shell executors on the machines you want to deploy to so they can run local commands just like you use SSH now and only your specific projects can use them. Then take a look at the next sub-answer regarding tags.

"Can I install multiple gitlab-runners which are taking aktion on just specific branches?"

Use either tags to pin certain jobs to runners (e.g. your deploy job) or use only or except to pin jobs to branches or tags. (e.g. your deploy_prod job only run on master branch)

Example .gitlab-ci.yml file (abstract):

deploy-dev:
  tags: 
    - dev-runner
  only: 
    - dev-branch
  script:
    - cd mydir
    - git pull

deploy-prod:
  tags: 
    - prod-runner
  only: 
    - master
  script:
    - cd mydir
    - git pull
Related