GitLab安装文档
GitLab 是一个用于仓库管理系统的开源项目,使用Git作为代码管理工具,并在此基础上搭建起来的web服务。 GitLab与GitHub的功能相似,通常企业使用GitLab在局域网搭建自己的Git代码管理仓库。
1 Docker下安装Gitlab
拉取gitlab、redis、postgresql,gitlab依赖redis和postgresql。
docker pull sameersbn/redis
docker pull sameersbn/postgresql
docker pull gitlab/gitlab‐ce:latest
创建postgresql、redis容器:
docker run ‐‐name postgresql ‐d ‐‐privileged=true ‐e 'DB_NAME=gitlabhq_production' ‐e 'DB_USER=gitlab' ‐e 'DB_PASS=password' ‐e 'DB_EXTENSION=pg_trgm' ‐v /home/root/opt/postgresql/data:/var/lib/postgresql sameersbn/postgresql
docker run ‐‐name redis ‐d ‐‐privileged=true ‐v /home/root/opt/redis/data:/var/lib/redis sameersbn/redis
创建gitlab容器:
docker run ‐‐name gitlab ‐d ‐‐link postgresql:postgresql ‐‐link redis:redisio ‐‐hostname 192.168.101.64 ‐p 10022:22 ‐p 8899:80 ‐e 'GITLAB_PORT=8899' ‐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' ‐e 'GITLAB_HOST=192.168.101.64' ‐e 'SMTP_AUTHENTICATION=login' ‐v /home/root/opt/gitlab/data:/home/git/data docker.io/gitlab/gitlab‐ce
浏览器访问:http://192.168.101.64:8899
初次访问需要等待一段时间。
2 添加公钥
Jenkins远程访问GitLab获取源代码,这里需要在GitLab配置公钥。
1、进入jenkins容器,生成公钥:
[root@localhost conf]# docker exec ‐it jenkins /bin/bash Error response from daemon: Container
10f316cedd5be97b499db231054a8505ed3b68c36d72cf0e26bbe253cb8a9615 is not running [root@localhost conf]# docker start jenkins jenkins
[root@localhost conf]# docker exec ‐it jenkins /bin/bash
bash‐4.4# ssh‐keygen ‐t rsa ‐C "mrt_0607@126.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:6c5kODkGUhikicIZzxrOU5+ZvZeKWnvsUkBEuxAW69c mrt_0607@126.com
The key's randomart image is:
+‐‐‐[RSA 2048]‐‐‐‐+
| oo++o |
|oo*oo.. |
|=+.*o. |
|+ =.o.B . |
| =...B.ES |
| .... =. . |
| .O.+o |
| .ooXo |
| ..o+oo |
+‐‐‐‐[SHA256]‐‐‐‐‐+
bash‐4.4# cat ~/.ssh/id_rsa.pub
ssh‐rsa
AAAAB3NzaC1yc2EAAAADAQABAAABAQDP9E1GFcc7QLoIAaujl3trJpiQZYRd4r0ZHvbOZdDNejayRyZodDWu8W1emHaIdn3PjqzNjkatkIayPL5/ccWmJbZWLNSGusJLaJW+vRxUBSNsG5QBrw7rogJqxhI878DCch7JpfFBe4pVNCQPlW1Ym+jquTn3vVcOAJZw3UUodRnijYQ0d+AotL5Gmj/7lhHi6L1Dssr8LbyuJFLmZPXzCMpFL68JjcppqJbunWEp06sO3GEyYndk1NDuqX0v8XJ0AXLTfbz3mT0u4irDKyI91mc6loDdYFpAYUSsstwXzVIRcjkZyRQNT0oAXMgROSox+kR0KswoU5aJKFDOipbx mrt_0607@126.com
bash‐4.4#
2、进入GitLab配置公钥:
3 配置webhook
GitLab中使用webhook向jenkins通知,当有代码push后将通知jenkins进行构建。
1、在Jenkins中找到通知地址
2、进入Jenkins设置允许匿名访问jenkins,这样GitLab才要成功通知Jenkins
3、使用管理员帐号admin@example.com登录Gitlab,密码就是你gitlab搭建好之后第一次输入的密码,设置允许 请求本地网络服务
4 设置钩子地址,即jenkins中的项目地址
钩子添加成功