Skip to content

Commit

Permalink
Move prepare-provider-packages to be run entirely in Breeze Python
Browse files Browse the repository at this point in the history
This is a follow-up after #35586 and it depends on this one. It
moves the whole functionality of preparing provider packages to
breeze, removing the need of doing it in the Breeze CI image.

Since we have Python breeze with its own environment managed via
`pipx` we can now make sure that all the necessary packages are
installed in this environment and run package building in the
same environment Breeze uses.

Previously we have been running all the package building inside the
CI image for two reasons:

* we could rely on the same version of build tools (wheel/setuptools)
  being installed in the CI image
* security of the provider package preparation that used setuptools
  pre PEP-517 way of building packages that executed setup.py code

In order to isolate execution of potentially arbitrary code
in setup.py from the HOST environment in CI - where the host
environment might have access to secrets and tokens that would allow
it to break out of the sandbox for PRs coming from forks. The setup.py
file has been prepared by breeze using JINJA templates but it was
potentially possible to manipulate provider package directory structure
and get "Python" injection into generated setup.py, so it was safer
to run it in the isolated Breeze CI environment.

This PR makes it secure to run it in the Host environment,
because instead of generating setup.cfg and setup.py we generate
pyproject.toml with all the necessary information and we are using
PEP-517 compliant way of building provider packages - no arbitrary
code executed via setup.py is possible this way on the host,
so we can safely build provider packages in the host. We are
generating declarative pyproject.toml for that rather than imperative
setup.py, so we are safe to run the build process in the host without
being afraid of executing arbitrary code.

We are using flit as build tool - this is one of the popular build
tools - created by Python Packaging team. It is simple and not
too opinionated, it supports PEP-517 as well as PEP-621, so most of
the project mnetadata in pyproject toml can be added to PEP-621
compliant "project" section of pyproject.toml.

Together with the change we improves the process of generation of the
extracted sources for the providers. Originally we copied the whole
sources of Airflow to a single directory (provider_packages) and run
sequentially provider packages building from that single directory,
however it made it impossible to parallelise such builds - all
providers had to be built sequentially.

We change the approach now - instead of copying all airflow
sources once to the single directory, we build providers in separate
subdirectories of files/provider_packages/PROVIDER_ID and we only
copy there relevant sources (i.e. only provider's subfolder from
the "airflow/providers". This is quite a bit faster (each provider
only gets built using only its own sources so just scanning the
directory is faster) but it also allows to run package preparation
in parallel because each provider is fully isolated from others.

This PR also excludes not-needed `prepare_providers_package.py`
and unneded `provider_packages` folder used to prepare providers
before as well as bash script to build the providers and some
unused bash functions.
  • Loading branch information
potiuk committed Nov 16, 2023
1 parent 47e9ad2 commit ace8031
Show file tree
Hide file tree
Showing 38 changed files with 956 additions and 2,429 deletions.
3 changes: 3 additions & 0 deletions .rat-excludes
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,6 @@ doap_airflow.rdf

# nvm (Node Version Manager)
.nvmrc

# PKG-INFO file
PKG-INFO
2 changes: 1 addition & 1 deletion NOTICE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Apache Airflow
Copyright 2016-2021 The Apache Software Foundation
Copyright 2016-2023 The Apache Software Foundation

This product includes software developed at The Apache Software
Foundation (http://www.apache.org/).
Expand Down
2 changes: 1 addition & 1 deletion airflow/www/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const BUILD_DIR = path.resolve(__dirname, "./static/dist");
// Convert licenses json into a standard format for LICENSES.txt
const formatLicenses = (packages) => {
let text = `Apache Airflow
Copyright 2016-2021 The Apache Software Foundation
Copyright 2016-2023 The Apache Software Foundation
This product includes software developed at The Apache Software
Foundation (http://www.apache.org/).
Expand Down
2 changes: 1 addition & 1 deletion chart/NOTICE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Apache Airflow
Copyright 2016-2021 The Apache Software Foundation
Copyright 2016-2023 The Apache Software Foundation

This product includes software developed at The Apache Software
Foundation (http://www.apache.org/).
Expand Down
2 changes: 1 addition & 1 deletion dev/breeze/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ PLEASE DO NOT MODIFY THE HASH BELOW! IT IS AUTOMATICALLY UPDATED BY PRE-COMMIT.

---------------------------------------------------------------------------------------------------------

Package config hash: 51d9c2ec8af90c2941d58cf28397e9972d31718bc5d74538eb0614ed9418310e7b1d14bb3ee11f4df6e8403390869838217dc641cdb1416a223b7cf69adf1b20
Package config hash: 772a3746780de67ba5c0198928b5f6d7461eb6ae3b9537665dab9c504515290d975bb52ef6b3bacc04148702402ab9b02c6e529910f2f727771df56ef56c1554

---------------------------------------------------------------------------------------------------------
13 changes: 6 additions & 7 deletions dev/breeze/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,25 @@ dependencies = [
"black>=23.11.0",
"click>=8.1.7",
"filelock>=3.13.0",
"flit>=3.5.0",
"gitpython>=3.1.40",
"inputimeout>=1.0.4",
"jinja2>=3.1.0",
"jsonschema>=4.19.1",
"packaging>=23.2",
"pendulum>=2.1.2,<3",
"pre-commit>=3.5.0",
"psutil>=5.9.6",
"pytest>=7.4.0",
"pygithub>=2.1.1",
"pytest-xdist>=3.3.1",
"pytest>=7.4.0",
"pyyaml>=6.0.1",
"PyGithub>=2.1.1",
"requests>=2.30.0",
"rich>=13.6.0",
"rich-click>=1.7.1",
"gitpython>=3.1.40",
"rich>=13.6.0",
"semver>=3.0.2",
"tabulate>=0.9.0",
"twine>=4.0.2",
"wheel>=0.41.3",
"setuptools>=68.2.2",
"jsonschema>=4.19.1",
]

[project.scripts]
Expand Down
Loading

0 comments on commit ace8031

Please sign in to comment.