Class: Blubber::Layer
- Inherits:
-
Object
- Object
- Blubber::Layer
- Defined in:
- lib/blubber/layer.rb
Instance Attribute Summary collapse
-
#build_id ⇒ Object
Returns the value of attribute build_id.
-
#directory ⇒ Object
readonly
Returns the value of attribute directory.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #branch_tag ⇒ Object
-
#build ⇒ Object
Actions.
- #build_tag ⇒ Object
- #cache ⇒ Object
-
#initialize(context:, directory:, name:) ⇒ Layer
constructor
A new instance of Layer.
- #project ⇒ Object
- #project_tag(tag) ⇒ Object
- #push ⇒ Object
-
#repo ⇒ Object
Accessors.
- #tag ⇒ Object
- #tags ⇒ Object
Constructor Details
#initialize(context:, directory:, name:) ⇒ Layer
Returns a new instance of Layer.
10 11 12 13 14 |
# File 'lib/blubber/layer.rb', line 10 def initialize(context:, directory:, name:) @context = context @directory = Pathname.new(directory) @name = name end |
Instance Attribute Details
#build_id ⇒ Object
Returns the value of attribute build_id.
8 9 10 |
# File 'lib/blubber/layer.rb', line 8 def build_id @build_id end |
#directory ⇒ Object (readonly)
Returns the value of attribute directory.
7 8 9 |
# File 'lib/blubber/layer.rb', line 7 def directory @directory end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/blubber/layer.rb', line 7 def name @name end |
Instance Method Details
#branch_tag ⇒ Object
75 76 77 |
# File 'lib/blubber/layer.rb', line 75 def branch_tag filter(build_info.branch_name) unless build_info.branch_name.empty? end |
#build ⇒ Object
Actions
17 18 19 |
# File 'lib/blubber/layer.rb', line 17 def build builder.build end |
#build_tag ⇒ Object
79 80 81 |
# File 'lib/blubber/layer.rb', line 79 def build_tag branch_tag || build_info.commit end |
#cache ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/blubber/layer.rb', line 42 def cache @cache ||= begin = [] if build_info.last_successful_commit << build_info.last_successful_commit.to_s end << build_tag.to_s if build_tag << branch_tag.to_s if branch_tag << 'latest' .map { |tag| "#{project}:#{tag}" } .find { |img| runner.run("docker pull #{img}").zero? } end end |
#project ⇒ Object
34 35 36 |
# File 'lib/blubber/layer.rb', line 34 def project "#{context.docker_registry}/#{repo}" end |
#project_tag(tag) ⇒ Object
38 39 40 |
# File 'lib/blubber/layer.rb', line 38 def project_tag(tag) "#{project}:#{tag}" end |
#push ⇒ Object
25 26 27 |
# File 'lib/blubber/layer.rb', line 25 def push builder.push end |
#repo ⇒ Object
Accessors
30 31 32 |
# File 'lib/blubber/layer.rb', line 30 def repo @repo ||= name.split('/').select { |p| p[/[a-z0-9]+/] }.join('/') end |
#tag ⇒ Object
21 22 23 |
# File 'lib/blubber/layer.rb', line 21 def tag builder.tag end |
#tags ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/blubber/layer.rb', line 59 def @tags ||= begin = [] << build_info.commit unless build_info.dirty? << branch_tag if branch_tag << 'latest' if branch_tag == 'master' end << File.read(directory.join('Dockerfile')).scan(/LABEL version=([\w][\w.-]*)/) .flatten.map { |t| "#{t}#{build_info.dirty? ? '-dirty' : ''}" } end end |