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

Update the image ID when a tag has been pushed #1054

Merged
merged 1 commit into from
Sep 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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