Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

provider ignoring context if a dockerfile exists in the current directory #592

Open
domoran opened this issue Jan 3, 2024 · 0 comments
Open

Comments

@domoran
Copy link

domoran commented Jan 3, 2024

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

  1. terraform apply

The docker build fails with the error message "failed to create LLB definition: the Dockerfile cannot be empty"

  1. 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"
#}
  1. terraform apply
    Now the build works.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant