Project

General

Profile

Revision c36fdec1

Added by Partha Aji almost 8 years ago

Fixes #10404 - Finds correct repo name for Docker Hub registry

Bug is stated as follows
on centos 7 ->

$ docker version
Client version: 1.5.0-dev
Client API version: 1.18
Go version (client): go1.3.3

$ docker search centos
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
docker.io: docker.io/centos The official build of CentOS. 978 [OK]
docker.io: docker.io/ansible/centos7-ansible Ansible on Centos7 40 [OK]
.....

On fedora 20 ->
$ docker version
Client version: 1.5.0
Client API version: 1.17

$ docker search centos
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
centos The official build of CentOS. 978 [OK]
ansible/centos7-ansible Ansible on Centos7 40 [OK]
......

Note the "docker.io: " prefix for the centos 7 name columns
http://rhelblog.redhat.com/2015/04/15/understanding-the-changes-to-docker-search-and-docker-pull-in-red-hat-enterprise-linux-7-1/
has details on why thats the case.

When you ask foreman-docker "search centos from docker hub", it gives
you different names based on whether the docker compute resource is
running on el7 or fedora 20. You then select an image and it shows the
tags for that. Based on your selections it picks "NAME" as the repo name
and chooses the tag. This works for docker compute instance running on
f20 and used to work for docker instance on el7.

Anyway problem is simple -> "docker.io: docker.io/centos" is not a valid
repo name. So foreman-docker has to somehow infer that
"docker.io/centos" is what the repo name should be and strip out
"docker.io: " while it should some how also work for
"my-other-registry.com:4000/cool-repo" and not strip out
"my-other-registry.com:4000".

This commit achieves to do that.

Also removing the hub_url code generation code because we'd need some
logic that converts docker.io/_/centos to
hub.registry.docker.com/_centos_/ and also work for rhel and regular
cases.

View differences:

test/functionals/image_search_controller_test.rb
26 26
    end
27 27
  end
28 28

  
29
  test "centos 7 search responses are handled correctly" do
30
    repository = "registry-fancycorp.rhcloud.com/fancydb-rhel7/fancydb"
31
    repo_full_name = "redhat.com: #{repository}"
32
    request.env["HTTP_ACCEPT"] = "application/javascript"
33
    expected = [{  "description" => "Really fancy database app...",
34
                   "is_official" => true,
35
                   "is_trusted" => true,
36
                   "name" =>  repo_full_name,
37
                   "star_count" => 0
38
                }]
39
    ForemanDocker::Docker.any_instance.expects(:search).returns(expected).at_least_once
40
    get :search_repository, { :search => "centos", :id => @container.id }, set_session_user
41
    assert_response :success
42
    refute response.body.include?(repo_full_name)
43
    assert response.body.include?(repository)
44
  end
45

  
46
  test "fedora search responses are handled correctly" do
47
    repository = "registry-fancycorp.rhcloud.com/fancydb-rhel7/fancydb"
48
    repo_full_name = repository
49
    request.env["HTTP_ACCEPT"] = "application/javascript"
50
    expected = [{ "description" => "Really fancy database app...",
51
                  "is_official" => true,
52
                  "is_trusted" => true,
53
                  "name" =>  repo_full_name,
54
                  "star_count" => 0
55
                }]
56
    ForemanDocker::Docker.any_instance.expects(:search).returns(expected).at_least_once
57
    get :search_repository, { :search => "centos", :id => @container.id }, set_session_user
58
    assert_response :success
59
    assert response.body.include?(repo_full_name)
60
    assert response.body.include?(repository)
61
  end
62

  
29 63
  def assert_response_is_expected
30 64
    assert_response :error
31 65
    assert response.body.include?('An error occured during repository search:')

Also available in: Unified diff