Class: Horatio::Releaser

Inherits:
Object
  • Object
show all
Defined in:
lib/horatio/releaser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Releaser

Returns a new instance of Releaser.



8
9
10
11
12
13
14
# File 'lib/horatio/releaser.rb', line 8

def initialize(options={})
  @options = options
  @registry = @options['registry']
  @release = Horatio::Detector.detect
  color { Log.info "detected #{@release.description}" }
  @vcs = Horatio::VCS.detect(@options)
end

Instance Attribute Details

#releaseObject

Returns the value of attribute release.



6
7
8
# File 'lib/horatio/releaser.rb', line 6

def release
  @release
end

#vcsObject

Returns the value of attribute vcs.



6
7
8
# File 'lib/horatio/releaser.rb', line 6

def vcs
  @vcs
end

Instance Method Details

#generate_artifactObject



16
17
18
19
20
21
22
23
24
# File 'lib/horatio/releaser.rb', line 16

def generate_artifact
  contents = JSON.pretty_generate({'name'             => @release.name,
                                   'version'          => "#{@release.version}-#{@vcs.latest_revision}",
                                   'app_version'      => @release.version,
                                   'source_revision'  => @vcs.latest_revision,
                                   'url'              => "#{@registry}/#{@release.name}:#{@release.version}-#{@vcs.latest_revision}"})

  File.open('docker-image.json', 'w') { |f | f.write(contents); }
end

#runObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/horatio/releaser.rb', line 26

def run
  color { Log.info "Running Docker build for #{@release.name}-#{@release.version}" }

  @release.validate

  color { Log.info "latest revision is #{@vcs.latest_revision }" }

  no_cache = ENV['DOCKER_BUILD_NO_CACHE'] ? "--no-cache " : ""

  run_sh "docker build " + no_cache + "-t #{@registry}/#{@release.name}:#{@release.version}-#{@vcs.latest_revision} ."
  run_sh "docker push #{@registry}/#{@release.name}"

  generate_artifact

  @release.increment(self)

  return true
end