Original Intention: The company’s front end and testers got into a fight today. The reason is that the test complained that the front-end staff changed the status of the Bug to resolved, so that the code was not submitted at all, and the front-end staff complained that the test was tested too often, and it was inconvenient to have to type several environment packages. It takes time to change things and pack them frequently. All have their own reasons, just don’t want to solve the problem.

Well, to solve this problem, I’m going to look at Gitlab’s CI integration. If I can get it, then the developer will just write the code and build the environment automatically.

I am also learning to sell now. According to the official website and search materials today, I just ran through the basic process. It took some time, so I will record it here

Gitlab CI/CD Quick start

According to the official website, to use CI, just make two things on the line

1 Create a. Gitlab-ci. yml file in your project that configures Piplines and stages as well as scripts. Gitlab-runner executes this file to build the environment.

Install and configure Gitlab-runner, a Go written tool for executing scripts in.gitlab-ci.yml.

A created. Gitlab – ci. Yml

stages:
  - deploy
 
deploy_develop:
  stage: deploy
  tags:
    - nodejs
  script:
    - echo "hello,ci/cd"
  only:
    - dev
Copy the code

In the above file I define a piplines(deploy) and a job(deploy_develop) that only applies to the dev branch and executes this job which prints “hello,ci/ CD”

Gitlab-runner installation and configuration

The Gitlab-runner does not need to be on the same machine as the Gitlab, or even on the local machine. On the contrary, the official advice is best alone, build must consume performance, do not affect other business good.

Install gitlab – runner docs.gitlab.com/runner/inst… I follow the official steps step by step, the system is Centos, if other systems according to the above installation method

sudo wget -O /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64
Copy the code

If you need to set environment variables, set /usr/local/bin to the PATH

Set the executable permission

sudo chmod +x /usr/local/bin/gitlab-runner
Copy the code

Add a single user for gitlab-runner

sudo useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash
Copy the code

Install services and start

sudo gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner
sudo gitlab-runner start
Copy the code

Three configuration gitlab – runner

After installing Gitlab-Runner, you need to register under the Api communication between runner and Gitlab

gitlab-runner register
Copy the code

Please enter the gitlab-ci coordinator URL (e.g. gitlab.com/): http://172.18.10.22/

Query Specific Runners in Charge at GitLab

Problems encountered

  1. This job is stuck, because you don’t have any active runners that can run This job. Tags are required. The value was set when gitlab-Runner was registered
stages:
  - deploy
 
deploy_develop:
  stage: deploy
  tags:
    - nodejs
  script:
    - echo "hello,ci/cd"
  only:
    - dev
Copy the code
  1. Using git clone pull code access problems When I install gitlab – runner is using a new user, and then in gitlab – runner installed on the machine use git clone code times permission problems. The public key corresponding to Gitlab needs to be added to the user’s.ssh/ directory

After the above steps, the basic of CI was finished, in the later development, the code only needs to be close to the corresponding branch, will be in accordance with. Gitlab – CI. Yml script built inside, just remember in the last company see the feel good hard ah, just haven’t been to, is not a today to tried under not only by some more impressive, It doesn’t feel as mysterious as it used to.

I’m just running through the basics of this one, and I’m going to pack it with nodeJS and webPack front end, and then I’m going to create a shell script and define it in gitlab-ci.yml.

PS: here I have to spray the company’s operation and maintenance, usually do nothing, the four operation and maintenance in addition to the usual release of a version of nothing, and no matter the environment or what, never care, are the development of their own. Asked for an online read-only permission library also refused to give, said there are security issues, some of the online problems are completely untraceable.

And, more ridiculous, the online version you can’t imagine, are our local into a compressed package to the designated folder, and then they released a machine, what age, but also the whole so original. I wish I had time to study current tools to improve efficiency. The key is that our leader has the same idea, which leads to this kind of thing being pressed all the time.

For example, when I installed Ci today, I thought that Gitlab-Runner must be installed on the machine of GitLab, so I went to ask them for permission. However, they refused, saying that THEY had not heard what Ci was and that it might be safe. Later, when I saw the official document that Ci could not be installed on the same machine, I found a test machine in our department to install it. Ah, really speechless.

The programmer’s crisis is mostly self-inflicted. When that day was eliminated, and will blame the reality of the ruthless, I do not know all this and from have a great relationship, very glad I have been working hard to maintain the habit of learning.