目前使用的source code management tool 是gitlab, 除了行使git 的功能外,对每次 merge request 都做了额外的CI/CD操作,这里记录一下相关语法和总结 from course Continuous Delivery with GitLab
CI
: code and feature integraion, combining updates into existing code base, testing with automation.
CD
: delivery can mean deployment, the process of building and deploying the app, for example, upload the object to somewhere that customer can download.
Gitlab uses pipelines to do both CI/CD
, defined in .gitlab-ci.yml
file at your branch.
Tips
[x] To navigate the source code in gitlab repo, try launch the Web IDE
, will show you a structure tree on left side of the files.
[x] Use snippet to share code or file block for issue solving, the same as gPaste.
[x] To-do list is someone mentions you in some events.
[x] Milestone is a goal that needs to track.
[x] Merge request (pull request in github) after merged can auto close the issue, deponds on setting.
Setup self-managed Gitlab
You can experiment with gitlab community edition locally by bringing up a gitlab server through Vagrant. For example, Vagrantfile, there are 2 VMs, one VM for configuring docker gitlab runner:
1 | # -*- mode: ruby -*- |
Vagrant quick commands:
1 | vagrant up |
Install the packages references from there, but it uses enterprise edition, we use community edition.
1 | # Update package manager and install prerequisites |
After install, go to browser and hit http://192.168.50.10
, reset root password and login as root
with the reseted password.
Experiment
[1] Create a new project hello world
(You can also create it by setting jenkins pipeline)
Use root user to create a private project, check RAEDME added option.
[2] Create a admin user, so don’t need to use root
user anymore.
Grant the new user as admin
, edit the password that will be used as temporary password next time you login.
sign out and sign in again with new admin user.
[3] Setup SSH for your user The same process as setup SSH on github, go to setting -> SSH keys.
[4] Create new project under admin user, set as priviate scope.
[4] Create anthos vagrant VM as gitlab client To avoid messing up system git global configuration, then vagrant ssh and git clone the project.
Go to project dashboard, in the left menu:
The CI/CD
tab is what we will focus on
The Operations
tab is where gitlab integrate other systems in your stack, for example kubernetes.
The Settings -> CI/CD
is about configuration.
CI/CD
[x] SonarQube, code quality testing tool.
.gitlab-ci.yml
通过设计stage 搭配完成了both CI/CD 的操作。可以通过不同的条件判断,对特定的branch 进行不同的CI/CD. 每次MR 之前和之后都各有一个 pipeline,针对的是MR前后的branch. 设置了jenkins pipeline double-commit 到master branch, 因为如果需要修改gitlab-ci.yml
只会checked in 到 master中, 所以变化要在master中得到体现。
CI
test levels, each of them is a stage in pipeline, should fail early and fail often.
- syntax and linting
- unit and integration
- acceptance
Gitlab runner is similar to jenkins, support run on VM, bare metal system or docker container or kubernetes. Here we use docker, so install docker first, can reference here
Here we install docker on gitlab server VM. [x] You can spin up another VM with 2GB, install docker and run gitlab runner container there. But make sure the VM can ping each other, just like what I did in Vagrantfile.
This docker install is on Ubuntu
, Centos
or other linux distro please see different way to install docker:
1 | sudo apt-get update |
Install docker gitlab runner, reference is here
1 | # name is gitlab-runner |
Then register the runner to your gitlab project, go to gitlab project Settings -> CI/CD -> Runners expand to see the registeration token.
1 | # later gitlab-runner is command |
Then reload the gitlab runner page, you will see the registered runner is there, click runner name to see specific. This runner is locked to this project, but you can alter it (the edit icon right near runner).
Create .gitlab-ci.yml
in your repo to specify the pipeline, if you create it on web IDE, you can choose a template for it, for example the bash template, more advanced syntax please see gitlab-ci doc:
1 |
|
In the Pipeline page, CI Lint
is the tool can edit and validate the .gitlab-ci
yaml file syntax.
You can also use Settings -> CI/CD -> Environment variables expand to set the env variables.
[x] where is the run-dev-check.sh script hosted? it is git cloned from another repo.
1 | script: |