WeAir

源码升级GitLab

1.编辑配置文件

进入/home/git/gitlab/conf目录并编辑gitlab.yml文件。

更改配置如下:

1
2
3
4
backup:
path: "tmp/backups" # Relative paths are relative to Rails.root (default: tmp/backups/)
gitaly_backup_path: "/home/git/gitaly/gitaly-backup" # Path of the gitaly-backup binary (default: searches $PATH)
...

2.备份

1
2
3
cd /home/git/gitlab

sudo -u git -H bundle exec rake gitlab:backup:create RAILS_ENV=production

3.停止GitLab服务

1
service gitlab stop

4.升级Git

1
2
3
4
5
6
apt-get install -y libcurl4-openssl-dev libexpat1-dev gettext libz-dev libssl-dev libpcre2-dev build-essential

git clone https://gitlab.com/gitlab-org/gitaly.git -b <X-Y-stable> /tmp/gitaly

cd /tmp/gitaly
make git GIT_PREFIX=/usr/local

5.获取最新代码

1
2
3
4
5
6
7
cd /home/git/gitlab

sudo -u git -H git fetch --all --prune
sudo -u git -H git checkout -- Gemfile.lock db/structure.sql locale

# 'BRANCH'改为需要升级的版本
sudo -u git -H git checkout BRANCH

6.更新配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
cd /home/git/gitlab

# 检查GitLab配置文件
git diff origin/PREVIOUS_BRANCH:config/gitlab.yml.example origin/BRANCH:config/gitlab.yml.example

# 检查NGINX配置文件
# HTTPS
git diff origin/PREVIOUS_BRANCH:lib/support/nginx/gitlab-ssl origin/BRANCH:lib/support/nginx/gitlab-ssl
# HTTP
git diff origin/PREVIOUS_BRANCH:lib/support/nginx/gitlab origin/BRANCH:lib/support/nginx/gitlab

# 更新启动脚本
cp lib/support/init.d/gitlab /etc/init.d/gitlab

7.安装库、迁移数据等

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
cd /home/git/gitlab

sudo -u git -H bundle config set --local deployment 'true'
sudo -u git -H bundle config set --local without 'development test mysql aws kerberos'

#更新gem包
sudo -u git -H bundle install

# 清理旧的gem包(可选)
sudo -u git -H bundle clean

# 数据迁移
sudo -u git -H bundle exec rake db:migrate RAILS_ENV=production

# 编译GetText PO
sudo -u git -H bundle exec rake gettext:compile RAILS_ENV=production

# 编译静态文件
sudo -u git -H bundle exec rake yarn:install gitlab:assets:clean gitlab:assets:compile RAILS_ENV=production NODE_ENV=production NODE_OPTIONS="--max_old_space_size=4096"

# 清理缓存文件
sudo -u git -H bundle exec rake cache:clear RAILS_ENV=production

8.升级GitLab Shell

1
2
3
4
5
cd /home/git/gitlab-shell

sudo -u git -H git fetch --all --tags --prune
sudo -u git -H git checkout v$(</home/git/gitlab/GITLAB_SHELL_VERSION)
sudo -u git -H make build

9.升级GitLab Workhorse

1
2
3
cd /home/git/gitlab

sudo -u git -H bundle exec rake "gitlab:workhorse:install[/home/git/gitlab-workhorse]" RAILS_ENV=production

10.升级Gitaly

1
2
3
4
cd /home/git/gitaly
sudo -u git -H git fetch --all --tags --prune
sudo -u git -H git checkout v$(</home/git/gitlab/GITALY_SERVER_VERSION)
sudo -u git -H make

11.升级GitLab Pages

1
2
3
4
5
cd /home/git/gitlab-pages

sudo -u git -H git fetch --all --tags --prune
sudo -u git -H git checkout v$(</home/git/gitlab/GITLAB_PAGES_VERSION)
sudo -u git -H make

12.启动GitLab

1
service gitlab start

13.检查GitLab状态

1
2
3
4
5
cd /home/git/gitlab

sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production

sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production

如果所有项目都是绿色,升级成功。

其它问题可查询官方文档