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 .dockerignore for build context copies in later stages #1447

Merged
merged 2 commits into from
Oct 8, 2020
Merged

Fix .dockerignore for build context copies in later stages #1447

merged 2 commits into from
Oct 8, 2020

Conversation

tscni
Copy link
Contributor

@tscni tscni commented Oct 3, 2020

Description

.dockerignore currently isn't being applied to build context copies during later (non-first) stages.
E.g.

FROM scratch AS a
COPY a .

FROM scratch AS b
COPY b . # <-- .dockerignore doesn't apply here

This PR adjusts the .dockerignore integration test to surface the issue and fixes it by refactoring the excluded file handling.
Instead of setting more global state, this replaces it with a FileContext struct (containing a root and excluded files), and passes that from the build start down to all relevant commands / functions.
A COPY --from then simply overwrites the FileContext without any excluded files. The handling around IsFirstStage is no longer necessary.

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

  • Includes unit tests
    Doesn't seem necessary.
  • Adds integration tests if needed.
    Well, a modification really.

See the contribution guide for more details.

Reviewer Notes

  • The code flow looks good.
  • Unit tests and or integration tests added.

Release Notes

Describe any changes here so maintainer can include it in the release notes, or delete this block.

Fix .dockerignore for build context copies in later stages

.dockerignore should continue to apply when copying from the build context in later stages, but it currently doesn't
This new FileContext struct allows much cleaner handling of context specific file exclusions.
The global excluded file state is no longer needed.

Additionally this also fixes the issue where excluded files aren't being applied for build context copies in later build stages.
@googlebot googlebot added the cla: yes CLA signed by all commit authors label Oct 3, 2020
@tejal29 tejal29 merged commit 5f4e2f1 into GoogleContainerTools:master Oct 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes CLA signed by all commit authors
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants