Writing in the front

Git is an open source distributed version control system designed to handle any project, small or large, with agility and efficiency. Git workflow:

It is not hard to see that the process of using Git is the synchronization between the remote repository and the local repository, and the repository is very important in the git process. Today, we will use Docker and GitLab to build a remote warehouse to further understand the use of GitLab.

For Docker, there is no need for a detailed introduction. It is one of the hottest open source projects and can deploy applications to a container by adding a layer of abstraction. In seemingly stable and mature scenarios, the benefits of using Docker are increasing. In this article, I’m not going to talk about what Docker is or how Docker works. Instead, I’m going to present the top five benefits of using this growing platform: The Top five Docker Benefits: Continuous integration, version control, portability, isolation, and security.

GitLab is an open source project for warehouse management system. It uses Git as a code management tool and builds web services based on it.

Developed by Ukrainian programmers DmitriyZaporozhets and ValerySizov, GitLab is written in Ruby. Later, some parts were rewritten in Go language, which is now widely used by large and medium-sized Internet companies at home and abroad.

GitLab is divided into Community Edition (CE) and Enterprise Edition (EE). The community edition is free, while the Enterprise edition includes some paid services and is generally sufficient for individual developers. About the differences between the community version and the enterprise version, you can go to the official website to check. This document describes how to install the CE version

Docker install portal:

  • Official Installation method
  • Community tutorial
  • Docker image acceleration
  • Domestic mirror acceleration

I. Installation and configuration

From 1.DockerMirror warehouse pullgitlabThe mirror

# gitlab-ce is a stable version. If no version is specified, the latest version will be pulled by default
# (This step may take a long time, please be patient ⌛️...)
$ docker pull gitlab/gitlab-ce
Copy the code

If you need to install another version, please go to the official image library to find another version number, or use the command to find:

Find images from Docker Hub
$ docker search gitlab
Copy the code

Parameter Description:

  • NAME: indicates the NAME of the mirror repository source
  • DESCRIPTION: indicates the DESCRIPTION of the mirror
  • OFFICIAL: Is it OFFICIAL with Docker
  • Stars: Similar to Github star, which means to like or like.
  • AUTOMATED: Automatic construction.

Pull the Gitlab image, which can be viewed by using the following command:

# list local mirrors
$ docker images
Copy the code

2. Run the GitLab image

First, before we run it, we need to know how Docker creates and runs containers:

Create a new container and run a command
docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
Copy the code

GitLab configuration (etc), logs, and data are usually placed outside the container for future upgrade, so please prepare these three directories first. Before setting everything else, configure a new environment variable, $GITLAB_HOME, that points to the directory where the configuration, log, and data files will reside. Ensure that the directory exists and that the appropriate permissions are granted.

export GITLAB_HOME=$HOME/docker/gitlab
Copy the code

$HOME: when the system root directory, you need to create the docker/gitlab directory in advance

# execute in the root directory of the system.
mkdir docker/gitlab
Copy the code

The GitLab container uses host-installed volumes to store persistent data:

Mount to the specified directory on the host Container directory instructions
$GITLAB_HOME/data /var/opt/gitlab Used to store application data.
$GITLAB_HOME/logs /var/log/gitlab Used to store logs.
$GITLAB_HOME/config /etc/gitlab Used to store GitLab configuration files.

sudo docker run --detach \
  --publish 443:443 --publish 80:80 --publish 22:22 \
  --name gitlab \
  --restart always \
  --volume $GITLAB_HOME/config:/etc/gitlab:Z \
  --volume $GITLAB_HOME/logs:/var/log/gitlab:Z \
  --volume $GITLAB_HOME/data:/var/opt/gitlab:Z \
  gitlab/gitlab-ee
Copy the code

Or:

$ docker run -d  -p 443:443 -p 9000:80 -p 22:22 --name gitlab --restart always -v $HOME/docker/gitlab/config:/etc/gitlab -v $HOME/docker/gitlab/logs:/var/log/gitlab -v $HOME/docker/gitlab/data:/var/opt/gitlab gitlab/gitlab-ce

# -d: background running
# -p: Map the internal ports of the container outward
# --name: name the container
-v: Mount the data folder, log folder, and configuration folder to the specified directory on the host

# 443:443: Map HTTP :443 to external port 443
# 99:80: Map Web :80 to external port 9000
# 22:22: Map SSH :22 to external port 22

Copy the code

A string appears after a successful run

You can run the following command to view the running containers:

# list containers. Only containers that are already running are displayedDocker PS displays all containers, including those that are not running. docker ps -aCopy the code

Output details:

  • CONTAINER ID: indicates the ID of a CONTAINER
  • IMAGE: IMAGE used
  • COMMAND: The COMMAND that is run when the container is started
  • CREATED: time when the container was CREATED
  • STATUS: indicates the STATUS of the container
  • PORTS: container port information and connection type used (TCP \ UDP)
  • NAMES: automatically assigned container NAMES

