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

.dockerignore white-list pattern causes error #249

Closed
1Mill opened this issue Jul 12, 2021 · 3 comments
Closed

.dockerignore white-list pattern causes error #249

1Mill opened this issue Jul 12, 2021 · 3 comments
Labels
bug Something isn't working pinned r/registry_image
Milestone

Comments

@1Mill
Copy link

1Mill commented Jul 12, 2021

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.0.2

Affected Resource(s)

  • docker_registry_image

Terraform Configuration Files

Folder structure:

  • app
    • empty
    • .dockerignore
    • Dockerfile
    • main.tf

empty

# This this an empty file

.dockerignore

*

!empty

Dockerfile

FROM scratch
COPY empty /empty

main.tf

terraform {
  required_version = "~> 1.0"

  required_providers {
    docker = {
      source  = "kreuzwerker/docker"
      version = ">= 2.14.0"
    }
  }
}

provider "docker" {...}

resource "docker_registry_image" "this" {
  name = "my-image-name"

  build {
    context = abspath(path.module)
  }
}

Debug Output

Expected Behaviour

Successfully build and publish image to registry.

Actual Behaviour

Error: Error building docker image: Error response from daemon: Cannot locate specified Dockerfile: Dockerfile

Steps to Reproduce

  1. terraform init
  2. terraform apply -auto-approve

Important Factoids

  • The error only occurs when using the white-list pattern in the .dockerignore file. This implies to me that something is wrong with the * interpretation / pattern in the module.
@mavogel mavogel added the bug Something isn't working label Jul 12, 2021
@github-actions
Copy link

This issue is stale because it has been open 60 days with no activity.
Remove stale label or comment or this will be closed in 7 days.
If you don't want this issue to be closed, please set the label pinned.

@github-actions github-actions bot added the stale label Sep 11, 2021
@mavogel mavogel added pinned and removed stale labels Sep 13, 2021
@JavaScriptBach
Copy link

JavaScriptBach commented Feb 9, 2022

I think the actual issue is that Dockerfiles must not be excluded before being passed to the API. I ran into a similar issue today (docker build worked fine, but missing Dockerfiles when using this provider) and finally resolved it by changing .dockerignore to not exclude Dockerfiles.

If you take a look at the CLI code, you can see it's excluding Dockerfile and .dockerignore before passing them to the API, along with a bunch of other complicated logic that has no equivalent in the provider. My guess is we need to implement something similar in order for this provider to behave more comparably to docker build.

Specifically what seems to not be implemented in the terraform docker provider is this:

You can even use the .dockerignore file to exclude the Dockerfile and .dockerignore files. These files are still sent to the daemon because it needs them to do its job. But the ADD and COPY instructions do not copy them to the image.

See docs

@Junkern
Copy link
Contributor

Junkern commented Jul 11, 2022

This should be fixed with the newest version https://github.com/kreuzwerker/terraform-provider-docker/releases/tag/v2.18.0
Even added the files you posted for reproduction as a test case :)

@Junkern Junkern closed this as completed Jul 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pinned r/registry_image
Projects
None yet
Development

No branches or pull requests

5 participants