背景介绍
作为一个老派程序员,偶尔能接到一些私单,不少私单涉及到代码安全问题,就不是很适合用Gitlab、Gitee 等在线代码托管服务了,于是在我的开发服务器上自己搭建了一个 git 服务,可选的git 服务有很多,如::Gitea、Gogs、Gitlab 等,由于公司环境基本上用 Gitlab,且Gitlab 功能足够强大,所以便选择了 Gitlab 作为服务端,Gitlab 在国内成立了极狐公司(https://gitlab.cn/)专门运营国内的 Gitlab,在部署的时候也就选择了 Gitlab 的极狐版本,部署的完整 docker-compose.yml 如下:
services:
gitlab:
image: 'registry.gitlab.cn/omnibus/gitlab-jh:latest'
# image: 'registry.gitlab.cn/omnibus/gitlab-jh:16.11.3'
#image: 'registry.gitlab.cn/omnibus/gitlab-jh:16.7.7'
restart: always
container_name: gitlab
hostname: 'git.work.zhuzhilong.com'
environment:
GITLAB_OMNIBUS_CONFIG: |
external_url 'http://git.work.zhuzhilong.com'
# Add any other gitlab.rb configuration here, each on its own line
alertmanager['enable']=false
networks:
- net-zzl
ports:
- '8007:80'
- '2223:22'
volumes:
- './config:/etc/gitlab'
- './logs:/var/log/gitlab'
- './data:/var/opt/gitlab'
- ../hosts:/etc/hosts
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
shm_size: '256m'
networks:
net-zzl:
name: bridge_zzl
external: true
在开发过程中,涉及多成员协作,而 Gitlab 自带的邮件服务还是很有必要的,所以本次我们就将我们的 gitlab 服务搭上邮件的快车。
配置过程如下:
1、进入 docker 容器
docker exec -it gitlab /bin/bash
2、编辑 /etc/gitlab/gitlab.rb 文件
修改涉及邮件发送相关的服务,主要配置信息如下:
### GitLab email server settings
###! Docs: https://docs.gitlab.com/omnibus/settings/smtp.html
###! **Use smtp instead of sendmail/postfix.**
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.feishu.cn"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "sender@zhuzhilong.com"
gitlab_rails['smtp_password'] = "xxxxxxxx"
gitlab_rails['smtp_domain'] = "mail.feishu.cn"
gitlab_rails['smtp_authentication'] = "login"
# gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
gitlab_rails['smtp_pool'] = false
###! **Can be: 'none', 'peer', 'client_once', 'fail_if_no_peer_cert'**
###! Docs: http://api.rubyonrails.org/classes/ActionMailer/Base.html
# gitlab_rails['smtp_openssl_verify_mode'] = 'none'
# gitlab_rails['smtp_ca_path'] = "/etc/ssl/certs"
# gitlab_rails['smtp_ca_file'] = "/etc/ssl/certs/ca-certificates.crt"
### Email Settings
gitlab_rails['gitlab_email_enabled'] = true
##! If your SMTP server does not like the default 'From: gitlab@gitlab.example.com'
##! can change the 'From' with this setting.
gitlab_rails['gitlab_email_from'] = 'xxxx@zhuzhilong.com'
gitlab_rails['gitlab_email_display_name'] = '朱治龙git'
gitlab_rails['gitlab_email_reply_to'] = 'reply@zhuzhilong.com'
# gitlab_rails['gitlab_email_subject_suffix'] = ''
# gitlab_rails['gitlab_email_smime_enabled'] = false
# gitlab_rails['gitlab_email_smime_key_file'] = '/etc/gitlab/ssl/gitlab_smime.key'
# gitlab_rails['gitlab_email_smime_cert_file'] = '/etc/gitlab/ssl/gitlab_smime.crt'
# gitlab_rails['gitlab_email_smime_ca_certs_file'] = '/etc/gitlab/ssl/gitlab_smime_cas.crt'
3、使配置生效并重启服务
gitlab-ctl reconfigure && gitlab-ctl restart
4、验证邮件发送服务
可在个人资料 -> 电子邮件 中添加新的邮件地址:
添加后,对应的邮箱会收到如下验证邮件即表示配置成功了:
评论 (0)