You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It looks like after the provider move in #42505, "main" tip caching for airflow is broken. Before the change installing airflow had use two stages caching:
Airflow has been installed from main first (which allowed to perform pre-installation without invalidation of docker layer)
Then additional installation was done after copying latest sources and pyproject.toml/hatch
This allowed for very fast rebuilds of the image using remote cache built on ghcr.io, when only source files or dependencies of airlfow changed.
It usually took 2-5 seconds to rebuild such image. Currently it looks like second installation step is running again full installation of airlfow (it takes about 2 minutes), which means that likely some mechanism of caching is broken.
We should review and updated Dockerfile.ci and scripts to bring the speed back.
I am slowly looking at the ways how we can again speed up the CI image build and caching.
One of the reasons I thought caching is not as good is the UV version bump. Whenever we increase the UV version it will invalidate the cache layer just before installing airflow from the branch tip.
ARG AIRFLOW_PIP_VERSION=24.2
ARG AIRFLOW_UV_VERSION=0.4.22
ARG AIRFLOW_USE_UV="true"
RUN echo "Airflow version: ${AIRFLOW_VERSION}"
# Copy all scripts required for installation - changing any of those should lead to
# rebuilding from here
COPY --from=scripts install_packaging_tools.sh install_airflow_dependencies_from_branch_tip.sh \
common.sh /scripts/docker/
RUN bash /scripts/docker/install_packaging_tools.sh; \
if [[ ${AIRFLOW_PRE_CACHED_PIP_PACKAGES} == "true" ]]; then \
bash /scripts/docker/install_airflow_dependencies_from_branch_tip.sh; \
fi
When we change default UV_VERSION - all the layers below that get invalidated - so the COPY that copies the script and installing dependencies from the main branch tip will run again and reinstalling of the whole airlfow from "main" branch runs from scratch. Even with uv where it is as fast as possible, it takes 180s on my machine (3 minutes) - which is pretty slow. And the only reason in this case is that we changed the UV version.
I think about optimizing it a bit - since UV version is changing so fast - maybe we can optimize it by installing "latest" version of UV for the "branch tip" installation and only then install the "fixed" version of UV.
We are fixing UV version in order to get stability in place - there is a risk that UV upgrade will break things (happened in the past) as they are "moving fast and break things". So fixing UV in the image (and manual updates and merging after PR passes) makes sense - but for the optimisation purpose, it might make sense that branch tip installation is happening with latest UV without specifying version.
This should be generally quite save and stable. The "install_airlfow_from_branch_tip" is only optimization of installation - preinstalling airflow from "some" good version of airflow. If we do not change UV_VERSION before it, the layer would usually not get invalidated for builds - because there is nothing that could trigger the invalidation (no other previous Dockerfile lines would change) - so once such a build succeeds in main and the remote cache is updated, it will NOT reinstall uv with latest version - it will keep the uv installed in the same version it succeed last time - because the cache will not get invalidated.
So the first time when the cache will be build it will roughly work this way:
install latest UV version
install airlfow from the latest main branch (this takes 3 minutes)
fix UV to the version (say 0.4.22) and install it
COPY airflow sources
proceed with installing airlfow from sources (incremental)
Then whenever we have modified airflow sources - for all the subsequent image build operations, if base python version and no Dockerfile above those line change and no UV version change - it will reuse the cache effectively:
-> from cache
-> from cache
-> from cache
COPY airflow sources
proceed with installing airlfow from sources (incremental)
If we update UV to 0.4.23 for example
-> from cache
-> from cache (this is where we save 3 minutes)
fix UV to the version (say 0.4.23) and install it
COPY airflow sources
proceed with installing airlfow from sources (incremental)
This means that we are saving 3 minutes for rebuilds of CI image (locally and on CI) - when only UV version change.
+1 as well - and if latest uv versions fails as a workaround we would need to (temporariy) fix the UV version in lowest layer... which is a small residual risk only.
Activity
potiuk commentedon Oct 16, 2024
cc: @ashb @kaxil @gopidesupavan @romsharon98 @shahar1 @eladkal @jscheffl.
I am slowly looking at the ways how we can again speed up the CI image build and caching.
One of the reasons I thought caching is not as good is the UV version bump. Whenever we increase the UV version it will invalidate the cache layer just before installing airflow from the branch tip.
Starting from here https://github.com/apache/airflow/blob/main/Dockerfile.ci#L1281
When we change default UV_VERSION - all the layers below that get invalidated - so the COPY that copies the script and installing dependencies from the
mainbranch tip will run again and reinstalling of the whole airlfow from "main" branch runs from scratch. Even withuvwhere it is as fast as possible, it takes 180s on my machine (3 minutes) - which is pretty slow. And the only reason in this case is that we changed the UV version.I think about optimizing it a bit - since UV version is changing so fast - maybe we can optimize it by installing "latest" version of UV for the "branch tip" installation and only then install the "fixed" version of UV.
We are fixing UV version in order to get stability in place - there is a risk that UV upgrade will break things (happened in the past) as they are "moving fast and break things". So fixing UV in the image (and manual updates and merging after PR passes) makes sense - but for the optimisation purpose, it might make sense that branch tip installation is happening with latest UV without specifying version.
This should be generally quite save and stable. The "install_airlfow_from_branch_tip" is only optimization of installation - preinstalling airflow from "some" good version of airflow. If we do not change UV_VERSION before it, the layer would usually not get invalidated for builds - because there is nothing that could trigger the invalidation (no other previous Dockerfile lines would change) - so once such a build succeeds in main and the remote cache is updated, it will NOT reinstall uv with latest version - it will keep the uv installed in the same version it succeed last time - because the cache will not get invalidated.
So the first time when the cache will be build it will roughly work this way:
Then whenever we have modified airflow sources - for all the subsequent image build operations, if base python version and no Dockerfile above those line change and no UV version change - it will reuse the cache effectively:
If we update UV to 0.4.23 for example
This means that we are saving 3 minutes for rebuilds of CI image (locally and on CI) - when only UV version change.
WDYT?
kaxil commentedon Oct 16, 2024
Yeah supportive of that change -- any time we can speed up is a bonus!
shahar1 commentedon Oct 16, 2024
Sounds like a good idea, so I'm supportive of that change either :)
gopidesupavan commentedon Oct 16, 2024
Great approach! installing the latest UV version first and locking the fixed version afterward is a smart way to optimize the build process.
potiuk commentedon Oct 16, 2024
Good. Let me attempt doing so
jscheffl commentedon Oct 16, 2024
+1 as well - and if latest uv versions fails as a workaround we would need to (temporariy) fix the UV version in lowest layer... which is a small residual risk only.
potiuk commentedon Oct 16, 2024
With #43101 rebuilding the image after bumping
uvversion on my Mac takes 30 seconds instead of 3 minutes.Speed-up rebuilding of CI image after pip/uv version change
Speed-up rebuilding of CI image after pip/uv version change (#43101)
18 remaining items
Simplify caching mechanisms for CI and PROD images (apache#45266)
Simplify caching mechanisms for CI and PROD images (apache#45266)