社内でwikiを使いたいと思い、そういえばGitLabが使えるかもしれないといろいろと調べていたが、バージョン6.0だとmarkdown形式のファイルへの対応が微妙(テーブルが表示されなかったり、ページ内リンクがきかなかったり)だったので、7.1へとアップデートする。
環境確認
CentOS6.4+unicorn+Apache+rvm
現状のGitLabのインストール状況をrakeコマンドで確認。
$ bundle exec rake gitlab:env:info RAILS_ENV=production System information System:CentOS release 6.4 (Final) Current User:git Using RVM:yes RVM Version:1.21.2 Ruby Version:1.9.3p429 Gem Version:1.8.25 Bundler Version:1.3.5 Rake Version:10.1.0 GitLab information Version:6.0.2 Revision:7e96df0 Directory:/home/git/gitlab DB Adapter:mysql2 URL:http://gitlab.example.com HTTP Clone URL:http://gitlab.example.com/some-project.git SSH Clone URL:ssh://[email protected]:10022/some-project.git Using LDAP:no Using Omniauth:no GitLab Shell Version:1.7.0 Repositories:/home/git/repositories/ Hooks:/home/git/gitlab-shell/hooks/ Git:/usr/bin/git
・公式ガイド
https://github.com/gitlabhq/gitlabhq/blob/master/doc/update/6.0-to-7.1.md
・目標
GitLab7.1へアップデート。
目次
内容
紹介
いろいろ変わってた。
今回の主な動機であるmarkdown形式への対応が素晴らしくアップデートされているようだ。
バックアップ
データベースのバックアップをとる。
$ sudo su git $ cd /home/git/gitlab $ bundle exec rake gitlab:backup:create RAILS_ENV=production
すると下記のエラー
rake aborted! No such file or directory - /home/git/gitlab/public/uploads …
public/uploads ディレクトリが必要なようなので、一旦作成する。
# mkdir /home/git/gitlab/public/uploads # chown git:git /home/git/gitlab/public/uploads $ bundle exec rake gitlab:backup:create RAILS_ENV=production
その後、再度バックアップ処理を行う。
成功。
サーバー停止
$ sudo service gitlab stop
Rubyのバージョンアップ
これまで使っていたruby1.9系が非推奨になったので、2.1にアップデートする。
$ cd /home/git/ $ rvm get latest $ rvm install 2.1 $ rvm use 2.1
追加パッケージのインストール
$ sudo yum install logrotate
GitLab7.1のコードを取得
$ cd /home/git/gitlab $ sudo -u git -H git fetch $ sudo -u git -H git checkout 7-1-stable
gitlab-shellのアップデート
$ cd /home/git/gitlab-shell $ sudo -u git -H git fetch $ sudo -u git -H git checkout v1.9.6
私の環境だと、上記コマンドでHEADが切り離されたので新たにブランチをきる。
$ git checkout -b v1.9.6
確認。
$ cat VERSION 1.9.6
ライブラリのインストールとマイグレーション
$ cd /home/git/gitlab
bundlerで追加されたライブラリのインストールを行う。
MySQLを利用しているので、下記を実行。
$ bundle install --without development test postgres --deployment
次に以下の rake タスクを実行して各種データのマイグレーションを行う。
$ bundle exec rake db:migrate RAILS_ENV=production $ bundle exec rake migrate_iids RAILS_ENV=production $ bundle exec rake assets:clean assets:precompile cache:clear RAILS_ENV=production $ sudo chmod u+rwx,g+rx,o-rwx /home/git/gitlab-satellites
redisのキャッシュをクリア
$ bundle exec rake cache:clear RAILS_ENV=production
configファイルのアップデート
gitlab.ymlのみ編集を行う。
設定ファイル /home/git/gitlab/config/gitlab.yml を下記リンク先の内容と自分の環境をあわせて作成する。
https://gitlab.com/gitlab-org/gitlab-ce/blob/7-1-stable/config/gitlab.yml.example
$ cd /home/git/gitlab/config $ cp gitlab.yml gitlab.yml.bak $ rm gitlab.yml.example $ wget https://gitlab.com/gitlab-org/gitlab-ce/raw/7-1-stable/config/gitlab.yml.example $ cp gitlab.yml.example gitlab.yml $ vi gitlab.yml
主に下記を編集した。
## GitLab settings gitlab: ## Web server settings host: gitlab.example.net port: 80 https: false … ## Email settings # Email address used in the "From" field in mails sent by GitLab email_from: [email protected] … # If you use non-standard ssh port you need to specify it ssh_port: 10022
※gitlab.ymlは書き方を少しでも間違うと、いろんなコマンドが正常に通らなくなるので、原因不明のエラーで詰まったらgitlab.ymlをもう一度見直すことをおすすめする。
次にunicorn.rbを更新する。
$ cp unicorn.rb unicorn.rb.bak $ rm unicorn.rb.example $ cp unicorn.rb unicorn.rb.bak $ wget https://gitlab.com/gitlab-org/gitlab-ce/raw/7-1-stable/config/unicorn.rb.example $ rm unicorn.rb $ cp unicorn.rb.example unicorn.rb $ vi unicorn.rb
特に変更せずに保存。
※ダウンロード先のバージョンに注意。
起動ファイルのアップデート
$ sudo rm /etc/init.d/gitlab $ cd /home/git/gitlab $ sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab $ sudo chmod +x /etc/init.d/gitlab
今回rvmを使っているので、下記を起動ファイルに追記。
$ sudo vi /etc/init.d/gitlab # # set rvm environment valiables. # export PATH=/home/git/.rvm/gems/ruby-2.1.2/bin:/home/git/.rvm/gems/[email protected]/bin:/home/git/.rvm/rubies/ruby-2.1.2/bin:/home/git/.rvm/bin:/opt/python2.7/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/shinji.y/bin:/home/git/.rvm/bin export GEM_HOME=/home/git/.rvm/gems/[email protected] export GEM_PATH=/home/git/.rvm/gems/[email protected]:/home/git/.rvm/gems/[email protected] export MY_RUBY_HOME=/home/git/.rvm/rubies/ruby-2.1.2 export IRBRC=/home/git/.rvm/rubies/ruby-2.1.2/.irbrc
GitLab起動
$ sudo service gitlab start
ブラウザからアクセスすると無事GitLab7.1が表示された。
以上。