summaryrefslogtreecommitdiff
path: root/scripts/gitaly-test-build
blob: e6afadccc7e1f21d633f6da3be36da2f885804d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'fileutils'

require_relative '../spec/support/helpers/gitaly_setup'

# This script assumes tmp/tests/gitaly already contains the correct
# Gitaly version. We just have to compile it and run its 'bundle
# install'. We have this separate script for that to avoid bundle
# poisoning in CI. This script should only be run in CI.
class GitalyTestBuild
  include GitalySetup

  def run
    set_bundler_config

    # If we have the binaries from the cache, we can skip building them again
    if File.exist?(tmp_tests_gitaly_bin_dir)
      GitalySetup::LOGGER.debug "Gitaly binary already built. Skip building...\n"
      # We still need to install the gems in that case
      install_gitaly_gems
    else
      abort 'gitaly build failed' unless build_gitaly
    end

    ensure_gitlab_shell_secret!
    check_gitaly_config!

    # Starting gitaly further validates its configuration
    gitaly_pid = start_gitaly
    gitaly2_pid = start_gitaly2
    praefect_pid = start_praefect
    Process.kill('TERM', gitaly_pid)
    Process.kill('TERM', gitaly2_pid)
    Process.kill('TERM', praefect_pid)

    # Make the 'gitaly' executable look newer than 'GITALY_SERVER_VERSION'.
    # Without this a gitaly executable created in the setup-test-env job
    # will look stale compared to GITALY_SERVER_VERSION.
    FileUtils.touch(File.join(tmp_tests_gitaly_bin_dir, 'gitaly'), mtime: Time.now + (1 << 24))
    FileUtils.touch(File.join(tmp_tests_gitaly_bin_dir, 'praefect'), mtime: Time.now + (1 << 24))
  end
end

GitalyTestBuild.new.run