Class: Blubber::Tagger

Inherits:
Object
  • Object
show all
Defined in:
lib/blubber/tagger.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(layer:, image_id:, logger: nil) ⇒ Tagger

Returns a new instance of Tagger.



13
14
15
16
17
# File 'lib/blubber/tagger.rb', line 13

def initialize(layer:, image_id:, logger: nil)
  @layer = layer
  @image_id = image_id
  @logger = logger
end

Class Method Details

.docker_registryObject



9
10
11
# File 'lib/blubber/tagger.rb', line 9

def self.docker_registry
  ENV.fetch('DOCKER_REGISTRY')
end

Instance Method Details

#branch_nameObject



48
49
50
# File 'lib/blubber/tagger.rb', line 48

def branch_name
  @branch_name ||= ENV['BRANCH_NAME'] || `git rev-parse HEAD | git branch -a --contains | sed -n 2p | cut -d'/' -f 3-`.strip
end

#projectObject



41
42
43
44
45
46
# File 'lib/blubber/tagger.rb', line 41

def project
  [
    Tagger.docker_registry,
    *layer.split('/').select { |p| p[/[a-z0-9]+/] }
  ].join('/')
end

#runObject



19
20
21
22
23
# File 'lib/blubber/tagger.rb', line 19

def run
  logger.info ui.color("#{layer}: PUSHING", :yellow)

  push
end

#tagsObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/blubber/tagger.rb', line 25

def tags
  @tags ||= begin
    tags = []
    tags << commit

    unless dirty?
      tags << branch_name.gsub(/[^\w.-]/, '_') unless branch_name.empty?
      tags << 'latest' if branch_name == 'master'
    end

    tags << File.read("#{layer}/Dockerfile").scan(/LABEL version=([\w][\w.-]*)/)

    tags.flatten.map { |t| "#{t}#{dirty? ? '-dirty' : ''}" }
  end
end