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



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

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

.run(git_url) ⇒ Object



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

def self.run(git_url)
    commands=Array.new()
    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.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{|cmd_string|
                commands << Rakkit::Command.new(cmd_string)
            }
        end
    end
    FileUtils.rm_rf(local_dir)
    commands
end