8

For you who are using Nestj as a project for the first time (Part 2: Configure gitlab-runner & operate gitlab)

If you don’t want to build gitlab , please skip to section 6.

1. CI/CD

We usually use some CI/CD continuous integration, for example, the dev gitlab is updated every time, but these functions are not CI , we will directly package and publish to the test environment, then we will configure This functional module.

2. gitlab-runner

Performing construction tasks is very performance consuming, so gitlab uses gitlab-runner alone to build projects independently, so in fact, gitlab provides an interface that can correspond to multiple runner , and different projects can be built with different runner .

Step 1: pull
docker pull gitlab/gitlab-runner
Step 2: run
docker run -d --name gitlab-runner --restart always \
  -v ~/gitlab-runner/config:/etc/gitlab-runner \
  -v /var/run/docker.sock:/var/run/docker.sock \
  gitlab/gitlab-runner

The above is a mapping of the configuration docker

Step 3: Registration
docker exec -it 容器id gitlab-runner register

It means I am going to execute gitlab-runner register

The container id above can be viewed with the following command

docker container ps -a 

image.png

Register and fill in the information

When the registration command is executed, we will let us fill in Url and Token . This parameter can be found in the picture:
image.png

Or open a project:

image.png

  • Set label

image.png
You can understand it as setting up an alias for us to manage and call this runner .

  • Setting up the environment

image.png
Here it is not equipped with node like, do not shell , direct selection docker .

  • Set the default mirror

image.png

3. Configure runner

Let's first look at the activated runner .
image.png
The tag here is set during initialization just now.

Set it to default runner

image.png

image.png

4. Pull the address of the project for correction (configure gitlab)

Into our container
docker exec -it gitlab_lulu bash 

vim /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml

image.png

Now you can access it correctly:
image.png

5. Upload a yml file to try

Just build a vue project

image: node

cache:
  paths:
    - node_modules/

install:
  tags:
    - tag1
  script:
    - echo 1111

image.png

6. Initially a gitlab module

This library is seldom used, and the documents are all in English. I will talk about how to learn it later.

installation
yarn add @gitbeaker/node
Generate gitlab module
nest g controller modules/gitlab

nest g service modules/gitlab
Simple configuration

/share/src/modules/gitlab/gitlab.controller.ts

import { Controller, Get } from '@nestjs/common';
import { GitlabService } from './gitlab.service';

@Controller('gitlab')
export class GitlabController {
    constructor(
        private readonly gitlabService: GitlabService
    ) { }
    @Get()
    getTags() {
        return this.gitlabService.getTags();
    }
}

/share/src/modules/gitlab/gitlab.service.ts

import { Injectable } from '@nestjs/common';

@Injectable()
export class GitlabService {
    getTags() {
        return 'tags列表'
    }
}

The effect is as follows:
image.png

Seven. Use @gitbeaker/node operate gitlab : Get all tag

/share/src/modules/gitlab/gitlab.service.ts

The first step is to get token

token with 0609c650077174 can you have the right to access some items, turn on the permissions, and set the expiration time.
image.png

image.png

Copy your token and put it in the project.

image.png

The second step is new an api instance

image.png

image.png

The third step is to label and try

image.png

image.png

8. How to learn to use @gitbeaker/node

The first step: query the desired api

Search for the keywords you want here, api document
image.png

Step 2: Click in to find the operation you want

For example, this new label

image.png

Step 3: Generally, the operation name is the method name

Check his parameter settings, options is generally the parameters to be passed.

image.png

Step 4: call the method

image.png

This ref can be understood as a unique label, so it can be commitID :

image.png

Step 5: View the results

image.png

image.png

end.

Next, we are going to perform database-related operations. If you have not done back-end related projects, you should take a closer look. It involves how typeorm handles many-to-many and many-to-one relationships. I will compare the pits I encountered I will show you all the experience and experience, and I hope to make progress with you.


lulu_up
5.7k 声望6.9k 粉丝

自信自律, 终身学习, 创业者