diff --git a/app/models/repository.rb b/app/models/repository.rb index ea6023755..75cb57bfc 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -137,8 +137,16 @@ def self.create_or_update!(repo) to_be_created_tags = repo["tags"] - tags to_be_deleted_tags = tags - repo["tags"] + client = Registry.get.client to_be_created_tags.each do |tag| - Tag.create!(name: tag, repository: repository, author: portus) + # Try to fetch the manifest digest of the tag. + begin + digest = client.manifest(name, tag, true) + rescue + digest = "" + end + + Tag.create!(name: tag, repository: repository, author: portus, digest: digest) logger.tagged("catalog") { logger.info "Created the tag '#{tag}'." } end diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index ebe2e67bc..1c59020cf 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -392,6 +392,10 @@ def get_url(repo, tag) let!(:tag2) { create(:tag, name: "tag2", repository: repo2) } let!(:tag3) { create(:tag, name: "tag3", repository: repo2) } + before :each do + allow_any_instance_of(Portus::RegistryClient).to receive(:manifest).and_return("digest") + end + it "adds and deletes tags accordingly" do # Removes the existing tag and adds two. repo = { "name" => "#{namespace.name}/repo1", "tags" => ["latest", "0.1"] } @@ -417,6 +421,7 @@ def get_url(repo, tag) repo = Repository.create_or_update!(repo) expect(repo.name).to eq "busybox" expect(repo.tags.map(&:name).sort).to match_array(["0.1", "latest"]) + expect(repo.tags.map(&:digest).uniq).to match_array(["digest"]) # Trying to create a repo into an unknown namespace. repo = { "name" => "unknown/repo1", "tags" => ["latest", "0.1"] }