使用Docker 建置 GitLab CI

最近有需求在Mac環境中,使用Docker建置Gitlab的開發環境與CI /CD , 所以記錄一下相關的步驟與細節,Gitlab是一個用Ruby on Rails 開發的開源項目,可以通過web 界面進行專案管理與測試。

使用Docker 佈署可以很容易進行安裝Gitlab與版本管理。

安裝Docker Desktop

https://docs.docker.com/docker-for-mac/install/

  • 點擊Docker.app進行安裝

啟動後會提示您使用系統密碼授權Docker.app。 需要特權訪問才能安裝網絡組件和Docker應用程序的鏈接。

頂部狀態欄中的Docker菜單表示Docker Desktop正在運行,並且可以從終端進行訪問。

如果您剛剛安裝了該應用程序,則還會收到一條消息,其中包含建議的後續步驟以及指向文檔的鏈接。 單擊Docker menu以消除此彈出通知。

  • 開啟Teminal 確認docker 指令可以正常
$ docker -v

下載Gitlab image

$ docker pull gitlab/gitlab-ce

https://docs.gitlab.com/omnibus/docker/

建立Gitlab Container

$   sudo docker run -d \
    --hostname xxxx.xxxx.xx \
    --name gitlab \
    --restart always \
    --publish 30001:22 --publish 30000:80 --publish 30002:443 \
    --volume ~/gitlab/data:/var/opt/gitlab \
    --volume ~/gitlab/logs:/var/log/gitlab \
    --volume ~/gitlab/config:/etc/gitlab \
    gitlab/gitlab-ce
  • hostname 建立gitlab 的位置可使用domain or ip
  • name container 名稱
  • restart 設定為docker 服務啟動後自動重啟
  • publish 將主機的30000, 30001, 30002 對應到 80, 22, 443
  • volume 將gitlab 的檔案對應到實體主機的路徑,container 刪除後重建與更新後不影響系統資料

修改gitlab.rb 文件

因為已經有把gitlab.rb 文件對應到 ~/gitlab/config

$ vi ~/gitlab/config/gitlab.rb

修改的內容如下:

  • external_url ‘http://hostname:30000
  • gitlab_rails[‘gitlab_ssh_host’] = ‘hostname’
  • gitlab_rails[‘gitlab_shell_ssh_port’] = 30001
  • nginx[‘listen_port’] = 80

修改email 的配置

一樣在gitlab.rb 中增加smtp的配置

gitlab_rails[‘gitlab_email_from’] = “xxxx@163.com”  
gitlab_rails[‘gitlab_email_reply_to’] = ‘xxxx@163.com‘  
gitlab_rails[‘smtp_enable’] = true
gitlab_rails[‘smtp_address’] = “smtp.163.com
gitlab_rails[‘smtp_port’] = 465 
gitlab_rails[‘smtp_user_name’] = “xxxx@163.com”  
gitlab_rails[‘smtp_password’] = “xxxxpassword”   gitlab_rails[‘smtp_domain’] = “163.com”   gitlab_rails[‘smtp_authentication’] = “login”          gitlab_rails[‘smtp_enable_starttls_auto’] = true 
gitlab_rails[‘smtp_tls’] =true    gitlab_rails[‘smtp_openssl_verify_mode’] = “peer” 

重啟gitlab service

$ sudo docker exec -it gitlab /bin/bash
$ gitlab-ctl reconfigure

在〈使用Docker 建置 GitLab CI〉中有 25 則留言

  1. I have bewn browsing online mpre than three hours
    today, yet I ndver found aany interesting artice likee yours.
    It’s pretty worth enough for me. Personally, if all website ownrs aand bloggerss maxe good contrnt as yoou did, the internet
    will bee much more useful thgan ecer before.

  2. Thaat is vrry attention-grabbing, You’re an eccessively
    skilled blogger. I’ve joined youyr rss feed annd look aheqd too looiking for more oof yourr fantastic post.
    Also, I’ve shared ypur website in myy social networks

  3. I was curipus if yoou eer considerd hanging thhe psge layout of yoyr blog?
    Its very wel written; I loove what youve goot to say.

    But maybe yoou could a lottle mmore inn thee wayy oof ckntent so peeople coulod comnect wih it better.
    Youve got an awfyl llot of tedt forr onbly having one oor twwo pictures.
    Maybe you cokuld space iit out better?

  4. I’m truloy enjoying thee design and layyout of your blog.
    It’s a ery easy on thhe eyes which makes it much more pleasant for me to
    clme here annd visit more often. Did yoou hiore out a designer to create yolur theme?
    Supesrb work!

  5. I have been surfing onine more thsn 2 hohrs today, yett
    I never found anny interestinhg aarticle like yours. It’s pretty worth enouvh
    for me. Personally, if all website owners aand bloggers
    made good content as you did,the net will be muc more useful than ever before.

  6. Woww that wwas odd. I just wrote an icredibly loong commwnt butt aftter
    I clicked suubmit my conment didn’t appear. Grrrr…
    well I’m not writing alll thaat over again. Anyhow, just wanted to say excellent blog!

  7. Goood day! Do yyou kniw iff they make anny plugins
    to assist with SEO? I’m tryijg to geet my log to rnk for soe targeted keyords buut
    I’m not seeung vwry good results. If you knoow of any plesase share.

    Cheers!

  8. Pleas llet mme know iff you’re looking ffor a artihle wrtiter ffor your site.
    Yoou haqve some really grewat articles aand Ibeslieve I woulkd be a good asset.
    If you ever want too take some of thee losd off, I’d absolutely
    love to writte some conteht forr yoiur bloog in exxchange ffor a linmk back to
    mine. Pleaase blast me aan e-mail iif interested. Manny thanks!

  9. Howdy vwry nice site!! Man .. Beautiful .. Amaxing .. I will bookomark
    your ite and take the feds additionally? Iam glaqd tto eek oout a lott of helpful
    infirmation right here withhin thhe submit, we waqnt develop extda techniques oon this regard, thank
    you for sharing. . . . . .

  10. Grewat work! Thhis is the type oof ibfo thzt aare ment to be shared across the net.
    Dsgrace onn Google for no loinger positioning this
    post higher! Come on ovcer and consult wit mmy site . Thaznk yoou =)

  11. Greetings! Quick querstion that’s totlly off topic.
    Do you kno how to mazke your site mobille
    friendly? My web ste looks weiord when vieeing from my iphone.
    I’m tryng to find a thesme or plgin that might be able to
    redolve thyis problem. If yoou haave any
    recommendations, pleazse share. Appreciate it!

  12. Superb blpog yoou have here butt I was curiouss if you knew of anyy forums
    tnat covver thhe same topics discussed iin this article? I’d really loge to bee a part oof community wyere I ccan get feedback
    from othewr knowledgeable people tuat shazre thee sane interest.

    If youu have aany recommendations, please lett me know.
    Appfeciate it!

發佈回覆給「Britt」的留言 取消回覆

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *