-
-
Notifications
You must be signed in to change notification settings - Fork 631
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
docker: include file dependencies in docker build context properly. #12758
Conversation
Signed-off-by: Andreas Stenius <andreas.stenius@svenskaspel.se>
Signed-off-by: Andreas Stenius <andreas.stenius@svenskaspel.se> # Building wheels and fs_util will be skipped. Delete if not intended. [ci skip-build-wheels]
Signed-off-by: Andreas Stenius <andreas.stenius@svenskaspel.se> # Rust tests and lints will be skipped. Delete if not intended. [ci skip-rust] # Building wheels and fs_util will be skipped. Delete if not intended. [ci skip-build-wheels]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@benjyw I've codified your input wrgt how we want to treat file deps for docker images in a test case.
Turns out, it didn't quite work at all, as it were :P
Intend to follow up with more tests...
[ci skip-build-wheels]
…context_root). Signed-off-by: Andreas Stenius <andreas.stenius@svenskaspel.se> # Building wheels and fs_util will be skipped. Delete if not intended. [ci skip-build-wheels]
[ci skip-build-wheels]
Signed-off-by: Andreas Stenius <andreas.stenius@svenskaspel.se> # Building wheels and fs_util will be skipped. Delete if not intended. [ci skip-build-wheels]
OK, I think this is a good change to merge, once approved. @benjyw |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good cleanups! See my comments inline.
# Get all sources, going into the build context. | ||
# Get all dependencies from those root targets. | ||
all_dependencies = await MultiGet( | ||
Get(Targets, DependenciesRequest(target.get(Dependencies), include_special_cased_deps=True)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why include_special_cased_deps=True
? Was this on purpose, or copy-pasta? I don't actually think we want that. Special-cased deps are a weird thing, that possibly shouldn't exist, but right now they do things like make sure that if you depend on relocated_files you don't also depend on the original pre-relocation files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise I didn't get files
targets referenced from my dependencies
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, well, guess it was something else, cause my tests works fine without. Will remove, then.
for target in transitive_targets.roots | ||
) | ||
|
||
# Get Dockerfiles from all roots. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that there will be exactly one root, because transitive_targets
was created from a single address.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adjust comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, probably good to clarify for the casual reader.
sources_fields=[t.get(Sources) for t in transitive_targets.closure], | ||
for_sources_types=(DockerImageSources, FilesSources, ResourcesSources), | ||
sources_fields=[t.get(Sources) for t in chain(*all_dependencies)], | ||
for_sources_types=(FilesSources, ResourcesSources), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this will now make sure that other Dockerfiles won't get pulled in via dependencies? Good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we might as well go ahead and stop handling ResourcesSources
here. As we discussed, it doesn't make much sense to do so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, and we will still pull in the files()
targets that we depend on via other docker_image
targets, but as previously discussed this is a general problem that we don't need to solve here right now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check on dropping resources here.
No, I have tests covering that they don't pull in files
from other docker_image
s.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about archives?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think those should just work - they are packaged resources. Are you seeing otherwise?
I'm surprised that files from other images (that this one depends on) aren't being pulled in. What prevents it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't tried anything with archives yet. Great if it just works. :)
all_dependencies
are not really all dependencies for all transient targets, just all dependencies for the roots, i.e. our docker_file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, right. packaged
resources, now I get it. Awesome. Yeah, that should work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I rephrased the comments and renamed a few variables to make things hopefully clearer.
@@ -71,7 +59,7 @@ async def build_docker_image( | |||
docker.build_image( | |||
field_set.image_tag, | |||
context.digest, | |||
field_set.context_root, | |||
".", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this arg to build_image()
at all now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, we could leave that as a default arg, and drop it here to make it cleaner. Will do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean can we just get rid of it entirely in the signature of build_image
, since we only set it once, to a hard-coded value. We can just hard-code it in the process call?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure :)
Signed-off-by: Andreas Stenius <andreas.stenius@svenskaspel.se> # Rust tests and lints will be skipped. Delete if not intended. [ci skip-rust] # Building wheels and fs_util will be skipped. Delete if not intended. [ci skip-build-wheels]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! I'm still unclear on why the files_B thing works, but good that it does, and I'll take a look at why some other time...
) | ||
|
||
# Get all dependencies for the root target. | ||
root_dependencies = await MultiGet( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see, this will only take the direct dependencies. That's probably OK? It means that if there is some intermediate target (e.g., of type target()
- which is a generic target useful for aggregating dependencies - we won't traverse it, but that's probably fine for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yes that's true.
) | ||
|
||
# Get all dependencies for the root target. | ||
root_dependencies = await MultiGet( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see, this will only take the direct dependencies. That's probably OK? It means that if there is some intermediate target (e.g., of type target()
- which is a generic target useful for aggregating dependencies) - we won't traverse it, but that's probably fine for now.
) | ||
|
||
# Get all dependencies for the root target. | ||
root_dependencies = await MultiGet( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see, this will only take the direct dependencies. That's probably OK? It means that if there is some intermediate target (e.g., of type target()
- which is a generic target useful for aggregating dependencies) - we won't traverse it, but that's probably fine for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great improvement!
Looks good once CI passes! |
I think the CI tests flunked. |
[ci skip-rust] [ci skip-build-wheels]
…d#12758) Turns out that there were quite a few corner cases uncovered wrgt targets, transitive targets and dependencies that I hadn't really come to terms with. [ci skip-rust] [ci skip-build-wheels]
…uild#12778)) * Add python-docx to the module mapping dictionary ([pantsbuild#12775](pantsbuild#12775)) * Add python-pptx to the module mapping dictionary ([pantsbuild#12776](pantsbuild#12776)) * Add `opencv-python` to the default Python module mapping ([pantsbuild#12777](pantsbuild#12777)) * Add `PyMuPDF` to the default Python module mapping ([pantsbuild#12774](pantsbuild#12774)) * Deprecate `--list-provides` option. ([pantsbuild#12759](pantsbuild#12759)) * Upgrade default `isort` to latest `isort==5.9.3` ([pantsbuild#12756](pantsbuild#12756)) * `OutputPathField.value_or_default()` no longer has an `Address` argument ([pantsbuild#12837](pantsbuild#12837)) * Properly include file dependencies in docker build context ([pantsbuild#12758](pantsbuild#12758)) * DigestSubset should not short-circuit when there are ignores involved. ([pantsbuild#12648](pantsbuild#12648)) * Improve cache reuse for `./pants package` when using a constraints file or lockfile ([pantsbuild#12807](pantsbuild#12807)) * Upgrade to Pex 2.1.48 and leverage packed layout. ([pantsbuild#12808](pantsbuild#12808)) * Fix backports of std lib modules like `dataclasses` not working with dependency inference ([pantsbuild#12818](pantsbuild#12818)) * Warn if `[python-repos]` is set during lockfile generation ([pantsbuild#12800](pantsbuild#12800)) * Add `version` to lockfile metadata headers ([pantsbuild#12788](pantsbuild#12788)) * jvm: add missing space to avoid two words running together ([pantsbuild#12793](pantsbuild#12793)) * Fix a markdown issue in a help string. ([pantsbuild#12766](pantsbuild#12766)) [ci skip-rust]
Turns out that there were quite a few corner cases uncovered wrgt targets, transitive targets and dependencies that I hadn't really come to terms with.
Signed-off-by: Andreas Stenius andreas.stenius@svenskaspel.se
[ci skip-rust]
[ci skip-build-wheels]