provider ignoring context if a dockerfile exists in the current directory
domoran opened this issue ยท 0 comments
Community Note
- Please vote on this issue by adding a ๐ reaction to the original issue to help the community and maintainers prioritize this request
- Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
- If you are interested in working on this issue or have submitted a pull request, please leave a comment
Terraform (and docker Provider) Version
Terraform v1.3.7
on windows_amd64
- provider registry.terraform.io/hashicorp/local v2.4.1
- provider registry.terraform.io/kreuzwerker/docker v3.0.2
Affected Resource(s)
docker_image.image
Terraform Configuration Files
terraform {
required_providers {
docker = {
source = "kreuzwerker/docker"
version = "3.0.2"
}
}
}
provider "docker" {
}
# Comment that out, and the docker provider will resolve the correct Dockerfile!
resource "local_file" "bad_dockerfile" {
content = ""
filename = "${path.module}/Dockerfile"
}
resource "local_file" "dockerfile" {
content = "from ubuntu:latest"
filename = "${path.module}/.context/Dockerfile"
}
resource "docker_image" "image" {
name = "bug"
build {
context = dirname(local_file.dockerfile.filename)
tag = ["webserver:latest"]
}
}
Debug Output
https://gist.github.com/domoran/1188b6754fd497be697cbf54b1a416bb
The relevant part of the log is:
2024-01-03T11:06:49.703+0100 [INFO] provider.terraform-provider-docker_v3.0.2.exe: 2024/01/03 11:06:49 [DEBUG] relDockerfile ..\Dockerfile: timestamp=2024-01-03T11:06:49.702+0100
where the provider is choosing an invalid Dockerfile location, based on the existence of another Dockerfile in the current directory.
Expected Behaviour
The docker provider should look for a Dockerfile inside the context and ignore the dockerfile inside the current directory. The search location should be consistent whether or not that other Dockerfile exists.
Actual Behaviour
When the empty Dockerfile in the current directory exists the docker provider picks up that file (and fails) even though context is set to .context directory.
Steps to Reproduce
terraform apply
The docker build fails with the error message "failed to create LLB definition: the Dockerfile cannot be empty"
terraform destroy
Now comment out the bad dockerfile resource
# Comment that out, and it will work
#resource "local_file" "bad_dockerfile" {
# content = ""
# filename = "${path.module}/Dockerfile"
#}
terraform apply
Now the build works.