Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
crono: update digests when creating tags
Browse files Browse the repository at this point in the history
In this commit the CatalogJob task will also update the manifest digests of
the tags that are to be created.

See #822

Signed-off-by: Miquel Sabaté Solà <[email protected]>
  • Loading branch information
mssola committed Apr 18, 2016
1 parent 77c7b15 commit 6127343
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
10 changes: 9 additions & 1 deletion app/models/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions spec/models/repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand All @@ -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"] }
Expand Down

0 comments on commit 6127343

Please sign in to comment.