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

Include complete platforms for FaaS environments for more reliable building #19253

Merged
merged 4 commits into from
Jun 13, 2023

Conversation

huonw
Copy link
Contributor

@huonw huonw commented Jun 5, 2023

This changes the behaviour of the runtime field of the python_aws_lambda_function, python_aws_lambda_layer and python_google_cloud_function FaaS targets to be translated into a Pants-provided complete platform (if known), rather than using the less specific --platform argument.

For example, when building a target like python_aws_lambda_function(..., runtime="python3.10"), Pants will pull out an appropriate complete platform resource and use that when building the Lambda function, to choose the correct wheels.

This is motivated by:

  1. the FaaS runtimes generally being stable (AIUI), so it's actually reasonable/possible to provide this.
  2. the naive wheel selection for runtime/--platform often fails and users have to switch to using complete platforms themselves, and, one can still use complete_platforms manually, so this is not worse.
  3. the switch to layout = "zip" means that passing both runtime="..." and complete_platforms=[...] will fail, as only one --platform=... or --complete-platform=... argument can be passed to the underlying PEX call.

The moving parts are:

  1. a script build-support/bin/generate_faas_complete_platforms.py that reads information about each FaaS system, including runtime docker repo and the tags for each 'known runtime', and shells out to docker to extra a complete platform JSON file
  2. if complete_platforms isn't specified, convert the runtime a complete platform argument (if it's known), or continue falling back to the naive --platform style

Notes:

  • Notable failing: this is only implemented for AWS: I cannot find an equivalent docker repo to https://gallery.ecr.aws/lambda/python for GCF, so despite being generic infrastructure, there's no 'known' runtimes for GCF.
  • This changes the interaction between the runtime and complete_platforms field:
    • passing both is deprecated, and the behaviour changes too (runtime is now totally ignored, but, per point 3 of the motivation above, this would fail anyway)
    • passing complete_platforms=[] is now permitted, and, I hope, means the PEX calls will use the ambient interpreter, e.g. if running in a compatible docker image
  • I haven't written explicit tests for the inference behaviour yet, as I didn't want to go too deep down that path before validating that this is sensible
  • I've only implemented this for layout = "zip", as layout = "lambdex" will be removed soon.
  • (Once we have this, I think we can even do one step better: infer an appropriate runtime from interpreter constraints (e.g. if a repo has constraints that cover only one major version, like ==3.10.*, infer runtime="python3.10"), so that a minimal FaaS target can be python_aws_lambda_function(name="foo", handler="./foo.py:handler").)

Fixes #18195

@huonw huonw marked this pull request as ready for review June 6, 2023 00:38
@huonw huonw requested a review from benjyw June 6, 2023 00:38
Copy link
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.

Excellent!

I don't know how to find out the exact GCF runtime short of actually running a live function to do so?

@huonw
Copy link
Contributor Author

huonw commented Jun 13, 2023

I'm going to merge this as is, with Lambda support, but keep #18195 open to cover adding it for GCF too.

@huonw huonw merged commit 302f544 into pantsbuild:main Jun 13, 2023
@huonw huonw deleted the feature/18195-auto-complete-platforms branch June 13, 2023 22:30
huonw added a commit that referenced this pull request Jun 14, 2023
This updates `changelog.py` to write the (non-internal) changes to the
relevant release notes file directly, rather than requiring a human to
copy-paste it in. For now, the file is just mutated, without committing.
The internal changes are still printed for the human to deal with.

For instance, `pants run src/python/pants_release/changelog.py --
--prior 2.18.0.dev1 --new 2.18.0.dev2` adds a new section to
`src/python/pants/notes/2.18.x.md`:

```diff
diff --git a/src/python/pants/notes/2.18.x.md b/src/python/pants/notes/2.18.x.md
index e648a4525c..d6668a24b1 100644
--- a/src/python/pants/notes/2.18.x.md
+++ b/src/python/pants/notes/2.18.x.md
@@ -1,5 +1,35 @@
 # 2.18.x Release Series
 
+## 2.18.0.dev2 (Jun 14, 2023)
+
+### New Features
+
+* Include complete platforms for FaaS environments for more reliable building ([#19253](#19253))
+
+* Add experimental support for Rustfmt ([#18842](#18842))
+
+* Helm deployment chart field ([#19234](#19234))
+
+### Plugin API Changes
+
+* Replace `include_special_cased_deps` flag with `should_traverse_deps_predicate` ([#19272](#19272))
+
+### Bug Fixes
+
+* Raise an error if isort can't read a config file ([#19294](#19294))
+
+* Improve handling of additional files in Helm unit tests ([#19263](#19263))
+
+* Add taplo to the release ([#19258](#19258))
+
+* Handle `from foo import *` wildcard imports in Rust dep inference parser ([#19249](#19249))
+
+* Support usage of `scala_artifact` addresses in `scalac_plugin` targets ([#19205](#19205))
+
+### Performance
+
+* `scandir` returns `Stat`s relative to its directory. ([#19246](#19246))
+
 ## 2.18.0.dev1 (Jun 02, 2023)
 
 ### New Features
```

This also moves it into the new `pants_release` root, adds some basic
tests, and has it fetch the relevant branch directly, rather than
prompting the user to do so. It also pulls out a `git.py` support module
with helpers for exec-ing `git` as an external process.

The commits are individually reviewable.

This is a step towards automating more of the "start release" process,
per #19279. After this
core refactoring of the functionality, I think the next step is to
combine it with the CONTRIBUTORS update and version bumping, and then
after that string it all together on CI so that starting a release is
fully automated.
huonw added a commit that referenced this pull request Aug 20, 2023
This adds a cached complete platform JSON file for the new support for
Python 3.11 in Lambda
https://aws.amazon.com/blogs/compute/python-3-11-runtime-now-available-in-aws-lambda/

As a bit of a drive-by, this also updates the other files based on what
seems to be upstream changes to the builder images.

As a reminder, #19253 set up this infrastructure for pre-baked
complete-platform JSON files for the AWS Lambda environment, which
enables Pants 2.18 to build lambdas that pick the right wheels more
reliably than just approximating via the `--platform` "incomplete"
platform summary.
huonw added a commit that referenced this pull request Aug 7, 2024
This updates the Lambda and GCF docs (very belatedly) for the "new"
behaviours related to choosing platform specific code, like inference of
the `runtime` field (#19314), and associated complete platforms
(#19253).

This includes stripping out the `runtime` field from the "main" flow,
and adding an separate subsection for how to specify the runtime
explicitly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Include appropriate complete_platforms for serverless/FaaS environments runtime
2 participants