CentOS で GitLab を 5.3 から 6.1 にバージョンアップしたのでそのときの手順を残しておきます。
参考
- https://github.com/gitlabhq/gitlabhq/blob/master/doc/update/5.3-to-5.4.md
- https://github.com/gitlabhq/gitlabhq/blob/master/doc/update/5.4-to-6.0.md
- https://github.com/gitlabhq/gitlabhq/blob/master/doc/update/6.0-to-6.1.md
- https://github.com/gitlabhq/gitlab-recipes/blob/master/install/centos/README.md
はじめに
すべての作業は git アカウントで行います。root が必要な作業は sudo しています。基本的に参考URLの手順通りです。
5.3 から 6.1 に一気にバージョンアップしようかとも思ったのですが、6.0 から 6.1 のバージョンアップ手順 に「6.1 の前に 6.0 にしておくべし」とあったので、面倒ですが順番にバージョンアップしました。
おそらく、5.4 は飛ばしたり、gitlab-shell は 5.3 から 6.1 まで一気にバージョンアップしても大丈夫だと思いますが、失敗すると面倒なので1つ1つ順番にやりました。
Backup
$ cd /home/git/gitlab $ RAILS_ENV=production bundle exec rake gitlab:backup:create
Stop server
$ sudo service gitlab stop
From 5.3 to 5.4
Get latest code(5.4)
$ cd /home/git/gitlab $ git fetch $ git checkout 5-4-stable
Update gitlab-shell
$ cd /home/git/gitlab-shell $ git fetch $ git checkout v1.5.0
Install libs, migrations, etc.
$ cd /home/git/gitlab $ bundle install --without development test postgres --deployment $ bundle exec rake db:migrate RAILS_ENV=production $ bundle exec rake assets:precompile RAILS_ENV=production
From 5.4 to 6.0
Get latest code(6.0)
$ cd /home/git/gitlab $ git checkout 6-0-stable error: Your local changes to the following files would be overwritten by checkout: db/schema.rb Please, commit your changes or stash them before you can switch branches. Aborting
エラーになりました。db/schema.rb がローカル側で変更されているようです。
$ git diff
diff --git a/db/schema.rb b/db/schema.rb index 348272e..585264e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -203,14 +203,14 @@ ActiveRecord::Schema.define(:version => 20130614132337) do create_table "snippets", :force => true do |t| t.string "title" - t.text "content" - t.integer "author_id", :null => false + t.text "content", :limit => 2147483647 + t.integer "author_id", :null => false t.integer "project_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.string "file_name" t.datetime "expires_at" - t.boolean "private", :default => true, :null => false + t.boolean "private", :default => true, :null => false t.string "type" end
大丈夫そうなので -f
で上書きします。
$ git checkout -f 6-0-stable
Update gitlab-shell
$ cd /home/git/gitlab-shell $ git checkout v1.7.0
Install additional packages
$ sudo yum install python-docutils
Install libs, migrations, etc.
$ cd /home/git/gitlab $ bundle install --without development test postgres --deployment $ bundle exec rake db:migrate RAILS_ENV=production
次の手順で yes/no プロンプトが表示されるので yes と入力します。
6.0 の変更で Team が無くなり Group がメンバーを持つようになったため、Group の所有者をメンバーに追加するかどうかのプロンプトだと思います。
$ bundle exec rake migrate_groups RAILS_ENV=production This will add group owners to group membership Do you want to continue (yes/no)? yes
次の手順でグローバルプロジェクトがプロジェクトの所有者の名前空間に移動されるのだと思いますが、グローバルプロジェクトを使っていなかったので関係ありませんでした。
$ bundle exec rake migrate_global_projects RAILS_ENV=production No global projects found. Proceed with update.
次の手順で yes/no プロンプトが表示されるので yes と入力します。
表示された Issue によると、6.0 からSSH公開鍵の一意性が公開鍵のコメントを除いて行われるようになったため、それが原因で重複してしまう公開鍵を削除するかどうかのプロンプトのようです。
$ bundle exec rake migrate_keys RAILS_ENV=production This will add fingerprint to ssh keys in db If you have duplicate keys https://github.com/gitlabhq/gitlabhq/issues/4453 all but the first will be deleted Do you want to continue (yes/no)? yes
作業を進めます。
$ bundle exec rake migrate_inline_notes RAILS_ENV=production $ bundle exec rake gitlab:satellites:create RAILS_ENV=production $ bundle exec rake cache:clear RAILS_ENV=production $ bundle exec rake assets:clean RAILS_ENV=production $ bundle exec rake assets:precompile RAILS_ENV=production
From 6.0 to 6.1
Get latest code(6.1)
$ cd /home/git/gitlab $ git checkout 6-1-stable
Update gitlab-shell
$ cd /home/git/gitlab-shell $ git checkout v1.7.1
Install libs, migrations, etc.
$ cd /home/git/gitlab $ bundle install --without development test postgres --deployment $ bundle exec rake db:migrate RAILS_ENV=production
次の手順で Issues/Merge Requests/Milestones の id がプロジェクト毎の連番になるようにリナンバリングされます。
$ bundle exec rake migrate_iids RAILS_ENV=production
作業を進めます。
$ bundle exec rake assets:clean RAILS_ENV=production $ bundle exec rake assets:precompile RAILS_ENV=production $ bundle exec rake cache:clear RAILS_ENV=production
Update config files
gitlab.yml を修正します。あらかじめ 5.3 でどのように修正していたかを確認し、それを参考に 6.1 の gitlab.yml.example をコピペ修正します。
$ cd /home/git/gitlab/config/ $ git diff --color 5-3-stable:config/gitlab.yml.example gitlab.yml $ cp gitlab.yml.example gitlab.yml $ vi gitlab.yml
production の gitlab/host
、gitlab/email_from
、gitlab/support_email
、git/bin_path
辺りが要修正箇所です。
@@ -17,3 +17,3 @@ production: &base ## Web server settings - host: localhost + host: gitlab.ore.example.jp port: 80 @@ -35,6 +35,6 @@ production: &base # Email address used in the "From" field in mails sent by GitLab - email_from: gitlab@localhost + email_from: gitlab@ore.example.jp # Email address of your support contact (default: same as email_from) - support_email: support@localhost + support_email: support@ore.example.jp @@ -171,3 +171,3 @@ production: &base git: - bin_path: /usr/bin/git + bin_path: /usr/local/bin/git # Max size of a git object (e.g. a commit), in bytes
アプリケーションサーバが puma から unicorn に変わった(戻った)ので unicorn.rb.example をコピーして unicorn.rb を作成します(内容は修正していません)。
$ cp unicorn.rb.example unicorn.rb
gitlab-shell が GitLab にアクセスするURLを修正します。
$ cd /home/git/gitlab-shell $ cp config.yml.example config.yml $ vi config.yml
次のように修正しました。
@@ -4,3 +4,3 @@ # Url to gitlab instance. Used for api calls. Should end with a slash. -gitlab_url: "http://localhost/" +gitlab_url: "http://localhost:8080/"
Update Init script
CentOS 用の init スクリプトと Apache 用の conf を差し替えます。
$ sudo rm /etc/init.d/gitlab $ sudo rm /etc/httpd/vhost.d/gitlab.conf $ sudo curl --output /etc/init.d/gitlab https://raw.github.com/gitlabhq/gitlab-recipes/master/init/sysvinit/centos/gitlab-unicorn $ sudo curl --output /etc/httpd/vhost.d/gitlab.conf https://raw.github.com/gitlabhq/gitlab-recipes/master/web-server/apache/gitlab.conf $ sudo chmod +x /etc/init.d/gitlab
ruby は GitLab 用にソースからインストールしているので init スクリプトにパスを記述します。
$ sudo vi /etc/init.d/gitlab
RVM を使っているわけではありませんが、RVM_PATH にパスを書いておけばよさそうなのでそうしました。
RVM_PATH="/home/git/ruby-versions/2.0.0-p247/bin"
Apache でモジュールが足りなかったので追加します。
$ sudo vi /etc/httpd/conf/httpd.conf
mod_rewrite
と mod_proxy_balancer
を追加しました。
LoadModule rewrite_module modules/mod_rewrite.so LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
Apache のバーチャルホスト設定を修正します。
$ sudo cp /etc/httpd/vhost.d/gitlab.conf /etc/httpd/vhost.d/gitlab.conf.orig $ sudo vi /etc/httpd/vhost.d/gitlab.conf
サーバ名とログファイル名を変更しました。
@@ -7,5 +7,5 @@ # mod_proxy_http <VirtualHost *:80> - ServerName gitlab.example.com + ServerName gitlab@ore.example.jp ServerSignature Off @@ -24,5 +24,5 @@ BalancerMember http://127.0.0.1:8080 ProxyPassReverse http://127.0.0.1:8080 - ProxyPassReverse http://gitlab.example.com:8080 + ProxyPassReverse http://gitlab@ore.example.jp:8080 </Proxy> @@ -41,9 +41,6 @@ </Location> - LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b" common_forwarded - ErrorLog /var/log/httpd/logs/gitlab.example.com_error.log - CustomLog /var/log/httpd/logs/gitlab.example.com_forwarded.log common_forwarded - CustomLog /var/log/httpd/logs/gitlab.example.com_access.log combined env=!dontlog - CustomLog /var/log/httpd/logs/gitlab.example.com.log combined + ErrorLog logs/gitlab-error_log + CustomLog logs/gitlab-access_log combined </VirtualHost>
Start application
GitLab の起動と Apache の再起動を行います。
$ sudo service gitlab start $ sudo service httpd restart
Check application status
GitLab のステータスを確認します。
$ cd /home/git/gitlab $ bundle exec rake gitlab:env:info RAILS_ENV=production $ bundle exec rake gitlab:check RAILS_ENV=production
gitlab:check で「Init script up-to-date?」が no になりますが Ubuntu/Debian の手順にある lib/support/init.d/gitlab を使わない限りそうなるので無視します。
さいごに
ブラウザで閲覧したり、Git で fetch/Push できればバージョンアップ成功です!
幾つか互換性の無い変更点があるので注意が必要です。
Global projects
グローバルプロジェクトがなくなり、すべてのプロジェクトはなんらかの(user or group)名前空間に属することになります。
バージョンアップ作業時にグローバルプロジェクトが存在する場合、そのプロジェクトのオーナーの名前空間に移動されます。
Teams
Team がなくなって、代わりに Group がメンバーを持つようになりました。
バージョンアップ作業時に Team が削除され、Group のオーナーが Group の最初のメンバーになります。
Global issue numbers
Issue 番号がプロジェクト毎に採番されるようになりました(たぶん MR と Milestone も)。
バージョンアップ作業時にリナンバリングされます。 古い番号の URL は新しい番号の URL にリダイレクトされますが、古い方の番号が別のチケットの番号に使われるとリダイレクトされません。