gitaly.rake 2.4 KB
Newer Older
1 2
# frozen_string_literal: true

3 4
namespace :gitlab do
  namespace :gitaly do
5 6
    desc 'GitLab | Gitaly | Clone and checkout gitaly'
    task :clone, [:dir, :storage_path, :repo] => :gitlab_environment do |t, args|
7
      warn_user_is_not_gitlab
8

9 10 11
      unless args.dir.present? && args.storage_path.present?
        abort %(Please specify the directory where you want to install gitaly and the path for the default storage
Usage: rake "gitlab:gitaly:install[/installation/dir,/storage/path]")
12
      end
13

14
      args.with_defaults(repo: 'https://gitlab.com/gitlab-org/gitaly.git')
15

16
      version = Gitlab::GitalyClient.expected_server_version
17

18
      checkout_or_clone_version(version: version, repo: args.repo, target_dir: args.dir, clone_opts: %w[--depth 1])
19 20 21 22 23
    end

    desc 'GitLab | Gitaly | Install or upgrade gitaly'
    task :install, [:dir, :storage_path, :repo] => [:gitlab_environment, 'gitlab:gitaly:clone'] do |t, args|
      warn_user_is_not_gitlab
24

25
      storage_paths = { 'default' => args.storage_path }
26
      Gitlab::SetupHelper::Gitaly.create_configuration(args.dir, storage_paths)
27 28 29 30

      # In CI we run scripts/gitaly-test-build
      next if ENV['CI'].present?

31
      Dir.chdir(args.dir) do
32 33 34 35 36 37 38 39
        Bundler.with_original_env do
          env = { "RUBYOPT" => nil, "BUNDLE_GEMFILE" => nil }

          if Rails.env.test?
            env["GEM_HOME"] = Bundler.bundle_path.to_s
            env["BUNDLE_DEPLOYMENT"] = 'false'
          end

40 41
          output, status = Gitlab::Popen.popen([make_cmd, 'all', 'git'], nil, env)
          raise "Gitaly failed to compile: #{output}" unless status&.zero?
Jacob Vosmaer's avatar
Jacob Vosmaer committed
42
        end
43 44
      end
    end
45 46 47 48 49

    def make_cmd
      _, status = Gitlab::Popen.popen(%w[which gmake])
      status == 0 ? 'gmake' : 'make'
    end
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68

    def warn_gitaly_out_of_date!(gitaly_binary, expected_version)
      binary_version, exit_status = Gitlab::Popen.popen(%W[#{gitaly_binary} -version])

      raise "Failed to run `#{gitaly_binary} -version`" unless exit_status == 0

      binary_version = binary_version.strip

      # See help for `git describe` for format
      git_describe_sha = /g([a-f0-9]{5,40})\z/
      match = binary_version.match(git_describe_sha)

      # Just skip if the version does not have a sha component
      return unless match

      return if expected_version.start_with?(match[1])

      puts "WARNING: #{binary_version.strip} does not exactly match repository version #{expected_version}"
    end
69 70
  end
end