Class: Blubber::Layer

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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_idObject

Returns the value of attribute build_id.



8
9
10
# File 'lib/blubber/layer.rb', line 8

def build_id
  @build_id
end

#directoryObject (readonly)

Returns the value of attribute directory.



7
8
9
# File 'lib/blubber/layer.rb', line 7

def directory
  @directory
end

#nameObject (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_tagObject



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

#buildObject

Actions



17
18
19
# File 'lib/blubber/layer.rb', line 17

def build
  builder.build
end

#build_tagObject



79
80
81
# File 'lib/blubber/layer.rb', line 79

def build_tag
  branch_tag || build_info.commit
end

#cacheObject



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
    cache_tags = []

    if build_info.last_successful_commit
      cache_tags << build_info.last_successful_commit.to_s
    end
    cache_tags << build_tag.to_s if build_tag
    cache_tags << branch_tag.to_s if branch_tag
    cache_tags << 'latest'

    cache_tags
      .map { |tag| "#{project}:#{tag}" }
      .find { |img| runner.run("docker pull #{img}").zero? }
  end
end

#projectObject



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

#pushObject



25
26
27
# File 'lib/blubber/layer.rb', line 25

def push
  builder.push
end

#repoObject

Accessors



30
31
32
# File 'lib/blubber/layer.rb', line 30

def repo
  @repo ||= name.split('/').select { |p| p[/[a-z0-9]+/] }.join('/')
end

#tagObject



21
22
23
# File 'lib/blubber/layer.rb', line 21

def tag
  builder.tag
end

#tagsObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/blubber/layer.rb', line 59

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

    unless build_info.dirty?
      tags << branch_tag if branch_tag
      tags << 'latest' if branch_tag == 'master'
    end

    tags << File.read(directory.join('Dockerfile')).scan(/LABEL version=([\w][\w.-]*)/)

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