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

Constructor Details

#initialize(repository, name, from_api: false) ⇒ Tag

Returns a new instance of Tag.



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

def initialize(repository, name, from_api: false)
  @repository = repository
  @name = name
  @from_api = from_api
end

Instance Attribute Details

#created_atObject



92
93
94
95
96
97
98
99
100
101
102
# File 'lib/container_registry/tag.rb', line 92

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

#manifest_digest=(value) ⇒ Object (writeonly)

Sets the attribute manifest_digest

Parameters:

  • value

    the value to set the attribute manifest_digest to.



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

def manifest_digest=(value)
  @manifest_digest = value
end

#media_typeObject

Returns the value of attribute media_type.



9
10
11
# File 'lib/container_registry/tag.rb', line 9

def media_type
  @media_type
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#published_atObject

Returns the value of attribute published_at.



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

def published_at
  @published_at
end

#referrersObject

Returns the value of attribute referrers.



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

def referrers
  @referrers
end

#repositoryObject (readonly)

Returns the value of attribute repository.



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

def repository
  @repository
end

#revisionObject



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

def revision
  @revision || config_blob&.revision
end

#total_sizeObject



139
140
141
142
143
144
145
# File 'lib/container_registry/tag.rb', line 139

def total_size
  return @total_size if @total_size

  return unless layers

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

#updated_atObject

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



64
65
66
67
68
# File 'lib/container_registry/tag.rb', line 64

def [](key)
  return unless manifest

  manifest[key]
end

#configObject



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

def config
  return if config_blob&.data.blank?

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

#config_blobObject



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

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

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

#digestObject



70
71
72
73
74
# File 'lib/container_registry/tag.rb', line 70

def digest
  strong_memoize(:digest) do
    @manifest_digest || 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.



106
107
108
109
# File 'lib/container_registry/tag.rb', line 106

def force_created_at_from_iso8601(string_value)
  date = parse_iso8601_string(string_value)
  instance_variable_set(ivar(:memoized_created_at), date)
end

#latest?Boolean

Returns:

  • (Boolean)


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

def latest?
  name == "latest"
end

#layersObject



123
124
125
126
127
128
129
130
131
132
133
# File 'lib/container_registry/tag.rb', line 123

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



60
61
62
# File 'lib/container_registry/tag.rb', line 60

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

#manifestObject



50
51
52
53
54
# File 'lib/container_registry/tag.rb', line 50

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

#pathObject



56
57
58
# File 'lib/container_registry/tag.rb', line 56

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

#protected_for_delete?(user) ⇒ Boolean

Returns:

  • (Boolean)


169
170
171
172
173
174
175
176
# File 'lib/container_registry/tag.rb', line 169

def protected_for_delete?(user)
  return true unless user
  return false unless protection_rule
  return false if user.can_admin_all_resources?

  max_access = project.team.max_member_access(user.id)
  protection_rule.delete_restricted?(max_access)
end

#protection_ruleObject



156
157
158
159
160
161
162
163
164
165
166
# File 'lib/container_registry/tag.rb', line 156

def protection_rule
  result = nil
  project.container_registry_protection_tag_rules.select(&:mutable?).each do |rule|
    next unless rule.matches_tag_name?(name)

    result ||= ::ContainerRegistry::Protection::TagRule.new
    set_highest_protection_rule_access_level(result, rule)
  end

  result
end

#put(digests) ⇒ Object



135
136
137
# File 'lib/container_registry/tag.rb', line 135

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

#short_revisionObject



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

def short_revision
  return unless revision

  revision[0..8]
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.



150
151
152
153
154
# File 'lib/container_registry/tag.rb', line 150

def unsafe_delete
  return unless digest

  client.delete_repository_tag_by_digest(repository.path, digest)
end

#v1?Boolean

Returns:

  • (Boolean)


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

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

#v2?Boolean

Returns:

  • (Boolean)


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

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

#valid?Boolean

Returns:

  • (Boolean)


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

def valid?
  from_api? || manifest.present?
end