Skip to content

"Main" tip caching of CI image is broken #42999

Closed

Description

@potiuk

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:

  1. Airflow has been installed from main first (which allowed to perform pre-installation without invalidation of docker layer)
  2. 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.

Image

We should review and updated Dockerfile.ci and scripts to bring the speed back.

Activity

  1. converted this from a draft issue on Oct 14, 2024
  2. added
    area:CI
    on Oct 14, 2024
  3. potiuk commented on Oct 16, 2024

    @potiuk
    MemberAuthor

    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

    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:

    1. install latest UV version
    2. install airlfow from the latest main branch (this takes 3 minutes)
    3. fix UV to the version (say 0.4.22) and install it
    4. COPY airflow sources
    5. 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:

    1. -> from cache
    2. -> from cache
    3. -> from cache
    4. COPY airflow sources
    5. proceed with installing airlfow from sources (incremental)

    If we update UV to 0.4.23 for example

    1. -> from cache
    2. -> from cache (this is where we save 3 minutes)
    3. fix UV to the version (say 0.4.23) and install it
    4. COPY airflow sources
    5. 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.

    WDYT?

  4. kaxil commented on Oct 16, 2024

    @kaxil
    Member

    Yeah supportive of that change -- any time we can speed up is a bonus!

  5. shahar1 commented on Oct 16, 2024

    @shahar1
    Contributor

    Sounds like a good idea, so I'm supportive of that change either :)

  6. gopidesupavan commented on Oct 16, 2024

    @gopidesupavan
    Member

    Great approach! installing the latest UV version first and locking the fixed version afterward is a smart way to optimize the build process.

  7. potiuk commented on Oct 16, 2024

    @potiuk
    MemberAuthor

    Good. Let me attempt doing so

  8. jscheffl commented on Oct 16, 2024

    @jscheffl
    Contributor

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

  9. potiuk commented on Oct 16, 2024

    @potiuk
    MemberAuthor

    With #43101 rebuilding the image after bumping uv version on my Mac takes 30 seconds instead of 3 minutes.

  10. self-assigned this
    on Oct 23, 2024
  11. 18 remaining items

  12. added a commit that references this issue on Dec 29, 2024
    9a4d14c
  13. added a commit that references this issue on Jan 16, 2025
    fa55cab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:CI

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions