Technology Sharing

GitLab CI/CD realizes project automated deployment

2024-07-11

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

1 Introduction to GitLab CI/CD

  • GitLab CI/CD is a set of continuous integration, continuous delivery, and continuous deployment tools for software development integrated in GitLab. This system allows development teams to automate the software delivery process, from detecting code changes, building, testing to the final deployment to the production environment.

  • Continuous Integration (CI)

    • Every time the code is pushed to the version control system (such as GitLab repository), the system automatically builds and tests. This ensures that code changes can be quickly integrated into the main branch and integration errors can be discovered and fixed.
  • Continuous Delivery (CD)

    • On the basis of continuous integration, further automation delivers verified code changes to a pre-production or production-ready environment. This stage may include more complex test suites, performance tests, etc. to ensure that the software can be deployed to the production environment at any time, but the actual deployment may require manual approval.
  • Continuous Deployment (CD)

    • Based on continuous delivery, the delivery process is fully automated, and the code that passes all tests can be directly deployed to the production environment without manual intervention. This means that every code change can reach the user quickly and safely after being tested.

2 GitLab CI/CD and GitLab Runner

  • GitLab CI/CD is a set of services integrated into the GitLab platform that manages the build, test, and deployment processes in the software development lifecycle. It defines various tasks (Jobs) and processes (Pipelines) by reading the .gitlab-ci.yml configuration file in the project, thereby achieving the goals of continuous integration and continuous deployment.

  • GitLab Runner is the actual worker or execution engine that implements these CI/CD processes. It is a separately deployed program that can be installed on different operating systems (such as Linux, macOS, Windows), and registered and bound to the GitLab instance. Once a new commit triggers the GitLab CI/CD process, GitLab will schedule the registered Runner to execute the tasks defined in .gitlab-ci.yml.

  • In simple terms, GitLab CI/CD is the planner and coordinator responsible for defining when and how to execute tasks, while GitLab Runner is the entity that specifically executes these tasks. Runner can be shared (serving multiple projects) or dedicated (serving only a single project), and different execution environments can be configured according to project requirements (for example, using Docker containers to isolate the build environment).

3 GitLab Runner

3.1 Installation

  • Take CentOS as an example
  • Download the gitlab-runner installation package, search for gitlab-runner in the Package column, and you can download this version el/7/x86_64/gitlab-runner-16.6.0-1.x86_64.rpm
  • The installation command is as follows
  •   # 安装
      sudo rpm -ivh gitlab-runner-16.6.0-1.x86_64.rpm	
      # 查看是否安装成功
      gitlab-runner -h