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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent Behavior with Docker Image Build Context in Terraform #652

Open
hsiangjenli opened this issue Oct 24, 2024 · 0 comments
Open

Comments

@hsiangjenli
Copy link

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.9.8  
on linux_amd64

Affected Resource(s)

  • docker_image

Terraform Configuration Files

# Working Configuration
resource "docker_image" "scsb_fastapi" {
  name = "hsiangjenli/scsb-fastapi:${local.current_date}"
  build {
    context    = "."
    dockerfile = "/home/hsiangjenli/Downloads/github/refactor-fastapi/Dockerfile.fastapi"
    build_args = {
      FASTAPI_MODULE_PATH       = "TODO"
      PREPROCESSING_MODULE_PATH = "TODO"
    }
    no_cache = "true"
  }
}
# Non-working Configuration
resource "docker_image" "scsb_fastapi" {
  name = "hsiangjenli/scsb-fastapi:${local.current_date}"
  build {
    context    = "/home/hsiangjenli/Downloads/github"
    dockerfile = "refactor-fastapi/Dockerfile.fastapi"
    build_args = {
      FASTAPI_MODULE_PATH       = "TODO"
      PREPROCESSING_MODULE_PATH = "TODO"
    }
    no_cache = "true"
  }
}

Actual Behaviour

The second configuration throws the following error:

Error: failed to read dockerfile: unexpected EOF

with docker_image.scsb_fastapi,
on main.tf line 13, in resource "docker_image" "scsb_fastapi":
13: resource "docker_image" "scsb_fastapi" {

Steps to Reproduce

  1. Apply the first configuration with terraform apply, which works correctly.
  2. Modify the configuration to the second setup (changing the context path) and run terraform apply again, which results in the "unexpected EOF" error.

Important Factoids

The reason for using the second configuration is to include additional modules from different paths into the Docker image. I’m trying to specify a different context directory for this purpose, but I’m unsure why the second configuration fails while the first works fine.

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