Fix Repository attribute in docker client PullOptions for private registries.

This commit is contained in:
Matti Savolainen 2015-07-03 12:58:05 +03:00
parent 03dc6c4879
commit 09e336a80a
2 changed files with 28 additions and 4 deletions

View File

@ -83,7 +83,7 @@ func pullImage(data *Data, client *dc.Client, image string) error {
splitPortRepo := strings.Split(splitImageName[1], "/")
pullOpts.Registry = splitImageName[0] + ":" + splitPortRepo[0]
pullOpts.Tag = splitImageName[2]
pullOpts.Repository = strings.Join(splitPortRepo[1:], "/")
pullOpts.Repository = pullOpts.Registry + "/" + strings.Join(splitPortRepo[1:], "/")
// It's either registry:port/username/repo, registry:port/repo,
// or repo:tag with default registry
@ -98,7 +98,7 @@ func pullImage(data *Data, client *dc.Client, image string) error {
// registry:port/username/repo or registry:port/repo
default:
pullOpts.Registry = splitImageName[0] + ":" + splitPortRepo[0]
pullOpts.Repository = strings.Join(splitPortRepo[1:], "/")
pullOpts.Repository = pullOpts.Registry + "/" + strings.Join(splitPortRepo[1:], "/")
pullOpts.Tag = "latest"
}

View File

@ -1,9 +1,8 @@
package docker
import (
"testing"
"github.com/hashicorp/terraform/helper/resource"
"testing"
)
func TestAccDockerImage_basic(t *testing.T) {
@ -24,9 +23,34 @@ func TestAccDockerImage_basic(t *testing.T) {
})
}
func TestAddDockerImage_private(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAddDockerPrivateImageConfig,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"docker_image.foobar",
"latest",
"2c40b0526b6358710fd09e7b8c022429268cc61703b4777e528ac9d469a07ca1"),
),
},
},
})
}
const testAccDockerImageConfig = `
resource "docker_image" "foo" {
name = "ubuntu:trusty-20150320"
keep_updated = true
}
`
const testAddDockerPrivateImageConfig = `
resource "docker_image" "foobar" {
name = "gcr.io:443/google_containers/pause:0.8.0"
keep_updated = true
}
`