Class: Baleen::Builder
- Inherits:
-
Object
- Object
- Baleen::Builder
- Defined in:
- lib/baleen/builder.rb
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(project, docker_url) ⇒ Builder
constructor
A new instance of Builder.
Constructor Details
#initialize(project, docker_url) ⇒ Builder
Returns a new instance of Builder.
8 9 10 11 |
# File 'lib/baleen/builder.rb', line 8 def initialize(project, docker_url) @project = project @docker_url = docker_url end |
Instance Method Details
#build ⇒ Object
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 |
# File 'lib/baleen/builder.rb', line 13 def build config = Configuration.instance url = @project.ci[:url] repo = @project.ci[:repo] tmp_dir = File.join(config.dir, "tmp/build") dir = File.join(tmp_dir, repo) output = StringIO.new connection = Docker::Connection.new(@docker_url, {}) FileUtils.mkdir_p(tmp_dir) if File.exists?(dir) Dir::chdir(dir) `git pull` else `git clone #{url} #{dir}` Dir::chdir(dir) end Gem::Package::TarWriter.new(output) do |tar| Find.find("./") do |f| if File::ftype(f) == "directory" tar.mkdir(f, 0640) else tar.add_file(f, 0640) { |tar_file| tar_file.write(File.open(f){|fl| fl.read})} end end end tar = output.tap(&:rewind).string connection.post('/build', {}, :body => tar) end |