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

Commit

Permalink
Update the image ID when a tag has been pushed
Browse files Browse the repository at this point in the history
Fixes #1034

Signed-off-by: Miquel Sabaté Solà <[email protected]>
  • Loading branch information
mssola committed Aug 31, 2016
1 parent bf04374 commit 0f29052
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/models/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ def self.add_repo(event, namespace, repo, tag)
repository = Repository.create(namespace: namespace, name: repo)
elsif repository.tags.exists?(name: tag)
# Update digest if the given tag already exists.
_, digest = Repository.id_and_digest_from_event(event, repository.full_name)
id, digest = Repository.id_and_digest_from_event(event, repository.full_name)
tag = repository.tags.find_by(name: tag)
tag.update!(digest: digest, updated_at: Time.current)
tag.update!(image_id: id, digest: digest, updated_at: Time.current)
repository.create_activity(:push, owner: actor, recipient: tag)
return
end
Expand Down
19 changes: 19 additions & 0 deletions spec/models/repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,25 @@ def get_url(repo, tag)
expect(tag.digest).to eq("bar")
expect(tag.updated_at).to_not eq(ua)
end

it "updates the image id of an already existing tag" do
allow(Repository).to receive(:id_and_digest_from_event).and_return(["image_id", "foo"])
event = { "actor" => { "name" => user.username }, "target" => { "digest" => "foo" } }
Repository.add_repo(event, registry.global_namespace, repository_name, tag_name)
expect(Repository.find_by(name: repository_name).tags.first.digest).to eq("foo")

# Making sure that the updated_at column is set in the past.
tag = Repository.find_by(name: repository_name).tags.first
tag.update!(updated_at: 2.hours.ago)
ua = tag.updated_at

allow(Repository).to receive(:id_and_digest_from_event).and_return(["id", "bar"])
Repository.add_repo(event, registry.global_namespace, repository_name, tag_name)
tag = Repository.find_by(name: repository_name).tags.first
expect(tag.image_id).to eq("id")
expect(tag.digest).to eq("bar")
expect(tag.updated_at).to_not eq(ua)
end
end

context "event does not match regexp of manifest" do
Expand Down

0 comments on commit 0f29052

Please sign in to comment.