Gitlab CE 简单使用说明

Docker部署

参考:
https://docs.gitlab.com/ee/install/docker.html

部署脚本:

#!/bin/bash
#
set -u

mkdir -p /srv/gitlab/{config,logs,data}  ## 在宿主机上创建数据、日志和配置目录

docker run --detach \
--hostname gitlab \
--publish 80:80 --publish 2224:22 \
--name gitlab \
--restart always \
--volume /srv/gitlab/config:/etc/gitlab \
--volume /srv/gitlab/logs:/var/log/gitlab \
--volume /srv/gitlab/data:/var/opt/gitlab \
gitlab/gitlab-ce:13.12.4-ce.0

基本配置

# docker exec -it gitlab /bin/bash
# docker exec -it gitlab vim /etc/gitlab/gitlab.rb
external_url 'http://<your_domain_or_ip>'
gitlab_rails['gitlab_shell_ssh_port'] = 2224

配置邮箱

## 私有企业邮箱
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "mail.test.com"
gitlab_rails['smtp_port'] = 25
gitlab_rails['smtp_user_name'] = "varden@test.com"
gitlab_rails['smtp_password'] = "123456"
gitlab_rails['smtp_domain'] = "test.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = false
gitlab_rails['smtp_openssl_verify_mode'] = "peer"
gitlab_rails['gitlab_email_from'] = "varden@test.com"
user['git_user_email'] = "varden@test.com"

## 163企业邮箱
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtphm.qiye.163.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "varden@test.com"
gitlab_rails['smtp_password'] = "123456"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
gitlab_rails['gitlab_email_from'] = 'varden@test.com'
gitlab_rails['smtp_domain'] = "test.com"
user['git_user_email'] = "varden@test.com"

## 163个人邮箱
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.ym.163.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "xxxx@xx.com"
gitlab_rails['smtp_password'] = "123456"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
gitlab_rails['gitlab_email_from'] = 'xxxx@xx.com'
gitlab_rails['smtp_domain'] = "smtp.ym.163.com"

## QQ邮箱
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.exmail.qq.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "xxxx@xx.com"
gitlab_rails['smtp_password'] = "123456"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
gitlab_rails['gitlab_email_from'] = 'xxxx@xx.com'
gitlab_rails['smtp_domain'] = "exmail.qq.com"

权限问题解决办法

# docker exec -it gitlab update-permissions
# docker restart gitlab

访问

http://<your_domain_or_ip>

与Jenkins集成相关配置

访问权限:这里建议公司内部的代码仓库都设置为Internal。

使用GitLab Webhook与Jenkins实现持续交付:

  • 第一种方法是为Jenkins专门制作Deploy Keys;
  • 第二种方法是在GitLab上增加一个Jenkins账户,用户Jenkins拉取代码,两种方法都可以。

这里采用第二种方法,账户为:jenkins,密码为:jenkins。

在Jenkins中配置Webhook:

Repository URL: http://<your_gitlab_server_ip>/jenkins/test.git
Credentials: jenkins/jenkins

配置时区

gitlab_rails['time_zone'] = 'Asia/Shanghai'
# gitlab-ctl reconfigure
# gitlab-ctl restart

其他部署方式

Docker Compose部署

模板示例:

web:
  image: 'gitlab/gitlab-ee:latest'
  restart: always
  hostname: 'gitlab.example.com'
  environment:
    GITLAB_OMNIBUS_CONFIG: |
      external_url 'http://gitlab.example.com:8929'
      gitlab_rails['gitlab_shell_ssh_port'] = 2224
  ports:
    - '8929:8929'
    - '2224:22'
  volumes:
    - '$GITLAB_HOME/config:/etc/gitlab'
    - '$GITLAB_HOME/logs:/var/log/gitlab'
    - '$GITLAB_HOME/data:/var/opt/gitlab'

Docker Swarm部署

模板示例:

version: "3.6"
services:
  gitlab:
    image: gitlab/gitlab-ee:latest
    ports:
      - "22:22"
      - "80:80"
      - "443:443"
    volumes:
      - $GITLAB_HOME/data:/var/opt/gitlab
      - $GITLAB_HOME/logs:/var/log/gitlab
      - $GITLAB_HOME/config:/etc/gitlab
    environment:
      GITLAB_OMNIBUS_CONFIG: "from_file('/omnibus_config.rb')"
    configs:
      - source: gitlab
        target: /omnibus_config.rb
    secrets:
      - gitlab_root_password
  gitlab-runner:
    image: gitlab/gitlab-runner:alpine
    deploy:
      mode: replicated
      replicas: 4
configs:
  gitlab:
    file: ./gitlab.rb
secrets:
  gitlab_root_password:
    file: ./root_password.txt

gitlab.rb文件内容:

external_url 'https://my.domain.com/'
gitlab_rails['initial_root_password'] = File.read('/run/secrets/gitlab_root_password')

root_password.txt文件内容:

MySuperSecretAndSecurePass0rd!

部署命令:

docker stack deploy --compose-file docker-compose.yml mystack
上一篇:如何使用Python SMTP发送邮件


下一篇:Python实现发送邮件(实现单发/群发邮件验证码)