DevOps GitLab CICD 实践1——GitLab 部署

释放双眼,带上耳机,听听看~!

配置目标

  • 邮件提示
  • GitHub第三方授权登陆
  • GitLab Runner
  • Docker私服注册

官方介绍

目前微服务盛行环境下,服务部署优先考虑Docker方式,便于迁移和弹性伸缩

官方镜像介绍 GitLab Docker images

GitLab Docker images

Both GitLab CE and EE are in Docker Hub:

  • GitLab CE Docker image
  • GitLab EE Docker image

The GitLab Docker images are monolithic images of GitLab running all the necessary services on a single container.

In the following examples we are using the image of GitLab CE. To use GitLab EE instead of GitLab CE, replace the image name to gitlab/gitlab-ee:latest.

If you want to use the latest RC image, use gitlab/gitlab-ce:rc or gitlab/gitlab-ee:rc for GitLab CE and GitLab EE respectively.

The GitLab Docker images can be run in multiple ways:

  • Run the image in Docker Engine
  • Install GitLab into a cluster
  • Install GitLab using docker-compose

docker-compose 脚本

此处选择社区版(CE)安装,同时为了便于参数配置,使用docker-compose方式编写脚本文件

Install GitLab using docker-compose

With Docker compose you can easily configure, install, and upgrade your Docker-based GitLab installation.

Install Docker Compose

Create a docker-compose.yml file (or download an example):


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
1web:
2   image: 'gitlab/gitlab-ce:latest'
3   restart: always
4   hostname: 'gitlab.example.com'
5   environment:
6     GITLAB_OMNIBUS_CONFIG: |
7       external_url 'https://gitlab.example.com'
8       # Add any other gitlab.rb configuration here, each on its own line
9   ports:
10     - '80:80'
11     - '443:443'
12     - '22:22'
13   volumes:
14     - '/srv/gitlab/config:/etc/gitlab'
15     - '/srv/gitlab/logs:/var/log/gitlab'
16     - '/srv/gitlab/data:/var/opt/gitlab'
17复制代码
18

Make sure you are in the same directory as docker-compose.yml and run docker-compose up -d to start GitLab

Read “Pre-configure Docker container” to see how the GITLAB_OMNIBUS_CONFIG variable works.

Below is another docker-compose.yml example with GitLab running on a custom HTTP and SSH port. Notice how the GITLAB_OMNIBUS_CONFIG variables match the ports section:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
1web:
2  image: 'gitlab/gitlab-ce:latest'
3  restart: always
4  hostname: 'gitlab.example.com'
5  environment:
6    GITLAB_OMNIBUS_CONFIG: |
7      external_url 'http://gitlab.example.com:9090'
8      gitlab_rails['gitlab_shell_ssh_port'] = 2224
9  ports:
10    - '9090:9090'
11    - '2224:22'
12  volumes:
13    - '/srv/gitlab/config:/etc/gitlab'
14    - '/srv/gitlab/logs:/var/log/gitlab'
15    - '/srv/gitlab/data:/var/opt/gitlab'
16复制代码
17

This is the same as using –publish 9090:9090 –publish 2224:22.

官方提示说明Docker CE版基于Omnibus版本,故环境配置也可参考相关文档

Omnibus文档目录

Installation and Configuration using omnibus package

Note: This section describes the commonly used configuration settings. Check configuration section of the documentation for complete configuration settings.

  • Installing GitLab

  • Manually downloading and installing a GitLab package

  • Setting up a domain name/URL for the GitLab Instance so that it can be accessed easily

  • Enabling HTTPS

  • Enabling notification EMails

  • Enabling replying via email

  • Installing and configuring postfix

  • Enabling container registry on GitLab

  • You will require SSL certificates for the domain used for container registry

  • Enabling GitLab Pages

  • If you want HTTPS enabled, you will have to get wildcard certificates

  • Enabling Elasticsearch

  • GitLab Mattermost Set up the Mattermost messaging app that ships with Omnibus GitLab package.

  • GitLab Prometheus Set up the Prometheus monitoring included in the Omnibus GitLab package.

  • GitLab High Availability Roles

