Class: Raykit::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/raykit/runner.rb

Class Method Summary collapse

Class Method Details

.get_build_yaml(directory) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/raykit/runner.rb', line 34

def self.get_build_yaml(directory)
  yaml = ""
  Dir.chdir(directory) do
    yaml = File.open(".gitlab-ci.yml").read if File.exist?(".gitlab-ci.yml")
  end
  yaml
end

.run(git_url) ⇒ Object



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
# File 'lib/raykit/runner.rb', line 7

def self.run(git_url)
  commands = []
  local_dir = Dir.mktmpdir("runner")
  puts "local_dir : #{local_dir}"
  commands << Raykit::Command.new("git clone #{git_url} #{local_dir}")
  Dir.chdir(local_dir) do
    commands << Raykit::Command.new("git log -n 1")
    yaml = get_build_yaml(local_dir)
    build_hash = YAML.safe_load(yaml)
    build_commands = Raykit::Command.parse_yaml_commands(yaml)
    if build_hash.key?("image")
      image = build_hash["image"]
      build_commands.insert(0, "cd home")
      build_commands.insert(1, "git clone #{git_url} build")
      build_commands.insert(2, "cd build")
      build_commands_string = build_commands.join(";")
      commands << Raykit::Command.new("docker run #{image} sh -c \"#{build_commands_string}\"")
    else
      build_commands.each do |cmd_string|
        commands << Rakkit::Command.new(cmd_string)
      end
    end
  end
  FileUtils.rm_rf(local_dir)
  commands
end