Gitlab 源码安装版 升级笔记

Gitlab 升级笔记

适用于使用源码安装的Gitlab

GitLab Community Edition 8.3.2 fbb8b6e>

0. Backup

1
2
cd /home/git/gitlab
sudo -u git -H bundle exec rake gitlab:backup:create RAILS_ENV=production

备份完成后会在/home/git/gitlab/backup文件夹下生成已时间戳命名的文件1459217332_gitlab_backup.tar

1. Stop server

1
sudo service gitlab stop

2.Run GitLab upgrade tool

Please replace X.X.X with the latest GitLab release.

GitLab 7.9 adds nodejs as a dependency. GitLab 7.6 adds libkrb5-dev as a dependency (installed by default on Ubuntu and OSX). GitLab 7.2 adds pkg-config and cmake as dependency. Please check the dependencies in the installation guide.

1
2
3
4
5
cd /home/git/gitlab
sudo -u git -H ruby -Ilib -e 'require "gitlab/upgrader"' -e 'class Gitlab::Upgrader' -e 'def latest_version_raw' -e '"vX.X.X"' -e 'end' -e 'end' -e 'Gitlab::Upgrader.new.execute'
# to perform a non-interactive install (no user input required) you can add -y
# sudo -u git -H ruby -Ilib -e 'require "gitlab/upgrader"' -e 'class Gitlab::Upgrader' -e 'def latest_version_raw' -e '"vX.X.X"' -e 'end' -e 'end' -e 'Gitlab::Upgrader.new.execute' -- -y

小插曲:执行命令时报错

1
2
3
4
5
from /home/git/gitlab/lib/gitlab/upgrader.rb:74:in `upgrade'
from /home/git/gitlab/lib/gitlab/upgrader.rb:22:in `execute'
from -e:7:in `<main>'

解决办法

1
2
3
Open /home/git/gitlab/lib/gitlab/upgrader.rb in editor
Replace all #{Gitlab.config.git.bin_path} by git and save
Run upgrader.rb as usual

I have the same problem upgrading from 8.5.1 to 8.5.5. Replacing Gitlab.config.git.bin_path with git fixed it.
This is the search and replace command to run in vi: %s/#{Gitlab.config.git.bin_path}/git/g

3. Start application

1
2
sudo service gitlab start
sudo service nginx restart

4. Check application status

Check if GitLab and its dependencies are configured correctly:

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

If all items are green, then congratulations upgrade is complete!

5. Upgrade GitLab Shell

GitLab Shell might be outdated, running the commands below ensures you’re using a compatible version:

1
2
3
cd /home/git/gitlab-shell
sudo -u git -H git fetch
sudo -u git -H git checkout v`cat /home/git/gitlab/GITLAB_SHELL_VERSION`

One line upgrade command

You’ve read through the entire guide and probably already did all the steps one by one.
Below is a one line command with step 1 to 5 for the next time you upgrade.
Please replace X.X.X with the latest GitLab release.

1
2
3
4
5
6
7
8
9
10
11
cd /home/git/gitlab; \
sudo -u git -H bundle exec rake gitlab:backup:create RAILS_ENV=production; \
sudo service gitlab stop; \
sudo -u git -H ruby -Ilib -e 'require "gitlab/upgrader"' -e 'class Gitlab::Upgrader' -e 'def latest_version_raw' -e '"vX.X.X"' -e 'end' -e 'end' -e 'Gitlab::Upgrader.new.execute' -- -y; \
cd /home/git/gitlab-shell; \
sudo -u git -H git fetch; \
sudo -u git -H git checkout v`cat /home/git/gitlab/GITLAB_SHELL_VERSION`; \
cd /home/git/gitlab; \
sudo service gitlab start; \
sudo service nginx restart; \
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production

####Note:
阿里云服务器ruby源不稳定。换国内的源

1
2
3
4
gem sources --add https://ruby.taobao.org/ --remove https://rubygems.org/
gem sources -l
# 请确保只有 ruby.taobao.org
gem install rails
1
sudo -u git bundle install

安装完成之后 update init script

1
2
rm /etc/init.d/gitlab
sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab

升级是由于是从7.x 到8.x 样式变化很大,所以执行完后样式错乱。后来找了些文档才发现要重新生产asset文件。

1
sudo -u git -H bundle exec rake assets:clean assets:precompile cache:clear RAILS_ENV=production

重启

1
2
service gitlab start
service nginx restart

Done!