Skip to main content

Gitlab Server

Installation

With Docker
mkdir /mygitlab

docker run --detach \
  --hostname  mygit.example.com\
  --publish 80:80 \
  --name gitlab \
  --restart always \
  --volume /mygitlab/config:/etc/gitlab \
  --volume /mygitlab/logs:/var/log/gitlab \
  --volume /mygitlab/data:/var/opt/gitlab \
  --privileged \
  gitlab/gitlab-ce:17.11.7-ce.0

Config

    主設定檔:/etc/gitlab/gitlab.rb 
    Custom port

    1- docker command

    • 使用非標準埠時,host 與 container 必須使用相同埠號。
    • 如果只修改 docker 啟動參數的外部 port,而不修改 gitlab.rb,服務可以正常啟動,首頁與帳號登入也正常,不過網頁上的專案 URL 位址會不正確。 
    docker run --detach \
      --hostname 10.4.1.76 \
      --publish 6080:6080 \
      --name gitlab \
      --volume /myapp/gitlab/config:/etc/gitlab \
      --volume /myapp/gitlab/logs:/var/log/gitlab \
      --volume /myapp/gitlab/data:/var/opt/gitlab \
    ...

    2- Edit gitlab.rb 

    • 變更 port 會影響 container 的通訊埠,且必須與 docker 啟動參數的內部 port 相同。
    nginx['listen_port'] = 6080
    external_url 'http://10.4.1.76:6080'

    Backup & Restore

    With Docker

    • 備份檔 (編號_日期_版本_gitlab_backup.tar) 要先複製到 container 的目錄 /var/opt/gitlab/backups (預設)
    # Backup
    docker exec -it <container-name> gitlab-backup create
    # Backup DB only
    docker exec -it <container-name> gitlab-backup create SKIP=artifacts,repositories,registry,uploads,builds,pages,lfs,packages,terraform_state
    
    # Verify the backup file
    docker exec -it <container-name> ls  /var/opt/gitlab/backups
    
    # Restore
    docker exec -it <container-name> bash
    > gitlab-ctl stop puma
    > gitlab-ctl stop sidekiq
    > gitlab-ctl status
    
    > gitlab-backup restore BACKUP=1704810663_2024_01_09_17.11.1
    # Restore DB only
    > gitlab-backup restore BACKUP=1704810663_2024_01_09_17.11.1 SKIP=artifacts,repositories,registry,uploads,builds,pages,lfs,packages,terraform_state
    
    > gitlab-ctl restart
    > gitlab-rake gitlab:check SANITIZE=true
    > gitlab-rake gitlab:artifacts:check
    > gitlab-rake gitlab:lfs:check
    > gitlab-rake gitlab:uploads:check
    
    # Restart the container
    docker restart <container-name>

    Upgrade & Patch

    Pre-upgrade and post-upgrade checks

    1- Check the general configuration:

    # With Docker
    docker exec -it <container-name> gitlab-rake gitlab:check | tee mylogs/check.250916.out

    2- Confirm that encrypted database values can be decrypted:

    # With Docker
    docker exec -it <container-name> gitlab-rake gitlab:doctor:secrets | tee mylogs/doctor_secrets.250916.out

    3- Check the status of all background database migrations.

    gitlab-psql -c "SELECT job_class_name, table_name, column_name, job_arguments FROM batched_background_migrations WHERE status NOT IN(3, 6);"
    
    # With Docker
    docker exec -it <container-name> gitlab-psql -c "SELECT job_class_name, table_name, column_name, job_arguments FROM batched_background_migrations WHERE status NOT IN(3, 6);"

    4- In GitLab UI, check that:

    • Users can sign in.
    • The project list is visible.
    • Project issues and merge requests are accessible.
    • Users can clone repositories from GitLab.
    • Users can push commits to GitLab.

    Troubleshooting

    HTTP 502
    1. 記憶體至少需要 4GB,如果不足可能無法初始化所有服務。
    2. 通訊埠衝突,檢查 host 與 container 是否有相同 port 衝突。Gitlab 內建多個服務,啟動會開啟相應的 port,例如 puma 預設使用 8080。要檢查不同內建服務的預設 port 號,可以檢視 gitlab.rb