Background: ONCE I saw the powerful GitLab assembly line of other project teams by chance, I remembered that I had to do some repetitive work by manual mirroring every day, and instantly became jealous. That’s the assembly line I want. As it happens, the team decided to move the code to the company’s machines, so it was time to complete GitLab.
Noun:
- .gitlab-ci.yml
YAML
.gitlab-ci.yml
YAML
The official tutorial
image: docker:stable
before_script:
- echohttp://mirrors.ustc.edu.cn/alpine/v3.6/main > / etc/apk/repositories;echohttp://mirrors.ustc.edu.cn/alpine/v3.6/community > > / etc/apk/repositories - apk update apk - add, update the git bash - docker login -u yourName -p yourPas yourDockerIp stages: -test
- build_docker
- cleanup_build
test:
stage: test
allow_failure: truecache: paths: - node_modules/ script: - apk add, update nodejs nodejs NPM - NPM install - registry = http://192.168.130.131:9090 - NPMtest
only:
- branches
build_docker:
stage: build_docker
retry: 2
script:
- apk add bash
- bash build-docker.sh
only:
- dev
- master
- release
- /^hotfixes-\d.\d.\d$/
cache:
paths:
- node_modules/
cleanup_build_dicker:
stage: cleanup_build
retry: 2
when: on_failure
script:
- CI_COMMIT_REF_NAME=${CI_COMMIT_REF_NAME} bash build-docker.sh
only:
- branches
- dev
- master
- release
Copy the code
-
Gitlab-runner
Gitlab-runner
.gitlab-ci.yml
-
Pipelines
.gitlab-ci.yml
Pipelines
stages
jobs
.gitlab-ci.yml
Let’s start the installation
1. Set up private GitLab:
During this setup process, I used an Ubuntu VIRTUAL machine. After entering a set of commands in the virtual machine, THE installation was almost complete. Most of the time I was still googling and trying various methods. After comparing several tutorials, I found a method that works for me.
forUbuntu add GitLab image source and install curl-sS http://packages.gitlab.com.cn/install/gitlab-ce/script.rpm.sh | sudo bash sudo yum install gitlab - ce configuration and start gitlab sudo gitlab-ctl reconfigureCopy the code
Next, you can access our GitLab by domain name. The first visit will require initial administrator password. After setting, the system will be redirected to the login page
2. Install gitlab – runner
At the beginning of the installation, I used the installation method provided by the government, but after a few operations, I found it was not easy to use (I must have opened it in the wrong way). So I silently opened the almighty Google and installed Gitlab-Ci-Multi-Runner. It’s still a bunch of commands. Wait for it to download. Refer to this netizen’s article for detailed introduction
1. Add Gitlab official source: curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-ci-multi-runner/script.deb.sh | sudo bash 2. Sudo apt-get install gitlab-ci-multi-runner 3 Sudo gitlab-ci-multi-runner register Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com) https://mygitlab.com/ci Please enter the gitlab-ci tokenfor this runner
xxx-xxx-xxx
Please enter the gitlab-ci description forthis runner my-runner INFO[0034] fcf5c619 Registering runner... succeeded Please enter the executor: shell, docker, docker-ssh, ssh? Docker Please enter the docker image (eg. Ruby :2.1): Node :4.5.0 INFO[0037] Runner registered successfully. Feel free to start it, butif it's
running already the config should be automatically reloaded!
Copy the code
At step 3, you fill in some information and follow the prompts down the line, where Toker can get IP /admin/runners from our GitLab administrator home page.
After the configuration is completed, runner needs to be edited at the bottom of the page to associate runner with the project, and then the assembly line can be run.
At this point, we are one step away from configuring the Runner: setting up the runner for the project. Enter the CI/CD Settings screen of the project (Settings => CI/CD => Runners), find the runner you just associated, and activate it.
Once this is done, the project is ready to run smoothly. When there are code updates in the project branch, you can see the current status of the tasks we defined in.gitlab-Ci-yML.
Pits encountered:
An error was encountered while installing GitLab
There was an error running gitlab-ctl reconfigure:
execute[/opt/gitlab/embedded/bin/initdb -D /var/opt/gitlab/postgresql/data -E UTF8] (postgresql::enable line 80) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
---- Begin output of /opt/gitlab/embedded/bin/initdb -D /var/opt/gitlab/postgresql/data -E UTF8 ----
STDOUT: The files belonging to this database system will be owned by user "gitlab-psql".
This user must also own the server process.
STDERR: initdb: invalid locale settings; check LANG and LC_* environment variables
---- End output of /opt/gitlab/embedded/bin/initdb -D /var/opt/gitlab/postgresql/data -E UTF8 ----
Ran /opt/gitlab/embedded/bin/initdb -D /var/opt/gitlab/postgresql/data -E UTF8 returned 1Copy the code
Under the guidance of the full stack leader, modify the /etc/default/locale file to add the following two configuration lines:
LC_CTYPE="en_US.UTF-8"
LC_ALL="en_US.UTF-8"Copy the code
There is also the problem of docker in Docker. It is obviously unrealistic to install a Docker every time in runner, so we used external Docker and GitLab official also provided corresponding tutorials.
During the installation process, downloading some resources is very slow, be sure to switch to the domestic image source!! Attached is the mirror source of USTC
echohttp://mirrors.ustc.edu.cn/alpine/v3.6/main > / etc/apk/repositories;echohttp://mirrors.ustc.edu.cn/alpine/v3.6/community > > / etc/apk/repositoriesCopy the code
After running for a period of time, Runner will generate a lot of images to fill the memory, and docker images can be used to check the current image situation. Unnecessary mirrors need to be cleaned and removed. You are advised to add a scheduled task to periodically clear mirrors
- Remove the mirror
docker rmi $(docker images | grep 'dev.k2data.com.cn:5001')Copy the code
- Scheduled Task Script
#! /bin/sh p=`df / | awk '{print $5}' | grep -Eo '[0-9] +' ` if p > 85; then docker rmi $(docker images | grep 'dev.k2data.com.cn:5001') fi Copy the code
The backup
gitlab-rake gitlab:backup:create
Copy the code
Conclusion:
With the help of the leader and several operation and maintenance colleagues, I could basically use the gITLab assembly line construction trip. Due to the narrow scope of knowledge, I spent most of the time looking up materials, reading documents and constantly testing. It is really beneficial to open books, think of the high school physics teacher said that sentence :” read more books, it is impossible to read bad people.”
The whole process is not too difficult to get down, and there are not many commands. But before the installation, the need to rely on their own online to search for all kinds of tutorials, midway will also appear a thousand strange mistakes, each step can give a tutorial alone. We need to go through the tutorials one by one and choose the one that suits us best. This is where it takes the most time. Another time consuming point is testing and installing dependencies, which can take up to an hour to wait for the download, only to find that the download fails.