docker_gitlab搭建
这里使用 docker-compose.yml 的方式部署
在虚拟机(ip:192.168.74.128)上部署的
之前有过一篇也是gitlab搭建 在CentOS 7上安装GitLab
部署gitlab
把gitlab官方的镜像拉下来
1
2
3
4
5
6
7
8wilker@ubuntu:~/Desktop/a_gitlab$ docker search gitlab # 搜一下 gitlab,基本第一个就是官方的
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
gitlab/gitlab-ce GitLab Community Edition docker image base... 1234 [OK]
sameersbn/gitlab Dockerized gitlab web server 910 [OK]
wilker@ubuntu:~/Desktop/a_gitlab$ docker pull gitlab/gitlab-ce # 拉下来
Using default tag: latest
latest: Pulling from gitlab/gitlab-ce在宿主中新建几个目录,然 gitlab 容器 挂载,存放 数据 及 配置
1
2
3
4wilker@ubuntu:~/Desktop/a_gitlab$ sudo mkdir /opt/gitlab
wilker@ubuntu:~/Desktop/a_gitlab$ sudo mkdir /opt/gitlab/config
wilker@ubuntu:~/Desktop/a_gitlab$ sudo mkdir /opt/gitlab/log
wilker@ubuntu:~/Desktop/a_gitlab$ sudo mkdir /opt/gitlab/data编写一个 docker-compose.yml 文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18version: '2'
services:
gitlab:
image: 'gitlab/gitlab-ce:latest'
container_name: my_gitlab
restart: always
hostname: 'gitlab.example.com'
environment:
GITLAB_OMNIBUS_CONFIG: |
external_url 'http://localhost'
# Add any other gitlab.rb configuration here, each on its own line
ports:
- '80:80'
- '22:22'
volumes:
- '/opt/gitlab/config:/etc/gitlab'
- '/opt/gitlab/logs:/var/log/gitlab'
- '/opt/gitlab/data:/var/opt/gitlab'部署
1
2
3
4
5
6
7
8wilker@ubuntu:~/Desktop/a_gitlab$ docker-compose up -d # 部署
Creating my_gitlab
wilker@ubuntu:~/Desktop/a_gitlab$ docker-compose ps # 查看一下
Name Command State Ports
-------------------------------------------------------------------------------------
my_gitlab /assets/wrapper Up 0.0.0.0:22->22/tcp, 443/tcp, 0.0.0.0:80->80/tcp然后要等上7、8秒左右,请求浏览器
http://localhost
才有反应,默认页面是设置 root 用户密码的界面设置好直接用来登录
然后上传 ssh 公钥
新建一个工程,在 物理机 上通过 ssh pull 下来。
如果添加了dns域名映射,则看 添加自定义域名 , 没有则看下一步
复制下来的 git 连接需要修改一下
1
2
3git@localhost:root/test_proj.git
修改为,改成虚拟机的ip
git@192.168.74.128:root/test_proj.git1
2
3
4
5git clone git@192.168.74.128:root/test_proj.git # 然后就clone下来了
Cloning into 'test_proj'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.
ok, done
添加自定义域名
做个内网的dns服务器,参考 ubuntu_内网dns服务器搭建.md , 添加一个域名 wilker.com 解析到 ip:192.168.74.128
修改配置文件 (宿主里) /opt/gitlab/config/gitlab.rb
1
2
3
4wilker@ubuntu:~/Desktop/a_gitlab$ sudo vi /opt/gitlab/config/gitlab.rb
取消这行注释并制定域名
external_url 'http://wilker.com'重启 gitlab
1
wilker@ubuntu:~/Desktop/a_gitlab$ docker restart my_gitlab
就可以复制直接 clone 下来了
1
2
3
4
5git clone git@wilker.com:root/test_proj.git
Cloning into 'test_proj'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.
邮件通知
以 qq 邮箱为例,其他差不多,其实配置差不多和 redmine 中的 邮件通知配置 差不多,参照 docker_redmine搭建.md
- 进入容器,修改配置文件 : /etc/gitlab/gitlab.rb
1 | wilker@ubuntu:~$ docker exec -it my_gitlab bash |
测试发送
1
2
3
4
5
6
7
8
9
10root@gitlab:/# gitlab-rails console
Notify.test_email('553972977@qq.com', 'Message Subject', 'Message Body').deliver_now #测试发送邮件
发送提示
test_email: processed outbound mail in 305.8ms
Sent mail to 553972977@qq.com (854.5ms)
Date: Wed, 19 Jul 2017 03:36:34 +0000
From: GitLab-Robot <364105996@qq.com>
Reply-To: GitLab-Robot <364105996@qq.com>
To: 553972977@qq.com如果成功发送,会有以下提示
1
2发送成功提示
=> #<Mail::Message:70141395443160, Multipart: false, Headers: <Date: Wed, 19 Jul 2017 03:36:34 +0000>, <From: GitLab-Robot <364105996@qq.com>>, <Reply-To: GitLab-Robot <364105996@qq.com>>, <To: 553972977@qq.com>, <Message-ID: <596ed3c25fb6_19523fcb189c711035918@gitlab.example.com.mail>>, <Subject: Message Subject>, <Mime-Version此时也有qq弹窗提示
踩坑记录
如果报错:
Net::ReadTimeout
,可能是下面几个没有配置1
2gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_ssl'] = true
关闭 avatar 头像请求
- 默认开启了 avatar,会去请求 https://www.gravatar.com/ 造成打开页面速度极慢,需要关掉,在页面 http://ip:port/admin/application_settings 中, **Account and Limit Settings -> Gravatar enabled ** 取消勾选,然后 点击 Save 保存设置即可
部署gitlab - 使用外部 mysql、redis
- todo: