Skip to content

Commit

Permalink
Correctly starting Selenoid from image with custom registry host and …
Browse files Browse the repository at this point in the history
…port (fixes aerokube#250)
  • Loading branch information
vania-pooh committed Dec 31, 2019
1 parent 39a8e88 commit 4b6650f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
11 changes: 7 additions & 4 deletions selenoid/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ func (c *DockerConfigurator) getImage(name string, version string) *types.ImageS
c.Errorf("Failed to list images: %v", err)
return nil
}
//name = c.getFullyQualifiedImageRef(name)
return findMatchingImage(images, name, version)
}

Expand All @@ -272,10 +273,12 @@ func findMatchingImage(images []types.ImageSummary, name string, version string)
const colon = ":"
for _, tag := range img.RepoTags {
nameAndVersion := strings.Split(tag, colon)
imageName := nameAndVersion[0]
imageVersion := nameAndVersion[1]
if strings.HasSuffix(imageName, name) && (version == "" || version == Latest || version == imageVersion) {
return &img
if len(nameAndVersion) >= 2 {
imageVersion := nameAndVersion[len(nameAndVersion)-1]
imageName := strings.TrimSuffix(tag, colon+imageVersion)
if strings.HasSuffix(imageName, name) && (version == "" || version == Latest || version == imageVersion) {
return &img
}
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions selenoid/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,12 @@ func TestGetSelenoidImage(t *testing.T) {
AssertThat(t, c.getSelenoidImage() == nil, Is{false})
setImageName(selenoidUIImage)
AssertThat(t, c.getSelenoidImage() == nil, Is{true})

const customRegistry = "my-registry.com:443"
c.RegistryUrl = "http://" + customRegistry
AssertThat(t, c.getSelenoidImage() == nil, Is{true})
setImageName(customRegistry + "/" + selenoidImage)
AssertThat(t, c.getSelenoidImage() == nil, Is{false})
}

func TestFindMatchingImage(t *testing.T) {
Expand All @@ -461,6 +467,11 @@ func TestFindMatchingImage(t *testing.T) {
RepoTags: []string{"aerokube/selenoid:1.4.3"},
Created: 300,
}
selenoid120CustomRegistry = types.ImageSummary{
ID: "4",
RepoTags: []string{"my-registry.com:443/aerokube/selenoid:1.2.0"},
Created: 100,
}
)
images := []types.ImageSummary{
selenoid141,
Expand All @@ -470,6 +481,7 @@ func TestFindMatchingImage(t *testing.T) {
Created: 200, //Intentionally using small timestamps
},
selenoid143,
selenoid120CustomRegistry,
}

AssertThat(t, findMatchingImage(images, "unknown-image-name", Latest) == nil, Is{true})
Expand All @@ -486,6 +498,10 @@ func TestFindMatchingImage(t *testing.T) {
foundSelenoidLatest := findMatchingImage(images, "aerokube/selenoid", Latest)
AssertThat(t, foundSelenoidLatest, Not{nil})
AssertThat(t, *foundSelenoidLatest, EqualTo{selenoid143})

foundSelenoidCustomRegistry := findMatchingImage(images, "my-registry.com:443/aerokube/selenoid", "1.2.0")
AssertThat(t, foundSelenoidCustomRegistry, Not{nil})
AssertThat(t, *foundSelenoidCustomRegistry, EqualTo{selenoid120CustomRegistry})
}

func TestIsVideoRecordingSupported(t *testing.T) {
Expand Down

0 comments on commit 4b6650f

Please sign in to comment.