结合配置目标编写yaml文件

注意:

  • 此处邮件使用163邮箱(官方没有提供163邮箱支持案例)
  • Docker私服公钥执行从私服上获取
  • 由于特殊原因,目标配置未启动SSL安全连接,但GitLab可以通过简单配置支持SSL并自动更新证书

配置文档

Let’s Encrypt Integration

Primary GitLab Instance

Note: Introduced in GitLab version 10.5 and disabled by default. Enabled by default in GitLab version 10.7 and later if external_url is set with the httpsprotocol and no certificates are configured.

Note: In order for Let’s Encrypt verification to work correctly, ports 80 and 443 will need to be accessible to the Let’s Encrypt servers that run the validation. Also note that the validation currently does not work with non-standard ports.

Caution Administrators installing or upgrading to GitLab version 10.7 or later and do not plan on using Let’s Encrypt should set the following in /etc/gitlab/gitlab.rb to disable:


1
2
3
1letsencrypt['enable'] = false
2复制代码
3

Add the following entries to /etc/gitlab/gitlab.rb to enable Let’s Encrypt support for the primary domain:


1
2
3
4
5
1letsencrypt['enable'] = true                      # GitLab 10.5 and 10.6 require this option
2external_url "https://gitlab.example.com"      # Must use https protocol
3letsencrypt['contact_emails'] = ['foo@email.com'] # Optional
4复制代码
5

生成163邮箱授权密码

生成GitHub授权秘钥

最终配置


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
1version: '3.1'
2
3services:
4
5  gitlab:
6    environment:
7      GITLAB_OMNIBUS_CONFIG: |
8        external_url '外部访问地址'
9        gitlab_rails['gitlab_shell_ssh_port'] = 22
10        registry_external_url 'Docker私服地址'
11        registry_nginx['ssl_certificate'] = "Docker 私服CA证书 crt文件"
12        registry_nginx['ssl_certificate_key'] = "Docker 私服公钥 pem文件"
13        gitlab_rails['smtp_enable'] = true
14        gitlab_rails['smtp_address'] = "smtp.163.com"
15        gitlab_rails['smtp_port'] = 465
16        gitlab_rails['smtp_user_name'] = "邮件发送者名称"
17        gitlab_rails['gitlab_email_from'] = '邮件发送地址'
18        gitlab_rails['smtp_password'] = "授权密码"
19        gitlab_rails['smtp_domain'] = "163.com"
20        gitlab_rails['smtp_authentication'] = "login"
21        gitlab_rails['smtp_enable_starttls_auto'] = true
22        gitlab_rails['smtp_tls'] = true
23        gitlab_rails['omniauth_enabled'] = true
24        gitlab_rails['omniauth_allow_single_sign_on'] = true
25        gitlab_rails['omniauth_block_auto_created_users'] = true
26        gitlab_rails['omniauth_providers'] = [
27          {
28            "name" => "github",
29            "app_id" => "Client ID",
30            "app_secret" => "Client Secret",
31            "url" => "https://github.com/",
32            "args" => { "scope" => "user:email" }
33          }
34        ]
35    image: gitlab/gitlab-ce:latest
36    hostname: 域名
37    restart: always
38    networks:
39    - devops-service-bridge
40    ports:
41    - '443:443'
42    - '80:8099'
43    - '22:22'
44    volumes:
45    - ./srv/gitlab/config:/etc/gitlab
46    - ./srv/gitlab/logs:/var/log/gitlab
47    - ./srv/gitlab/data:/var/opt/gitlab
48    - /etc/docker/certs.d:/etc/docker/certs.d
49
50
51networks:
52  devops-service-bridge:
53    driver: bridge
54复制代码
55

给TA打赏
共{{data.count}}人
人已打赏
安全运维

故障复盘的简洁框架-黄金三问

2021-9-30 19:18:23

安全运维

OpenSSH-8.7p1离线升级修复安全漏洞

2021-10-23 10:13:25

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索