Class: ContainerRegistry::Tag
- Inherits:
-
Object
- Object
- ContainerRegistry::Tag
- Includes:
- Gitlab::Utils::StrongMemoize
- Defined in:
- lib/container_registry/tag.rb
Instance Attribute Summary collapse
- #created_at ⇒ Object
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#repository ⇒ Object
readonly
Returns the value of attribute repository.
-
#updated_at ⇒ Object
Returns the value of attribute updated_at.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #config ⇒ Object
- #config_blob ⇒ Object
- #digest ⇒ Object
-
#force_created_at_from_iso8601(string_value) ⇒ Object
this function will set and memoize a created_at to avoid a #config_blob call.
-
#initialize(repository, name) ⇒ Tag
constructor
A new instance of Tag.
- #latest? ⇒ Boolean
- #layers ⇒ Object
- #location ⇒ Object
- #manifest ⇒ Object
- #path ⇒ Object
- #put(digests) ⇒ Object
-
#total_size ⇒ Object
rubocop: disable CodeReuse/ActiveRecord.
-
#unsafe_delete ⇒ Object
Deletes the image associated with this tag Note this will delete the image and all tags associated with it.
- #v1? ⇒ Boolean
- #v2? ⇒ Boolean
- #valid? ⇒ Boolean
Constructor Details
#initialize(repository, name) ⇒ Tag
Returns a new instance of Tag.
13 14 15 16 |
# File 'lib/container_registry/tag.rb', line 13 def initialize(repository, name) @repository = repository @name = name end |
Instance Attribute Details
#created_at ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/container_registry/tag.rb', line 76 def created_at return @created_at if @created_at strong_memoize(:memoized_created_at) do next unless config DateTime.rfc3339(config['created']) rescue ArgumentError nil end end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/container_registry/tag.rb', line 7 def name @name end |
#repository ⇒ Object (readonly)
Returns the value of attribute repository.
7 8 9 |
# File 'lib/container_registry/tag.rb', line 7 def repository @repository end |
#updated_at ⇒ Object
Returns the value of attribute updated_at.
7 8 9 |
# File 'lib/container_registry/tag.rb', line 7 def updated_at @updated_at end |
Instance Method Details
#[](key) ⇒ Object
48 49 50 51 52 |
# File 'lib/container_registry/tag.rb', line 48 def [](key) return unless manifest manifest[key] end |
#config ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/container_registry/tag.rb', line 68 def config return unless config_blob&.data strong_memoize(:config) do ContainerRegistry::Config.new(self, config_blob) end end |
#config_blob ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/container_registry/tag.rb', line 60 def config_blob return unless manifest && manifest['config'] strong_memoize(:config_blob) do repository.blob(manifest['config']) end end |
#digest ⇒ Object
54 55 56 57 58 |
# File 'lib/container_registry/tag.rb', line 54 def digest strong_memoize(:digest) do client.repository_tag_digest(repository.path, name) end end |
#force_created_at_from_iso8601(string_value) ⇒ Object
this function will set and memoize a created_at to avoid a #config_blob call.
90 91 92 93 94 95 96 97 98 |
# File 'lib/container_registry/tag.rb', line 90 def force_created_at_from_iso8601(string_value) date = begin DateTime.iso8601(string_value) rescue ArgumentError nil end instance_variable_set(ivar(:memoized_created_at), date) end |
#latest? ⇒ Boolean
22 23 24 |
# File 'lib/container_registry/tag.rb', line 22 def latest? name == "latest" end |
#layers ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/container_registry/tag.rb', line 111 def layers return unless manifest strong_memoize(:layers) do layers = manifest['layers'] || manifest['fsLayers'] layers.map do |layer| repository.blob(layer) end end end |
#location ⇒ Object
44 45 46 |
# File 'lib/container_registry/tag.rb', line 44 def location "#{repository.location}:#{name}" end |
#manifest ⇒ Object
34 35 36 37 38 |
# File 'lib/container_registry/tag.rb', line 34 def manifest strong_memoize(:manifest) do client.repository_manifest(repository.path, name) end end |
#path ⇒ Object
40 41 42 |
# File 'lib/container_registry/tag.rb', line 40 def path "#{repository.path}:#{name}" end |
#put(digests) ⇒ Object
123 124 125 |
# File 'lib/container_registry/tag.rb', line 123 def put(digests) repository.client.put_tag(repository.path, name, digests) end |
#total_size ⇒ Object
rubocop: disable CodeReuse/ActiveRecord
128 129 130 131 132 |
# File 'lib/container_registry/tag.rb', line 128 def total_size return unless layers layers.sum(&:size) if v2? end |
#unsafe_delete ⇒ Object
Deletes the image associated with this tag Note this will delete the image and all tags associated with it. Consider using DeleteTagsService instead.
138 139 140 141 142 |
# File 'lib/container_registry/tag.rb', line 138 def unsafe_delete return unless digest client.delete_repository_tag_by_digest(repository.path, digest) end |
#v1? ⇒ Boolean
26 27 28 |
# File 'lib/container_registry/tag.rb', line 26 def v1? manifest && manifest['schemaVersion'] == 1 end |
#v2? ⇒ Boolean
30 31 32 |
# File 'lib/container_registry/tag.rb', line 30 def v2? manifest && manifest['schemaVersion'] == 2 end |
#valid? ⇒ Boolean
18 19 20 |
# File 'lib/container_registry/tag.rb', line 18 def valid? manifest.present? end |