Gitlab 読み (4)

gitlab の lib/tasks 配下を云々。

$ find lib/tasks 
lib/tasks
lib/tasks/.gitkeep
lib/tasks/sidekiq.rake
lib/tasks/travis.rake
lib/tasks/gitlab
lib/tasks/gitlab/import.rake
lib/tasks/gitlab/task_helpers.rake
lib/tasks/gitlab/check.rake
lib/tasks/gitlab/setup.rake
lib/tasks/gitlab/enable_namespaces.rake
lib/tasks/gitlab/gitolite_rebuild.rake
lib/tasks/gitlab/test.rake
lib/tasks/gitlab/cleanup.rake
lib/tasks/gitlab/bulk_add_permission.rake
lib/tasks/gitlab/backup.rake
lib/tasks/gitlab/info.rake
lib/tasks/gitlab/enable_automerge.rake
lib/tasks/gitlab/generate_docs.rake

ええと、とりあえず lib/tasks/sidekiq.rake は /etc/init.d/gitlab で云々されています。以下な記述があります。

SIDEKIQ_PID="$PID_PATH/sidekiq.pid"
STOP_SIDEKIQ="RAILS_ENV=production bundle exec rake sidekiq:stop"
START_SIDEKIQ="RAILS_ENV=production bundle exec rake sidekiq:start"

で、start で以下とか

      sudo -u gitlab -H bash -l -c "mkdir -p $PID_PATH && $START_SIDEKIQ  > /dev/null  2>&1 &"

stop で以下とか

    sudo -u gitlab -H bash -l -c "mkdir -p $PID_PATH && $STOP_SIDEKIQ  > /dev/null  2>&1 &"

lib/tasks/sidkiq.rake が以下になっています。

$ cat lib/tasks/sidekiq.rake 
namespace :sidekiq do
  desc "GITLAB | Stop sidekiq"
  task :stop do
    run "bundle exec sidekiqctl stop #{pidfile}"
  end

  desc "GITLAB | Start sidekiq"
  task :start do
    run "nohup bundle exec sidekiq -q post_receive,mailer,system_hook,common,default -e #{Rails.env} -P #{pidfile} >> #{Rails.root.join("log", "sidekiq.log")} 2>&1 &"
  end

  def pidfile
    Rails.root.join("tmp", "pids", "sidekiq.pid")
  end
end

sidekiq 云々は別途確認ってことで。
あと、lib/tasks/travis.rake ってのもあるんですが中身が以下。

$ cat lib/tasks/travis.rake 
desc "Travis run tests"
task :travis => [
  :spinach,
  :spec
]

これはこれで謎ですね。つうか travis-ci にアカウント作って試験できるか確認してみたいですね。試しに https://travis-ci.org/ に行ってみたら github なアカウントで大丈夫なのか。別途 folk して云々してみよ。
つうかこの記述自体が謎。配列? シンボル? spinach で grep してみたのが以下。

$ find |xargs grep spinach
./Guardfile:guard 'spinach' do
./features/support/env.rb:require 'spinach/capybara'
./Gemfile:  gem 'spinach-rails'
./Gemfile:  gem 'guard-spinach'
./lib/tasks/travis.rake:  :spinach,
./lib/tasks/gitlab/test.rake:  desc "GITLAB | Run both spinach and rspec"
./lib/tasks/gitlab/test.rake:  task :test => ['spinach', 'spec']
./Gemfile.lock:    guard-spinach (0.0.2)
./Gemfile.lock:      spinach
./Gemfile.lock:    spinach (0.5.2)
./Gemfile.lock:    spinach-rails (0.1.8)
./Gemfile.lock:      spinach (>= 0.4)
./Gemfile.lock:  guard-spinach
./Gemfile.lock:  spinach-rails

あら、gitlab:test でも同様の記述がありますね。spinach て何かな。別途確認の方向ってことで一旦スルー。以下控え。

gitlab 方面

なんか微妙に gdgd 気味です。とりあえず rake --tasks から gitlab なナニを抜きだしてみました。