There are seven container states:

  • Created (already created)
  • Restarting
  • Running
  • Removing (on the move)
  • Paused
  • Exited (stop)
  • He was dead.

Configuration of 3.

The gitLab container works fine as described above, but when creating a project on GitLab, the URL access address of the generated project is generated according to the hostname of the container, which is the container ID. As gitlab server, we need a fixed URL to access the address, then need to configure the gitlab. Rb (hosting path: $HOME/gitlab/config/gitlab rb), configure the HTTP protocol used to access the address

$HOME is the root directory of the current system, and can be modified according to its own path
vim $HOME/gitlab/config/gitlab.rb

# configure the HTTP protocol to use the access address, without the port number default 80
external_url 'http://127.0.0.1'

Configure the IP address and port used by SSH
gitlab_rails['gitlab_ssh_host'] = 'http://127.0.0.1'
gitlab_rails['gitlab_shell_ssh_port'] = 22 This port is port 222 mapped from port 22 during run
:wq Save the configuration file and exit
Copy the code

Restart GitLab after modification

Docker restart Gitlab is required every time you modify the gitlab configurationCopy the code

4. Configure the email service

It is mainly used for mail notification service in daily use of GitLab

1. Modify the configuration file. You are advised to use the enterprise email address vim$HOME/gitlab/config/gitlab.rb
Copy the code
# Start email service
gitlab_rails['smtp_enable'] = true
Set the SMTP service according to your/company's email protocol
gitlab_rails['smtp_address'] = "smtp.exmail.qq.com"
Set the SMTP service port of the mailbox
gitlab_rails['smtp_port'] = 465
# Set the sender, set up a separate application mailbox
gitlab_rails['smtp_user_name'] = "[email protected]"
Set the email password
gitlab_rails['smtp_password'] = "password"

gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
# gitLab sender can be customized according to their own needs
gitlab_rails['gitlab_email_from'] = 'getlab' 
Copy the code

After making the configuration effective, we can use gitlab’s own tools to test it. Execute the following commands in sequence:

$docker exec -it gitlab bash - $gitlab- Rails console production Notify.test_email('[email protected]', 'Message Subject', 'Message Body').deliver_nowCopy the code

We installed GitLab

The port we exposed the Web service to when we ran the container earlier was 9000, through which we accessed our installed GitLab Web client

http://127.0.0.1:9000/
Copy the code

Open the above address in the address bar of the browser, and the visit will show as follows:

Enter the new root user password for the first time, and then enter the gitLab login page

Enter the password user name root and the password set by yourself to enter the main interface of GitLab

3. Administrator Settings

The administrator is mainly responsible for the daily maintenance of GitLab and needs to assign permissions to the corresponding team members. Gitlab has an administrator role and has many permissions, including user management, project management and permission management, etc. Click the “wrench” (Admin Area) icon on the navigation to enter the console of the management console:

1. Registration restrictions

Originally, I planned to let everyone register their GitLab accounts according to the format specifications written by me, but some people always did not comply with the specifications, and finally I had to remind them one by one, which greatly affected the work efficiency. Therefore, I decide to block the registration function of GitLab, and the administrator will assign accounts to new employees if they need GitLab accounts.

There are the following problems about the account:

  1. A lot of stranger accounts appear out of nowhere
  2. A lot of account registrations for team membersEmailandUserNameNone of them fit the code
  3. Inconvenient to manage,unsafe(Turnover is difficult to control)

Click on the workbench, and the left menu bar “Setting” –> “General” –> “Sign-up Restrictions”

Delete “sign-up Enabled” & “Require admin Approval for new sign-ups” and slide down “Save changes” to Save

2. User management

Click the workbench, left menu bar “Users”, according to the corresponding page steps, there is no description here

Mainly about Access:

  1. Can create group: whether to create a group
  2. Access level:
  • Regular: a common user can access groups and projects that have been assigned permissions or their own
  • Admin: administrator. The administrator can access all groups, projects, and usersgitlabThe maintenance of the
  1. External: An External person (rarely used)

If the user dimission, there are four kinds of gitLab user account processing:

  1. Deactivate this user: Deactivate this user and the user will be deactivated (only registered users will have this).
  2. Block this user: the user will be unable to log in, the user will not be able to access the Git repository, and all information will be retained (You are advised to use this method)
  3. Delete user: Delete the user and some information will be migrated to Ghost User.
  4. Delete user and contributions: Deletes users and related contributions

4. Start simple setup of GitLab(non-administrator)

1. Personal information Settings

After login, click Profile Settings in the upper right corner

After modifying the relevant information, scroll to the bottom of the page and click the “Update Profile Settings” button to Update it

2. Change the password

For security, users are forced to change their passwords after logging in for the first time. If they want to change their passwords later, they can go through the following process:

3. Preferences

You can configure gitlab according to your favorite style, including Navigation theme, Syntax highlighting theme, Behavior, Localization(language setting).

Navigation theme & Navigation theme :

Group management

