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

Fix Dockerfile not located when added to dockerignore #2272

Merged

Conversation

danvergara
Copy link
Contributor

What does this PR do?

When the user adds Dockerfile to the .dockerignore file, testcontainers is not able to build the image with error:

Error response from daemon: Cannot locate specified Dockerfile

This is because testcontainers doesn't include the Dockerfile to the buildcontext on purpose, it only expects to do so, if it is not included on the ignorefile. The docker client doesn't this either, the Docker cli is aware of this and maintainers have addressed this limitation in this PR long ago as the have tweaked the client to include both files to the build context.

To fix this, I added the .dockerignore file in the current context and the target Dockefile to the Build Context.

includes = append(includes, dockerIgnoreLocation, c.GetDockerfile())

archive.TarOptions struct has a key on it to include files to the archive:

buildContext, err := archive.TarWithOptions(
	c.Context,
	&archive.TarOptions{ExcludePatterns: excluded, IncludeFiles: includes},
)

Why is it important?

The motivation is that some developers don't want to include the Dockerfile to the result image to keep it as minimal as possible.

Related issues

Closes #2203

@danvergara danvergara requested a review from a team as a code owner February 29, 2024 03:27
Copy link

netlify bot commented Feb 29, 2024

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit 434d4f0
🔍 Latest deploy log https://app.netlify.com/sites/testcontainers-go/deploys/65dff990b7d3120008365393
😎 Deploy Preview https://deploy-preview-2272--testcontainers-go.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@danvergara danvergara changed the title Fix dockerfile dockerignore Fix dockerfile not located when added to dockerignore Feb 29, 2024
@danvergara danvergara changed the title Fix dockerfile not located when added to dockerignore Fix Dockerfile not located when added to dockerignore Feb 29, 2024
@danvergara
Copy link
Contributor Author

@mdelapenya is it normal that the Rootless pipeline always fails? I keep seeing it failing across the latest pull requests.

@mdelapenya mdelapenya self-assigned this Feb 29, 2024
Copy link
Collaborator

@mdelapenya mdelapenya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for investigating and submitting a fix. Much appreciated!

@mdelapenya mdelapenya added the bug An issue with the library label Feb 29, 2024
@mdelapenya mdelapenya merged commit 9d8e386 into testcontainers:main Feb 29, 2024
91 checks passed
mdelapenya added a commit to jespino/testcontainers-go that referenced this pull request Mar 1, 2024
* main:
  chore: bump Go version to 1.21 (testcontainers#2292)
  chore(deps): bump github.com/ClickHouse/clickhouse-go/v2 (testcontainers#2226)
  feat: WithLogger ContainerCustomizer support (testcontainers#2259)
  chore(deps): bump github.com/jackc/pgx/v5 in /modules/cockroachdb (testcontainers#2217)
  Move the file and mounts tests into a test package (testcontainers#2270)
  Fix Dockerfile not located when added to dockerignore (testcontainers#2272)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An issue with the library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Cannot locate specified Dockerfile: Dockerfile, will retry
2 participants