Gitlab-Runner for Deployment
version: 1.3.8
Created: 12.08.2022
Last edit: 08.12.2023
The current guide is the optional step and can be involved only after provided Deployment of Marionette Stack
You should use the same VM for deployment as was used in the pointed "Deployment of Marionette Stack on Stage" guide.
Also, you need a root level access to the operation system of your PC, basic knowledge on Git and SSH as well, an account on TuneX Gitlab (address: gitlab.tunex.io).
If you don't match some of these requirements please read the manual carefully and use the explanations provided as links to external resources.
Gitlab-runner is a tool for executing instructions from a special ".gitlab-ci.yml" file. In the scope of current guide Girlab-runner automates the rendering of compose and template files and restarting services on each change in the Marionette project. Of course, it make sense only after after finished initial deployment of the Marionette Stack
For more information about gitlab runners follow the source: GitLab Runner | GitLab .
1. Install Gitlab Runner for Deployment
If you are a client and can't perform the actions below yourself, or you are not sure experienced in this topic enough, please contact us and our support will execute this part on your behalf.
1.1. Take hint for install and register Group gitlab-runner on TuneX Gitlab
Note: The Group gitlab-runner can be used for any CI/CD jobs for each project of your Group on TuneX Gitab. That is the main reason to create one Group runner instead of several runners for each project inside your Group on TuneX Gitab.
1.1.1. Open Gitlab menu Settings -> CI/CD inside your Gitlab group on the TuneX Gitlab and push 'Expand' button for runners:
Â
1.1.2. On expanded runners click "Take me there":
Â
1.1.3. Get runners page and click there on "Register a group runners' and push "Show runner installation adn registration instructions":
Â
1.1.4. Use window for next guide steps to install and register runner:
Â
1.2. Connect to VM and install gitlab-runner
Run to connect the VM:
ssh root@[IP address]
where [IP address] - the address of the VM for deploy
You should got something like:
Â
Below used "Download and install binary" from step 1.1.4
Install Gitlab runner (recommend binary install: Install GitLab Runner manually on GNU/Linux | GitLab ):
curl -L --output /usr/local/bin/gitlab-runner "https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64"
Give permissions to execute gitlab-runner
Run next command to add execute permissions:
chmod +x /usr/local/bin/gitlab-runner
create a GitLab CI user:
install and run as service:
1.3. Add user gitlab-runner to sudoers and to docker group
Enable sudo without password for gitlab-runner by next command:
!!! You should never edit /etc/sudoers with a regular text editor, such as Vim or nano, because they do not validate the syntax like the visudo editor
To the end of the opened /etc/sudoers file add this line:
e.g.:
Â
and save changes
2. Register Group gitlab-runner
Connect to the VM again (in case you exit or loose connection):
where [IP address] - the address of the VM for deploy
2.1. Register Group gitlab-runner on VM for deploy in TuneX Gitlab
Use "Command to register runner" from the step 1.1.4:
Â
Here is command for register gitlab-runner:
where [Registration token] copied from "Command to register runner"
Just copy row from "Command to register runner", run it and answer the questions like on the screen:
Â
For success working of the gitlab-runner for CI-CD task rename .bash_logout to .bash_logout.back in the runner home directory:
Make sure you have .bash_logout.back inside /home/gitlab-runner folder, type command:
get similar to the screen:
Â
Restart gitlab-runner service:
Check the status of gitlab-runner:
You should get green active (running) status:
Â
Use "Ctrl+C" on the keyboard to exit the status window of gitlab-runner.
2.2. Check registration of the Group gitlab-runner on the TuneX Gitlab
2.2.1. Use left Gitlab menu CI/CD -> Runners inside Your group:
Â
2.2.2 Check the gitlab-runner is available in the list of Group runners
Here is an example of available gitlab-runner and pointed VM IP and answers during runner register:
Â
3. Set Group gitlab-runner to CI/CD job and run pipeline for deploy
If you are a client and can't perform the actions below yourself, or you are not sure experienced in this topic enough, please contact us and our support will execute this part on your behalf.
3.1. Enter to your Gitlab group on the TuneX Gitlab and click on "Marionette-stage" project:
Â
3.2. Open menu CI/CD -> Editor for project Marionette-stage:
Â
3.3. Edit CI/CD file for "Marionette-stage" project
CI/CD editor opens the file ".gitlab-ci.yml" for editing, make sure it uses script "/root/marionette/deploy-stage" and the tags has "stage":
Â
Note: Learn configuration options for your GitLab .gitlab-ci.yml file: https://gitlab.tunex.io/help/ci/yaml/index
Save commit if ".gitlab-ci.yml" have been changed:
Â
3.4. Open menu CI/CD -> Pipelines for project Marionette-stage:
Â
3.5. Run pipeline and check success deploy
Push button "Run pipeline":
Â
On the opened page push again "Run pipeline":
Â
After running pipile you'll get the process like:
Â
Wait for the finish and get success result like:
Â
4. Conclusion
You've successfully added gitlab-runner for deployment to your Group on TuneX Gitab.