In GitLab, the whole management approach is the group as the smallest unit, and namespaces are unique names used as user names, group names, or subgroup names. Groups are created for many reasons, granting access to multiple projects and multiple team members in fewer steps by organizing related projects under the same namespace and adding members to the top-level group. By creating a group and including the appropriate members, it is easier to mention all the team members in the question at the same time and merge the requests.

  • Assemble related items together
  • Grant members access to multiple projects at once
  • Groups can also be nested within subgroups.

1. Create a group

In the top menu, click ‘Groups’ and then’ Your Groups’, then click the green button ‘New Group’

Or, in the top menu, expand the Plus symbol and select New Group

Add the following information:

  • Private: Internal projects, groups and their projects can only be viewed by members
  • Internal: private can only be cloned and viewed by project members,
  • Public: Public access, which allows the owner to make the project visible

2. Delete groups & Edit

Click the Groups on the left and then click the group you want to modify/delete

3. Add group members

Click “Groups” on the left, and then “Members” of course.

Description of permission types:

  • Guest: An anonymous user who can create a project or write a message board

  • Reporter: Chen

    Create a project, write a message board, pull a project, download a project, create code snippets

  • Developer: Developer, create a project, write a comment, pull a project, download a project, create a code snippet, create a merge request, create a new branch, push an unprotected branch, remove an unprotected branch, create a tag, write a wiki

  • Master(changed to Maintainer): administrators

Create project, write a message board, project, download the program, to create code snippets, create merge request, to create a new branch, push unprotected branch, remove the unprotected branch, create labels, write a wiki, increase the team members, push the protected branch, remove the branch of the insured, edit item, add the deployment of key hook, configure project

  • Owner: the Owner

Create project, write a message board, project, download the program, to create code snippets, create merge request, to create a new branch, push unprotected branch, remove the unprotected branch, create labels, write a wiki, increase the team members, push the protected branch, remove protection branch, editing projects, add deployment key, configuration, hooks, switch public mode , move the project to another namespace, and delete the project

When an expiration date is added to a user, the user’s permissions will be revoked

4. Edit & delete group members

Click “Groups” on the left, and then “Members,” of course, to get to the list of users

5. Add items to the group

There is a lot of overlap in work. The codes developed every day are in the project of the group. Daily operations include the management of the Code warehouse, branch management, project user maintenance, Code Review, etc

Enter the details of the group, click “New Project” button, enter the add page, enter the basic information of the project to save.

New projects fall into three main categories: Blank Project (blank project), Create from Templte (community-based open source project template creation), and Import Project (import from existing projects, supporting many channels).

New project:

Create from Templte & Import project is something you can try, but I won’t go into it here

Six, Code Review

1. Objectives and principles

  • Improve code quality, identify potential defects early, and reduce the cost of fixing/fixing defects
  • Promote knowledge sharing within the team to improve the overall level of the team
  • The review process is also a process of thinking reconstruction for reviewers to help more people understand the system
  • Is a means of transferring knowledge, letting others who are not familiar with the code know the author’s intentions – and thoughts – so that it can be easily maintained in the future
  • Can be used to confirm that their design and implementation is a clear and simple one
  • Encourage learning from each other’s strengths and strengths
  • Finish quickly and efficientlyCode Review

2. Processes and rules

Git Flow + Pull Request (PR) to do Code Review.

Pull Request (PR)

  • Often when we receive a new requirement, we need to pull out a new local branch through the trunk branch for development
  • Submit only when the task is completePR
  • It is strictly prohibited to aPRThere are multiple tasks, unless they are closely related
  • Specify the corresponding when submitting the PRReviewThe personnel of
  • codeReviewBy merging the trunk,Delete the Fear branch

After initiating the Pull Request, send the link of the Pull Request via Email to the code reviewer to notify the reviewer to review it in time. (For BUG fixing classes, merge or reject must be completed on the same day; for functional classes, major adjustments need to be made to Review meetings, time and meeting personnel must be specified in the email)

Submit the PR when the task is complete

After the PR is submitted, the corresponding staff will receive email reminders to process the PR Review

At this point, if the code is found not compliant, there is a bug can move the mouse to the current line, for evaluation

If there is no problem, merge will be called back for processing. If there is no problem, merge will be used. This process will loop until the code is satisfied at 😊

Vii. Permission Description table in GITLab

Note: Master in older versions is equivalent to Maintainer in new versions

Gitlab-ctl Common command

Gitlab-ctl restart nginx # restart a single service gitlab-ctl start# restart a single service gitlab-ctl stop # restart a single service Gitlab-ctl reconfigure gitlab-ctl show-config gitlab-ctl uninstall Gitlab-ctl cleanSecan # Delete all data, Gitlab-ctl tail <service name> check the service log gitlab-ctl tail nginx #Copy the code

Thank you for your patience to read, give you a thumb up 👍 👍 👍, creation is not easy, if you have any help to you, ❤ ️ ❤ ️ please use your hands to get rich a praise oh ❤ ️ ❤ ️, thank 🙏 🙏 🙏 welcome reproduced at the same time, remember to indicate the source 💐