From 18c2e94a25e0f668329a9291f8615b6455ad43e9 Mon Sep 17 00:00:00 2001
From: Jarek Potiuk <jarek@potiuk.com>
Date: Wed, 27 Mar 2024 15:47:46 +0100
Subject: [PATCH] Fix failure of additional prod image builds in non-main build

As of #38533 - we are building locally constraints for non-main
production image builds. This change required CI images to be used
and pulled before they were used. For "additional" image checks
image-tag used in this case contained the "extra" prefix and the
CI image could not be pulled.

This change fixes this, it also displays the right Python version
when pulling CI image and forces it's use in the pull/constraint
steps to be explicitly used when provider packages are built.
---
 .github/workflows/build-images.yml            |  1 +
 .github/workflows/ci.yml                      |  1 +
 .github/workflows/prod-image-build.yml        | 20 ++++++-------------
 .github/workflows/prod-image-extra-checks.yml |  3 +++
 4 files changed, 11 insertions(+), 14 deletions(-)

diff --git a/.github/workflows/build-images.yml b/.github/workflows/build-images.yml
index 19c3b28b1ed96..26899fbfd0a55 100644
--- a/.github/workflows/build-images.yml
+++ b/.github/workflows/build-images.yml
@@ -209,6 +209,7 @@ jobs:
       push-image: "true"
       use-uv: "true"
       image-tag: ${{ needs.build-info.outputs.image-tag }}
+      ci-image-tag: ${{ needs.build-info.outputs.image-tag }}
       platform: "linux/amd64"
       python-versions: ${{ needs.build-info.outputs.python-versions }}
       branch: ${{ needs.build-info.outputs.default-branch }}
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 57fddf61e48d1..32bb7c1f13028 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -490,6 +490,7 @@ jobs:
       build-type: "Regular"
       do-build: ${{ needs.build-info.outputs.in-workflow-build }}
       image-tag: ${{ needs.build-info.outputs.image-tag }}
+      ci-image-tag: ${{ needs.build-info.outputs.image-tag }}
       platform: "linux/amd64"
       python-versions: ${{ needs.build-info.outputs.python-versions }}
       branch: ${{ needs.build-info.outputs.default-branch }}
diff --git a/.github/workflows/prod-image-build.yml b/.github/workflows/prod-image-build.yml
index 84769c2943d3c..02a502653b68e 100644
--- a/.github/workflows/prod-image-build.yml
+++ b/.github/workflows/prod-image-build.yml
@@ -73,6 +73,10 @@ on:  # yamllint disable-line rule:truthy
         description: "Tag to set for the image"
         required: true
         type: string
+      ci-image-tag:
+        description: "Tag to use for the CI image used during the build"
+        required: true
+        type: string
       python-versions:
         description: "JSON-formatted array of Python versions to build images from"
         required: true
@@ -243,23 +247,11 @@ ${{ inputs.do-build == 'true' && inputs.image-tag || '' }}"
         shell: bash
         run: echo "${{ env.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
         if: inputs.do-build == 'true'
-      - name: Pull CI images ${{ inputs.python-versions-list-as-string }}:${{ inputs.image-tag }}
+      - name: Pull CI images ${{ matrix.python-version }}:${{ inputs.ci-image-tag }}
         run: >
-          breeze ci-image pull --tag-as-latest --image-tag "${{ inputs.image-tag }}"
+          breeze ci-image pull --tag-as-latest --image-tag "${{ inputs.ci-image-tag }}"
           --python "${{ matrix.python-version }}"
         if: inputs.do-build == 'true' && inputs.build-provider-packages != 'true'
-      - name: "Prepare chicken-eggs provider packages"
-        # In case of provider packages which use latest dev0 version of providers, we should prepare them
-        # from the source code, not from the PyPI because they have apache-airflow>=X.Y.Z dependency
-        # And when we prepare them from sources they will have apache-airflow>=X.Y.Z.dev0
-        run: >
-          breeze release-management prepare-provider-packages --include-not-ready-providers
-          --package-format wheel --version-suffix-for-pypi dev0
-          ${{ inputs.chicken-egg-providers }}
-        if: >
-          inputs.do-build == 'true' &&
-          inputs.chicken-egg-providers != '' &&
-          inputs.build-provider-packages != 'true'
       - name: "PyPI constraints"
         timeout-minutes: 25
         run: >
diff --git a/.github/workflows/prod-image-extra-checks.yml b/.github/workflows/prod-image-extra-checks.yml
index faa904e4387c4..cf7225a03627f 100644
--- a/.github/workflows/prod-image-extra-checks.yml
+++ b/.github/workflows/prod-image-extra-checks.yml
@@ -57,6 +57,7 @@ jobs:
     with:
       build-type: "Bullseye"
       image-tag: bullseye-${{ inputs.image-tag }}
+      ci-image-tag: ${{ inputs.image-tag }}
       debian-version: "bullseye"
       python-versions: ${{ inputs.python-versions }}
       platform: "linux/amd64"
@@ -75,6 +76,7 @@ jobs:
     with:
       build-type: "MySQL Client"
       image-tag: mysql-${{ inputs.image-tag }}
+      ci-image-tag: ${{ inputs.image-tag }}
       install-mysql-client-type: "mysql"
       python-versions: ${{ inputs.python-versions }}
       platform: "linux/amd64"
@@ -93,6 +95,7 @@ jobs:
     with:
       build-type: "pip"
       image-tag: mysql-${{ inputs.image-tag }}
+      ci-image-tag: ${{ inputs.image-tag }}
       install-mysql-client-type: "mysql"
       python-versions: ${{ inputs.python-versions }}
       platform: "linux/amd64"
