Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploy every build to a server using Gitlab CI

I've set up my own Gitlab server with one project and a Gitlab runner configured for it. I'm new to continuous integration server and therefore don't know how to accomplish the following.

Every time I commit to the master branch of my project I would like to deploy the repository to another server and run two shell-commands there (npm installand forever restartall)

How would I do this? Do I need a runner on the machine which the project is deployed to as well?

like image 958
Hedge Avatar asked Nov 17 '15 22:11

Hedge


People also ask

Can we deploy using GitLab?

GitLab CI/CD can automatically build, test, deploy, and monitor your applications by using Auto DevOps.

Is GitLab CI CD good?

GitLab CI/CD is one of the most loved CI/CD tools used for DevOps testing. GitLab CI/CD has strong documentation, easy control, good User Experience on its side.

What is the difference between continuous deployment and continuous delivery?

Continuous Delivery is the automation of steps to safely get changes into production. Where Continuous Deployment focuses on the actual deployment, Continuous Delivery focuses on the release and release strategy. An elusive goal would be a “push of a button” to get changes into production.


1 Answers

You could use gitlab-ci and gitlab-runner [runners.ssh] to deploy to single or mutiple servers.

the flow:

(git_project with yml file)  --> (gitlab && gitlab-ci) --> (gitlabrunner) ---runners.ssh---> (deployed_server,[deploye_server2]) 
  1. you need register gitlab-runner to gitlab-ci and set the tag to delpoyServer on 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" 

the runner.ssh means, the runner will login into ${the_destionation_of_deployServer_IP1} and ${the_destionation_of_deployServer_IP2}, then clone the project to builds_dir.

  1. write the yml file for example: .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 
  2. set the your gitlab-runner to delpoyServer1 and delpoyServer2tags in 'http://your.gitlab.server/ci/admin/runners'

    • when you push you code to gitlab
    • the gitlab-ci server will parser your .gitlab-ci.yml file in your project, choose a runner with the tags: deployServer1 or deployServer2;
    • the gitlab-runnerwith the deployServer1 tag will login into ${the_destionation_of_deployServer_IP1} and ${the_destionation_of_deployServer_IP2} with ssh , clone the project to builds_dir, then execute you script: npm install && forever restartall.

link:

  • gitlab-runner register
  • runners.ssh
like image 112
michael Avatar answered Oct 13 '22 07:10

michael