Rapid Deployment of Gitlab
Introduction to Gitlab
GitLab uses Ruby on Rails, an open source version management system, to implement a self-hosted Git project repository, which can access public or private projects through a web interface. It has functions similar to Github, able to browse source code, manage defects and comments. At the same time, Gitlab integrates a series of CI functions. I have to say that Gitlab is very high in enterprise usage.
Kato highly recommends that users use the Git code repository to manage code, so as to obtain a better source code management and automated CI experience. Without further ado, we will complete the complete deployment of the Gitlab service in Kato in 10 minutes.
Ready to Work
- Prepare a usable domain name (if you can prepare it), such as git.example.com
- Prepare the certificate corresponding to the domain name (if you can prepare it)
- Kato platform has been installed, please refer to the document platform installation
- The Kato platform is in an environment capable of connecting to the Internet.
In this tutorial, we will deploy Gitlab based on the completed Docker image installation method; the running effect on Kato after deployment is as follows:
Deploying an open source project in Kato is the fastest and easiest way based on Docker mirroring. Especially some mirrors made according to cloud native recommendations have excellent running compatibility and experience in Kato.
The Gitlab components we deployed today include Postgresql components, Redis components and Gitlab-Server components. Their network dependencies are as you can see in the above figure. We deploy them in order from small to top according to the dependencies.
First create the application
Gitlab and add components from the application management page:
We create components based on the DockerRun command, refer to the document Method of component creation,
The Gitlab image deployed this time is provided by the community and is currently the most widely used image. Source code reference docker-gitlab
Deploy Postgresql Components
Add components, based on the following DockerRun command, Kato will obtain the image name and persistent storage directory from the following command.
docker run --name gitlab-postgresql -d \ --volume /srv/docker/gitlab/postgresql:/var/lib/postgresql \ sameersbn/postgresql:10
After the component build source is identified, the usual process is to create and start it directly, but we also need to set the running type of the component to stateful component, and also need to set the connection information. Therefore, we need to choose to create or not start. The way is as follows:
We emphasize, cancel the radio button in the red box in the picture, this step is very important
After canceling, click Create to jump directly to the component management page. We do the following steps:
1. Change port alias and set connection information
Enter the component port management page, the service has added port 5432 by default, change the port protocol to
TCP, open the internal service button of the port, and click the port alias information behind
Use alias to set the port alias in the pop-up window As
DB. After confirmation, two connection information of
DB_POST will be automatically generated, and the final effect is as shown below.
In the component
dependency page, you can query the connection information, click on the
component connection information–>
Add variable, continue to add the following connection information:
| Variable name | Value | Description | | ———— | ——————- | —————- ———- | | DB_EXTENSION | pg_trgm | | | DB_NAME | gitlabhq_production | Database name | | DB_PASS | password | Password, you can define the value freely | | DB_USER | gitlab | Username to connect to the database |
Adding these connection information has two effects:
- Postgresql will read these variables and automatically create users and databases
- The Postgresql service will be injected into the Gitlab-Server environment after being relied on by Gitlab-Server, and Gitlab-Server will connect to the database based on these variable information.
2. Change component deployment type
Since Postgresql belongs to the database category, we need to set the component deployment type to a stateful component, enter the component
other settings page, and switch the
component deployment type to a stateful component in the
basic information information.
3. Create components
After the setting is complete, click Build to start building and start the component. At this time, we can start the deployment of the next component.
Deploy Redis Components
The process of deploying Redis components is the same as that of Postgresql. The only difference is that there is no need to add too much connection information.
- Add components based on the following DockerRun command
docker run --name gitlab-redis -d \ --volume /srv/docker/gitlab/redis:/var/lib/redis \ sameersbn/redis:4.0.9-1
- After completing the check, set
Create not startand enter the component management page
- Set the 6379 port alias to
REDIS, and enable the port internal service; after completion, you can view the two connection information variables
REDIS_PORTon the component dependency page, which will be injected into the Gitlab component.
- Change the deployment type of the component to
- Create the component, now you can move on to the next step.
Deploy Gitlab-Server Components
- Use the following DockerRun command to create a component, and select
Create not start.
docker run --name gitlab -d \ --publish 10022:22 --publish 10080:80 \ -e GITLAB_PORT=80 \ -e GITLAB_HOST=git.example.com \ -e GITLAB_SSH_PORT=10022 \ -e GITLAB_SECRETS_DB_KEY_BASE=long-and-random-alpha-numeric-string \ -e GITLAB_SECRETS_SECRET_KEY_BASE=long-and-random-alpha-numeric-string \ -e GITLAB_SECRETS_OTP_KEY_BASE=long-and-random-alpha-numeric-string \ --volume /srv/docker/gitlab/gitlab:/home/git/data \ sameersbn/gitlab:11.8.2
What needs to be explained here is some of the variable information:
| Variable | Value | Description | | ————— | ————— | —————– ————————————————– ————- | | GITLAB_PORT | 80 | | | GITLAB_HOST | git.example.com | The previously prepared domain name, if you do not prepare to set the default domain name assigned by Kato later (it can be changed after creation) | | GITLAB_SSH_PORT | 20222 | Gitlab server port 22 is the port assigned after opening the external network access (can be changed after creation) | | GITLAB_SSH_HOST | 10.10.10.10 | Gitlab server 22 port after opening the IP for external network access (can be changed after creation) |
- After creating the component, rely on the two components established above, directly enter the topological diagram editing mode, and connect Gitlab Server with redis and postgresql components. Refer to the document [Establish component dependencies](/docs/user-manual/component- connection/regist_and_discover/)
- Build the component and wait for the component to start.
Note that the first startup process of Gitlab components is relatively slow, wait for the components to start up.
Configure Gateway Access Policy
The gitlab component provides HTTP access on port 80 and SSH code access on port 22, adding access policies to them respectively.
80 port, configure the HTTP access policy, use the pre-prepared domain name such as (git.example.com), which must be consistent with the GITLAB_HOST configuration. The certificate corresponding to the bound domain name.
After the addition is complete, enter the access strategy list, select the strategy just added, enter the parameter configuration, and adjust the
upload limitto 10000 Mb, basically there is no limit.
Add a TCP policy to port 22. The generated IP and port need to be consistent with the two variables GITLAB_SSH_HOST and GITLAB_SSH_PORT.
At this point, the Gitlab component is deployed and you can directly access the component. The password of the root account will be set the first time you enter.
After the installation is complete, visit the page 502 back to Gitlab
At this time, Gitlab is in the process of initialization and startup, and some internal processes have not been started yet. At this time, you only need to wait for the component startup to complete. The first startup is about 5-10 minutes.
The above process is still a bit complicated, can it be deployed directly with one click.
Of course it is possible. We have shared the Gitlab components to the Kato public application market and provide Kato users with one-click installation. Search the application market for
Gitlab and select the version
v11.8.2, and install it directly after synchronization; Yes, after installation, you need to reconfigure Gitlab’s
GITLAB_SSH_HOST and other information according to your gateway access strategy.
There is no other Q&A at the moment. If you have any questions, please leave a message at our Slack Channel.