Class: Blubber::Tagger
- Inherits:
-
Object
- Object
- Blubber::Tagger
- Defined in:
- lib/blubber/tagger.rb
Class Method Summary collapse
Instance Method Summary collapse
- #branch_name ⇒ Object
-
#initialize(layer:, image_id:, logger: nil) ⇒ Tagger
constructor
A new instance of Tagger.
- #project ⇒ Object
- #run ⇒ Object
- #tags ⇒ Object
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_registry ⇒ Object
9 10 11 |
# File 'lib/blubber/tagger.rb', line 9 def self.docker_registry ENV.fetch('DOCKER_REGISTRY') end |
Instance Method Details
#branch_name ⇒ Object
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 |
#project ⇒ Object
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 |
#run ⇒ Object
19 20 21 22 23 |
# File 'lib/blubber/tagger.rb', line 19 def run logger.info ui.color("#{layer}: PUSHING", :yellow) push end |
#tags ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/blubber/tagger.rb', line 25 def ||= begin = [] << commit unless dirty? << branch_name.gsub(/[^\w.-]/, '_') unless branch_name.empty? << 'latest' if branch_name == 'master' end << File.read("#{layer}/Dockerfile").scan(/LABEL version=([\w][\w.-]*)/) .flatten.map { |t| "#{t}#{dirty? ? '-dirty' : ''}" } end end |