How to set up automatic application deployment using Gitlab?

How to set up automatic application deployment using Gitlab?
Your Hosting
Your Hosting
Updated on 10/10/2023 – 7 min. reading
Blog
Welcome to the continuation of the original article: How to install GitLab . Today we will look at the more important part, which is the setup of the deployment to the production and test server.

If you don’t have GitLab installed yet, you can order our server for a week for free and try everything out. We recommend min. VPS Basic configuration .

Contents
Basic settings

Installation of GitLab runner

SSH key settings
If the installation was successful and you set a specific database by industry password, you will see the welcome page after logging in under the root login.

First login to GitLab

VPS Center

Try our server and domain management application for free. You will feel like an experienced administrator.

Basic settings
The first step is to create your own projects. You can create a completely new one (our case) or clone or import a project.

In the newly created project, we will create 3 important

files: $DEPLOY_USER@$PRODUCTION_SERVER:$PRODUCTION_DIR

 

rsync -ar –compress –delete –exclude-from=.gitignore –rsync-path=”sudo rsync” –chown=www-data:www-data –exclude-from=.deploy_ignore . $DEPLOY_USER@$DEVELOP_SERVER:$DEVELOP_DIR/$PROJECT_NAME-$CI_BUILD_REF_NAME
Installation of GitLab runner
An important part of GitLab are the so-called gitlab-runners, which can be described as a non-stop running daemon that waits for what you give it a task and is responsible for the famous “pushing”.

Freelo – Task and project management tool

Join, invite your team and clients, divide

the work and watch the tasks go into motion.

Official instructions for runner registration in ENG.

Let’s add gitlab-runner to the official repository:

curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh | sudo bash
Then we install the runner with the command:

sudo apt-get install gitlab-runner
Let’s start with registration

sudo gitlab-runner registry

Then the installation will ask for the URL where the gitlab instance is running

Please enter the gitlab-ci coordinator URL (eg https://gitlab.com)

https://gitlab.vas-hosting.cz
In the next step, it is necessary to insert the so-called registration token of the runner, which can be found in the Admin Area > Runners administration.

A token that you can copy from the administration

In step 4, you can describe your runner. You can later change the hostname in the administration.

Please enter the gitlab-ci description for this runner

[host] first-runner

specific database by industry

Step 5 is VERY important. In our .gitlab-ci.yml file, we have specified that deploy is performed by a runner that has the tag: deploy . You can change the tag later in the administration.

Please enter the gitlab-ci tags for this runner (comma separated):

deploy
In the last step, we choose the so-called ” Runner executor “. We have a choice of:

Please enter the executor: ssh, docker+machine, docker-ssh+machine, kubernetes, docker, parallels, virtualbox, docker-ssh, shell:

shell
We will choose shell for our needs . You can also look at the comparison table , where the individual benefits are described.

And that’s it! We have successfully registered the first runner .

Next, we have a “deploy” user specified in the  .gitlab-ci.yml file, which we now need to create.

useradd -m -s /bin/bash deploy

SSH key settings
The last part is the trickiest part and concerns the generation and correct setting of SSH keys.

To generate a new SSH key, we use the RSA method,   which bloga banner dezajno: kiel krei blogan standardon por sporta blogo has worked well for us.

First, we need to log in as root under the user “gitlab-runner”, which was automatically created when Gitlab was installed.

are gitlab-runner
We will generate an SSH key.

ssh-keygen -o -t rsa -b 4096
After generating, you will be asked if you want to leave ar numbers the default path, if so, press Enter. Then you will be asked if you want to encrypt the SSH key, and in our  case we definitely don’t want that = press enter twice.

After that, a key similar to this will appear:

 

Scroll to Top