BigW Consortium Gitlab

tag.rb 1.46 KB
Newer Older
1
module ContainerRegistry
2 3 4
  class Tag
    attr_reader :repository, :name

5 6
    delegate :registry, :client, to: :repository

7 8 9 10 11 12 13 14 15 16
    def initialize(repository, name)
      @repository, @name = repository, name
    end

    def valid?
      manifest.present?
    end

    def manifest
      return @manifest if defined?(@manifest)
Kamil Trzcinski committed
17

18 19 20
      @manifest = client.repository_manifest(repository.name, name)
    end

21 22 23 24
    def path
      "#{repository.path}:#{name}"
    end

25 26
    def [](key)
      return unless manifest
Kamil Trzcinski committed
27

28 29 30 31 32
      manifest[key]
    end

    def digest
      return @digest if defined?(@digest)
Kamil Trzcinski committed
33

34 35 36
      @digest = client.repository_tag_digest(repository.name, name)
    end

37 38
    def config_blob
      return @config_blob if defined?(@config_blob)
39
      return unless manifest && manifest['config']
Kamil Trzcinski committed
40

41
      @config_blob = repository.blob(manifest['config'])
42 43 44 45
    end

    def config
      return unless config_blob
Kamil Trzcinski committed
46

47
      @config ||= ContainerRegistry::Config.new(self, config_blob)
48 49 50 51
    end

    def created_at
      return unless config
Kamil Trzcinski committed
52

53 54 55 56 57 58
      @created_at ||= DateTime.rfc3339(config['created'])
    end

    def layers
      return @layers if defined?(@layers)
      return unless manifest
Kamil Trzcinski committed
59

60
      @layers = manifest['layers'].map do |layer|
61
        repository.blob(layer)
62 63 64 65 66
      end
    end

    def total_size
      return unless layers
Kamil Trzcinski committed
67

68 69 70 71 72
      layers.map(&:size).sum
    end

    def delete
      return unless digest
Kamil Trzcinski committed
73

74 75 76 77
      client.delete_repository_tag(repository.name, digest)
    end
  end
end