-
Notifications
You must be signed in to change notification settings - Fork 9.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
provider/docker: Add support for a list of pull_triggers within the docker_image resource. #10845
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -188,15 +188,11 @@ func findImage(d *schema.ResourceData, client *dc.Client) (*dc.APIImages, error) | |
return nil, fmt.Errorf("Empty image name is not allowed") | ||
} | ||
|
||
foundImage := searchLocalImages(data, imageName) | ||
|
||
if foundImage == nil { | ||
if err := pullImage(&data, client, imageName); err != nil { | ||
return nil, fmt.Errorf("Unable to pull image %s: %s", imageName, err) | ||
} | ||
if err := pullImage(&data, client, imageName); err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this functionality is correct in either case. |
||
return nil, fmt.Errorf("Unable to pull image %s: %s", imageName, err) | ||
} | ||
|
||
foundImage = searchLocalImages(data, imageName) | ||
foundImage := searchLocalImages(data, imageName) | ||
if foundImage != nil { | ||
return foundImage, nil | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,6 +89,22 @@ func TestAccDockerImage_data(t *testing.T) { | |
}) | ||
} | ||
|
||
func TestAccDockerImage_data_pull_trigger(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
PreventPostDestroyRefresh: true, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: testAccDockerImageFromDataConfigWithPullTrigger, | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestMatchResourceAttr("docker_image.foobarbazoo", "latest", contentDigestRegexp), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDockerImageDestroy(s *terraform.State) error { | ||
for _, rs := range s.RootModule().Resources { | ||
if rs.Type != "docker_image" { | ||
|
@@ -131,6 +147,16 @@ data "docker_registry_image" "foobarbaz" { | |
} | ||
resource "docker_image" "foobarbaz" { | ||
name = "${data.docker_registry_image.foobarbaz.name}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be useful to have 2 tests - 1 for pull_trigger and 1 for pull_triggers There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can do this, sure. |
||
pull_trigger = "${data.docker_registry_image.foobarbaz.sha256_digest}" | ||
pull_triggers = ["${data.docker_registry_image.foobarbaz.sha256_digest}"] | ||
} | ||
` | ||
|
||
const testAccDockerImageFromDataConfigWithPullTrigger = ` | ||
data "docker_registry_image" "foobarbazoo" { | ||
name = "alpine:3.1" | ||
} | ||
resource "docker_image" "foobarbazoo" { | ||
name = "${data.docker_registry_image.foobarbazoo.name}" | ||
pull_trigger = "${data.docker_registry_image.foobarbazoo.sha256_digest}" | ||
} | ||
` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we deleting the searchLocalImages check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was removed for two reasons, first because we do not need to care about if the image is found locally or not. A docker pull on an image that you already have just results in a no-op. Second, this is actually incorrect in the case of someone using a docker-swarm. If you search local images in the swarm, it will return any image on any host in the swarm. Because of this behavior, it was previously possible for terraform to try and start a container on a swarm host that did not have the image pulled, which is incorrect.