使用docker在本地部署一個Gitlab+Jenkins
GitLab
localhost:helloworld jackzhang$ docker search gitlab
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
gitlab/gitlab-ce GitLab Community Edition docker image based … 2989 [OK]
直接pull下來
localhost:helloworld jackzhang$ docker search gitlab/gitlab-ce
Pull下來之后如何運行呢闻牡?去docker hub上查一下文檔妄田,當然也可以度娘,安裝文檔一大堆
https://docs.gitlab.com/omnibus/docker/
寫個簡單的腳本驮捍,這樣就不用每次手動敲命令了
#!/bin/bash
export GITLAB_HOME=~/GITLAB_HOME/
echo $GITLAB_HOME
docker run -d --publish 443:443 --publish 80:80 --publish 22:22 \
--name gitlab \
--restart always \
--volume $GITLAB_HOME/config:/etc/gitlab:Z \
--volume $GITLAB_HOME/logs:/var/log/gitlab:Z \
--volume $GITLAB_HOME/data:/var/opt/gitlab:Z \
gitlab/gitlab-ce:latest
此處有坑疟呐,對于路徑的長度好像是有一個什么限制,原來指定volume的時候宿主機(Mac本地地址)路徑有點長东且,在啟動后循環(huán)輸出:
gitaly loop on error: socket could not be created in /var/opt/gitlab/gitaly/internal_sockets
去Google了一下启具,大概是因為路徑長度的原因,于是改回了一個較短的路徑珊泳,能夠正常啟動鲁冯。Google到的鏈接:https://gitlab.com/gitlab-org/gitaly/-/issues/2311
現(xiàn)在GitLab已經(jīng)起來了,需要改一些配置色查,可以通過gitlab運行的log中看到需要修改哪里的配置
localhost:gitlab jackzhang$ docker logs gitlab | more
Thank you for using GitLab Docker Image!
Current version: gitlab-ce=13.2.1-ce.0
Configure GitLab for your system by editing /etc/gitlab/gitlab.rb file
And restart this container to reload settings.
To do it use docker exec:
docker exec -it gitlab vim /etc/gitlab/gitlab.rb
docker restart gitlab
For a comprehensive list of configuration options please see the Omnibus GitLab readme
https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md
If this container fails to start due to permission problems try to fix it by executing:
docker exec -it gitlab update-permissions
cat: /var/opt/gitlab/gitlab-rails/VERSION: No such file or directory
docker restart gitlab
Cleaning stale PIDs & sockets
Installing gitlab.rb config...
Generating ssh_host_rsa_key...
Generating public/private rsa key pair.
按照上面的說明薯演,運行docker命令
docker exec -it gitlab vim /etc/gitlab/gitlab.rb
主要是需要修改訪問Gitlab的地址,http的和ssh的秧了,在配置文件中增加以下兩行即可
external_url 'http://192.168.1.8'
gitlab_rails['gitlab_ssh_host'] = '192.168.1.8'
此時可以通過瀏覽器訪問http://192.168.1.8加載GitLab跨扮。首次登陸需要修改root的密碼,輸入兩次密碼以更改root密碼验毡。也可以注冊新的用戶登陸后創(chuàng)建project衡创。
需要為新用戶創(chuàng)建SSH公鑰,產(chǎn)生后將其拷貝到Gitlab的設(shè)置中
localhost:gitlab jackzhang$ ssh-keygen -t rsa -C '<your email>'
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/<your user name>/.ssh/id_rsa): <your_rsa_file_name>
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in <your_rsa_file_name>.
Your public key has been saved in <your_rsa_file_name>.pub.
The key fingerprint is:
SHA256:Wkv4DLEjR8pfMQM4rSLTYi3VtCP1+4GinPrdf8SlNQI <your email>
The key's randomart image is:
+---[RSA 3072]----+
| o=. |
| .+.+. E |
| .o. =o.+ . |
|+ooooo.+o+ . + |
|.+..+.*oS.. = . |
| . o+.X...+ |
| + o +.. |
| . . . . |
| ... . .... |
+----[SHA256]-----+
#輸出產(chǎn)生的公鑰并拷貝
localhost:gitlab jackzhang$ cat <your_rsa_file_name>.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDM+wDtRaZqn3s1o20jQZoGZ4+TLvDu1d37QE3/AwB8DIbg1GSLqBpYqsttpbWwewUKhXs0m/0+Cet1tNgGGZZNT+/Hu9KPjln43dTSPAgmS+hF6BrEN8pK4nbwH9yG4llXAEjGyKwuHow75bkA0JV0Y7vbRePv6/OqVcifjeU6ckvN1I8287RFLi0f5EY6GrFJsoFMCec++u0zEEyTV+3OwbcKpe+03Du3Vm6C8y5feBkmo5bRNQoc0NNfTj9uMAuw8dQVjZBYJzEiRotnqIhbUAeO7vf6deS+UBsco5gl+HAP+fkeT+fu26VGlopgvQueDr68CDd3PjIvsFtldyl15t0RmT5U0kiz/G99ekU33RiAkO7rU9Ou5PSaD0C2iK2VXEj7cUHI91Xut2kYDBqMmt/V4+pf7G3HrsPrwPHKEepNAlYsOWLA22VZYTThzFCrsVfWTI4gS5Psh68vrVeaUe1PDhGgc10U5AGatP60SPxqLX5RDoluIts9vJVZIgc= <your email>
在Gitlab中點擊右上角用戶頭像的向下箭頭晶通,選擇setting璃氢,在user setting中選擇SSH keys,在右側(cè)按照提示輸入添加狮辽。
OK一也,到此我們的GitLab已經(jīng)設(shè)置完畢,project也創(chuàng)建成功隘竭,試試下載代碼吧塘秦。如果你還沒有Git的客戶端,請移步到Git的安裝步驟: https://git-scm.com/book/en/v2/Getting-Started-Installing-Git
在GitLab的project中選擇你要clone的project动看,在右上角的Clone里面選擇HTTP的下載方式尊剔,拷貝URL
#這里用localhost代替了上面的IP,因為DHCP的原因菱皆,本地IP經(jīng)常發(fā)生改變
localhost:GIT_REPO jackzhang$ git clone http://localhost/Zhang/helloworld.git
Cloning into 'helloworld'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
Jenkins