Open IlyesDemineExtVeolia opened 11 months ago
I found that the build will be retriggered if the content of (file, subfolder, etc) your context folder change, which makes sense because the provider does not know which file in the context folder will be used (e.g COPY
or ADD
could copy them into the image) while building the Dockerfile
.
In my case the build is triggered even if the content has not changed. I suspect that it's auth_config
that causes the rebuild due to changing credentials.
I've also come across this bug. Our use case was to build an image from a dockerfile in a folder src/example
and push it to an AWS ECR repository. We wanted to only rebuild/push image when there were changes to the code in src/example
. However, even with the triggers hash is the same, the docker_image
is being rebuilt every time.
resource "docker_registry_image" "registry_image" {
name = docker_image.image.name
}
resource "docker_image" "image" {
name = "${aws_ecr_repository.repository.repository_url}:latest"
build {
context = "${path.module}/src/example"
}
triggers = {
dir_sha1 = sha1(join("", [for f in fileset(path.module, "src/example/**") : filesha1(f)]))
}
}
Our solution was to rollback to version 2.25.0 of kreuzwerker/docker. (note the above configuration needs changing for this version).
I guess quite a few of us are currently sitting on 2.25.0 because of this.
See also https://github.com/kreuzwerker/terraform-provider-docker/issues/555
@enc In addition this issue there are also #555 and #607 all the same problem might be good to have them in one place and close duplicates...
This issue described in comment by samuelcortinhas is really annoying with CI deployments because virtual machine that runs terraform starts with clean local docker registry so docker_image
resource acts like it was as remotely deleted and terraform tries to recreate it running the docker build again (even though image already exists in remote repo), if we could use docker_registry_image
for building and uploading images like before it would solve this resource recreation problem on every terraform apply that happens during builds. Currently this kind of optimised behaviour is not possible to achieve after changes from version >2.25.0
I opened #607.
@samuelcortinhas I had to update to v3+ becuase v2.5.0 started to throw errors out of nothing. Does it still work for you? I guess I will have to give it a try again because with this bug I am keep rebuilding stuff for nothing.
I am using AWS ECR too.
Boh, I downgraded to v2.25.0
like others and now works again...
I guess we will never update it. :D
Community Note
Terraform (and docker Provider) Version
Affected Resource(s)
docker_image
Terraform Configuration Files
Debug Output
Panic Output
Expected Behaviour
Don't build and deploy if context and dockerfile doesn't change
Actual Behaviour
Build and Deploy at each terraform apply
Steps to Reproduce
terraform apply
Important Factoids
References
0000