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

docker: include file dependencies in docker build context properly. #12758

Merged
merged 12 commits into from
Sep 8, 2021

Conversation

kaos
Copy link
Member

@kaos kaos commented Sep 6, 2021

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]

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]
Copy link
Member Author

@kaos kaos left a 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...

@kaos kaos requested a review from benjyw September 6, 2021 08:33
…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]
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]
# 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]
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]
@kaos
Copy link
Member Author

kaos commented Sep 7, 2021

OK, I think this is a good change to merge, once approved. @benjyw

@kaos
Copy link
Member Author

kaos commented Sep 7, 2021

@benjyw do you feel this PR solves the issues covered by #12694 ?

Edit: how did chewing on the context-name-calling go?

@stuhood stuhood added this to the 2.7.x milestone Sep 7, 2021
Copy link
Sponsor Contributor

@benjyw benjyw left a 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))
Copy link
Sponsor Contributor

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.

Copy link
Member Author

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.

Copy link
Member Author

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.
Copy link
Sponsor Contributor

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Adjust comment?

Copy link
Sponsor Contributor

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),
Copy link
Sponsor Contributor

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!

Copy link
Sponsor Contributor

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.

Copy link
Sponsor Contributor

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.

Copy link
Member Author

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

Copy link
Member Author

Choose a reason for hiding this comment

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

What about archives?

Copy link
Sponsor Contributor

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?

Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link
Member Author

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,
".",
Copy link
Sponsor Contributor

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?

Copy link
Member Author

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.

Copy link
Sponsor Contributor

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?

Copy link
Member Author

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]
# 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]
Copy link
Sponsor Contributor

@benjyw benjyw left a 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(
Copy link
Sponsor Contributor

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.

Copy link
Member Author

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(
Copy link
Sponsor Contributor

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(
Copy link
Sponsor Contributor

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.

Copy link
Sponsor Contributor

@benjyw benjyw left a comment

Choose a reason for hiding this comment

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

Great improvement!

@benjyw
Copy link
Sponsor Contributor

benjyw commented Sep 8, 2021

Looks good once CI passes!

@kaos
Copy link
Member Author

kaos commented Sep 8, 2021

I think the CI tests flunked.

@benjyw benjyw merged commit 001a1d6 into pantsbuild:main Sep 8, 2021
@kaos kaos deleted the docker/dep_tests branch September 9, 2021 05:04
stuhood pushed a commit to stuhood/pants that referenced this pull request Sep 9, 2021
…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]
stuhood added a commit that referenced this pull request Sep 9, 2021
…k of #12758) (#12823)

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]

Co-authored-by: Andreas Stenius <andreas.stenius@svenskaspel.se>
jsirois added a commit to jsirois/pants that referenced this pull request Sep 10, 2021
…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]
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

Successfully merging this pull request may close these issues.

3 participants