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

Commit

Permalink
lib/portus: do not remove all the repos if one fails
Browse files Browse the repository at this point in the history
Right now, the `RegistryClient#catalog` method can erase the DB of all the
repos. This happens when, for some unexpected reason, the
`RegistryClient#add_tags` method fails at retrieving one repository. In this
case, before this patch this method just returned an empty array. After this
patch, repositories that are not found will simply not be added, but the
method will go on adding tags to other repositories.

See #663

Signed-off-by: Miquel Sabaté Solà <[email protected]>
  • Loading branch information
mssola committed Jan 22, 2016
1 parent 296dabe commit 5626ad9
Show file tree
Hide file tree
Showing 3 changed files with 218 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/portus/registry_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ def add_tags(repositories)
result = []
repositories.each do |repo|
res = perform_request("#{repo}/tags/list")
return [] if res.code.to_i != 200
result << JSON.parse(res.body)
result << JSON.parse(res.body) if res.code.to_i == 200
end
result
end
Expand Down
18 changes: 18 additions & 0 deletions spec/lib/portus/registry_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,24 @@ def perform_request(_endpoint, _verb, _authentication)
end
end

it "does not remove all repos just because one of them is failing" do
create(:registry)
create(:admin, username: "portus")

VCR.use_cassette("registry/get_registry_one_fails", record: :none) do
registry = Portus::RegistryClient.new(
registry_server,
false,
"portus",
Rails.application.secrets.portus_password)

catalog = registry.catalog
expect(catalog.length).to be 1
expect(catalog[0]["name"]).to eq "busybox"
expect(catalog[0]["tags"]).to match_array(["latest"])
end
end

it "fails if this version of registry does not implement /v2/_catalog" do
VCR.use_cassette("registry/get_missing_catalog_endpoint", record: :none) do
registry = Portus::RegistryClient.new(
Expand Down
199 changes: 199 additions & 0 deletions spec/vcr_cassettes/registry/get_registry_one_fails.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5626ad9

Please sign in to comment.