$ rake --tasks|grep gitlab
rake gitlab:app:check                         # GITLAB | Check the configuration of the GitLab Rails app
rake gitlab:backup:create                     # GITLAB | Create a backup of the GitLab system
rake gitlab:backup:restore                    # GITLAB | Restore a previously created backup
rake gitlab:check                             # GITLAB | Check the configuration of GitLab and its environment
rake gitlab:cleanup:config                    # GITLAB | Cleanup | Clean gitolite config
rake gitlab:cleanup:dirs                      # GITLAB | Cleanup | Clean namespaces
rake gitlab:cleanup:repos                     # GITLAB | Cleanup | Clean respositories
rake gitlab:enable_automerge                  # GITLAB | Enable auto merge
rake gitlab:enable_namespaces                 # GITLAB | Enable usernames and namespaces for user projects
rake gitlab:env:check                         # GITLAB | Check the configuration of the environment
rake gitlab:env:info                          # GITLAB | Show information about GitLab and its environment
rake gitlab:generate_docs                     # GITLAB | Generate sdocs for project
rake gitlab:gitolite:check                    # GITLAB | Check the configuration of Gitolite
rake gitlab:gitolite:update_keys              # GITLAB | Rebuild each user key in Gitolite config
rake gitlab:gitolite:update_repos             # GITLAB | Rebuild each project in Gitolite config
rake gitlab:import:all_users_to_all_projects  # GITLAB | Add all users to all projects (admin users are added as masters)
rake gitlab:import:repos                      # GITLAB | Import bare repositories from git_host -> base_path into GitLab project instance
rake gitlab:import:user_to_projects[email]    # GITLAB | Add a specific user to all projects (as a developer)
rake gitlab:satellites:create                 # GITLAB | Create satellite repos
rake gitlab:setup                             # GITLAB | Setup production application
rake gitlab:sidekiq:check                     # GITLAB | Check the configuration of Sidekiq
rake gitlab:test                              # GITLAB | Run both spinach and rspec

あらら、desc な記述だろうと思うのですが面白い task がありますね。列挙してみます。ちなみに awk で云々は以下で。

$ rake --tasks|grep gitlab|awk '{for(i=6;i<NF;i++){printf("%s ",$i)}print $NF}'

出力を以下に箇条書きで列挙。

  • Check the configuration of the GitLab Rails app
  • Create a backup of the GitLab system
  • Restore a previously created backup
  • Check the configuration of GitLab and its environment
  • Cleanup | Clean gitolite config
  • Cleanup | Clean namespaces
  • Cleanup | Clean respositories
  • Enable auto merge
  • Enable usernames and namespaces for user projects
  • Check the configuration of the environment
  • Show information about GitLab and its environment
  • Generate sdocs for project
  • Check the configuration of Gitolite
  • Rebuild each user key in Gitolite config
  • Rebuild each project in Gitolite config
  • Add all users to all projects (admin users are added as masters)
  • Import bare repositories from git_host -> base_path into GitLab project instance
  • Add a specific user to all projects (as a developer)
  • Create satellite repos
  • Setup production application
  • Check the configuration of Sidekiq
  • Run both spinach and rspec

例えば "Setup production application" なソレは lib/tasks/gitlab/setup.rake な模様。記述が以下。

namespace :gitlab do
  desc "GITLAB | Setup production application"
  task :setup => :environment do
    setup
  end

  def setup
    warn_user_is_not_gitlab

    puts "This will create the necessary database tables and seed the database."
    puts "You will lose any previous data stored in the database."
    ask_to_continue
    puts ""

    Rake::Task["db:setup"].invoke
    Rake::Task["db:seed_fu"].invoke
    Rake::Task["gitlab:enable_automerge"].invoke
  rescue Gitlab::TaskAbortedByUserError
    puts "Quitting...".red
    exit 1
  end
end

setup なソレの先頭にある warn_user_is_not_gitlab は以下らしい。

$ find|xargs grep warn_user_is_not_gitlab
./lib/tasks/gitlab/task_helpers.rake:  def warn_user_is_not_gitlab

定義が以下。

  def warn_user_is_not_gitlab
    unless @warned_user_not_gitlab
      gitlab_user = Gitlab.config.gitlab.user
      current_user = run("whoami").chomp
      unless current_user == gitlab_user
        puts "#{Colored.color(:black)+Colored.color(:on_yellow)} Warning #{Colored.extra(:clear)}"
        puts "  You are running as user #{current_user.magenta}, we hope you know what you are doing."
        puts "  Things may work\/fail for the wrong reasons."
        puts "  For correct results you should run this as user #{gitlab_user.magenta}."
        puts ""
      end
      @warned_user_not_gitlab = true
    end
  end

このあたり掘削してみると面白そうなんですが本質からは全然離れているというアレ。とりあえず、gitlab 配下は継続して掘ります。
あと、

  • sidekiq の関係
  • gitlab を folk して travis-ci でなんちゃら

とか明日以降でいろいろ、ってことで。あるいは以下とか