Class: ContainerRegistry::Tag

Inherits:
Object
  • Object
show all
Includes:
Gitlab::Utils::StrongMemoize
Defined in:
lib/container_registry/tag.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Constructor Details

#initialize(repository, name) ⇒ Tag

Returns a new instance of Tag.


12
13
14
# File 'lib/container_registry/tag.rb', line 12

def initialize(repository, name)
  @repository, @name = repository, name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name


7
8
9
# File 'lib/container_registry/tag.rb', line 7

def name
  @name
end

#repositoryObject (readonly)

Returns the value of attribute repository


7
8
9
# File 'lib/container_registry/tag.rb', line 7

def repository
  @repository
end

Instance Method Details

#[](key) ⇒ Object


46
47
48
49
50
# File 'lib/container_registry/tag.rb', line 46

def [](key)
  return unless manifest

  manifest[key]
end

#configObject


66
67
68
69
70
71
72
# File 'lib/container_registry/tag.rb', line 66

def config
  return unless config_blob&.data

  strong_memoize(:config) do
    ContainerRegistry::Config.new(self, config_blob)
  end
end

#config_blobObject


58
59
60
61
62
63
64
# File 'lib/container_registry/tag.rb', line 58

def config_blob
  return unless manifest && manifest['config']

  strong_memoize(:config_blob) do
    repository.blob(manifest['config'])
  end
end

#created_atObject


74
75
76
77
78
79
80
81
82
# File 'lib/container_registry/tag.rb', line 74

def created_at
  return unless config

  strong_memoize(:created_at) do
    DateTime.rfc3339(config['created'])
  rescue ArgumentError
    nil
  end
end

#digestObject


52
53
54
55
56
# File 'lib/container_registry/tag.rb', line 52

def digest
  strong_memoize(:digest) do
    client.repository_tag_digest(repository.path, name)
  end
end

#latest?Boolean

Returns:

  • (Boolean)

20
21
22
# File 'lib/container_registry/tag.rb', line 20

def latest?
  name == "latest"
end

#layersObject


84
85
86
87
88
89
90
91
92
93
94
# File 'lib/container_registry/tag.rb', line 84

def layers
  return unless manifest

  strong_memoize(:layers) do
    layers = manifest['layers'] || manifest['fsLayers']

    layers.map do |layer|
      repository.blob(layer)
    end
  end
end

#locationObject


42
43
44
# File 'lib/container_registry/tag.rb', line 42

def location
  "#{repository.location}:#{name}"
end

#manifestObject


32
33
34
35
36
# File 'lib/container_registry/tag.rb', line 32

def manifest
  strong_memoize(:manifest) do
    client.repository_manifest(repository.path, name)
  end
end

#pathObject


38
39
40
# File 'lib/container_registry/tag.rb', line 38

def path
  "#{repository.path}:#{name}"
end

#put(digests) ⇒ Object


96
97
98
# File 'lib/container_registry/tag.rb', line 96

def put(digests)
  repository.client.put_tag(repository.path, name, digests)
end

#total_sizeObject

rubocop: disable CodeReuse/ActiveRecord


101
102
103
104
105
# File 'lib/container_registry/tag.rb', line 101

def total_size
  return unless layers

  layers.map(&:size).sum if v2?
end

#unsafe_deleteObject

Deletes the image associated with this tag Note this will delete the image and all tags associated with it. Consider using DeleteTagsService instead.


111
112
113
114
115
# File 'lib/container_registry/tag.rb', line 111

def unsafe_delete
  return unless digest

  client.delete_repository_tag_by_digest(repository.path, digest)
end

#v1?Boolean

Returns:

  • (Boolean)

24
25
26
# File 'lib/container_registry/tag.rb', line 24

def v1?
  manifest && manifest['schemaVersion'] == 1
end

#v2?Boolean

Returns:

  • (Boolean)

28
29
30
# File 'lib/container_registry/tag.rb', line 28

def v2?
  manifest && manifest['schemaVersion'] == 2
end

#valid?Boolean

Returns:

  • (Boolean)

16
17
18
# File 'lib/container_registry/tag.rb', line 16

def valid?
  manifest.present?
end