BigW Consortium Gitlab

repository.rb 886 Bytes
Newer Older
1
module ContainerRegistry
2 3 4
  class Repository
    attr_reader :registry, :name

5 6
    delegate :client, to: :registry

7 8 9 10
    def initialize(registry, name)
      @registry, @name = registry, name
    end

11 12 13 14
    def path
      [registry.path, name].compact.join('/')
    end

15
    def tag(tag)
16
      ContainerRegistry::Tag.new(self, tag)
17 18 19 20
    end

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

22 23 24 25 26 27 28 29 30
      @manifest = client.repository_tags(name)
    end

    def valid?
      manifest.present?
    end

    def tags
      return @tags if defined?(@tags)
31
      return [] unless manifest && manifest['tags']
Kamil Trzcinski committed
32

33
      @tags = manifest['tags'].map do |tag|
34
        ContainerRegistry::Tag.new(self, tag)
35 36 37
      end
    end

38 39 40 41
    def blob(config)
      ContainerRegistry::Blob.new(self, config)
    end

42 43
    def delete_tags
      return unless tags
Kamil Trzcinski committed
44

45
      tags.all?(&:delete)
46 47 48
    end
  end
end