This is an automated email from the ASF dual-hosted git repository. potiuk pushed a commit to branch fix-optimization-of-prod-image-building-for-non-main-branches in repository https://gitbox.apache.org/repos/asf/airflow.git
commit a43bd0916cfb940edba90737e2f2fe05478cab31 Author: Jarek Potiuk <ja...@potiuk.com> AuthorDate: Thu Dec 7 12:30:36 2023 +0100 Fix optimization of PROD image building side-effect The change #35856 optimized waiting time before PROD image builds start - rather than waiting for full constratints generation, the PROD image building just used source constraints generated right after building the CI image quickly. This is fine for main because there we install airflow and packages using constraints from sources, but for release branches we use the provider constraints - in order to be able to install providers from PyPI rather than from sources. This means that we have to wait for constraints generation to complete before we start building PROD images - because we need to download the constraints generated there to use them. Unfortunately GitHub Actions do not have conditional dependencies depending on where the workflow is run - so instead we have to effectively duplicate PROD build steps and skip steps in them instead. --- .github/actions/build-prod-images/action.yml | 7 ++ .github/workflows/ci.yml | 138 +++++++++++++++++++++++++-- 2 files changed, 139 insertions(+), 6 deletions(-) diff --git a/.github/actions/build-prod-images/action.yml b/.github/actions/build-prod-images/action.yml index f038234087..14a5aa8de9 100644 --- a/.github/actions/build-prod-images/action.yml +++ b/.github/actions/build-prod-images/action.yml @@ -66,6 +66,13 @@ runs: with: name: source-constraints path: ./docker-context-files + if: ${{ inputs.build-provider-packages == 'true' }} + - name: "Download constraints from the Generate & Verify build" + uses: actions/download-artifact@v3 + with: + name: constraints + path: ./docker-context-files + if: ${{ inputs.build-provider-packages != 'true' }} - name: "Build & Push PROD images with source providers ${{ env.IMAGE_TAG }}:${{ env.PYTHON_VERSIONS }}" shell: bash run: > diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 17896a65d9..6ca4e0d373 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1605,20 +1605,28 @@ jobs: steps: - name: Cleanup repo run: docker run -v "${GITHUB_WORKSPACE}:/workspace" -u 0:0 bash -c "rm -rf /workspace/*" - if: needs.build-info.outputs.in-workflow-build == 'true' + if: > + needs.build-info.outputs.in-workflow-build == 'true' && + needs.build-info.outputs.default-branch == 'main' - uses: actions/checkout@v4 with: ref: ${{ needs.build-info.outputs.targetCommitSha }} persist-credentials: false - if: needs.build-info.outputs.in-workflow-build == 'true' + if: > + needs.build-info.outputs.in-workflow-build == 'true' && + needs.build-info.outputs.default-branch == 'main' - name: "Install Breeze" uses: ./.github/actions/breeze - if: needs.build-info.outputs.in-workflow-build == 'true' + if: > + needs.build-info.outputs.in-workflow-build == 'true' && + needs.build-info.outputs.default-branch == 'main' - name: > Build PROD Images ${{needs.build-info.outputs.all-python-versions-list-as-string}}:${{env.IMAGE_TAG}} uses: ./.github/actions/build-prod-images - if: needs.build-info.outputs.in-workflow-build == 'true' + if: > + needs.build-info.outputs.in-workflow-build == 'true' && + needs.build-info.outputs.default-branch == 'main' with: build-provider-packages: ${{ needs.build-info.outputs.default-branch == 'main' }} chicken-egg-providers: ${{ needs.build-info.outputs.chicken-egg-providers }} @@ -1648,17 +1656,135 @@ jobs: steps: - name: Cleanup repo run: docker run -v "${GITHUB_WORKSPACE}:/workspace" -u 0:0 bash -c "rm -rf /workspace/*" + if: > + needs.build-info.outputs.in-workflow-build == 'true' && + needs.build-info.outputs.default-branch == 'main' + - uses: actions/checkout@v3 + with: + ref: ${{ needs.build-info.outputs.targetCommitSha }} + persist-credentials: false + submodules: recursive + if: > + needs.build-info.outputs.in-workflow-build == 'true' && + needs.build-info.outputs.default-branch == 'main' + - name: "Install Breeze" + uses: ./.github/actions/breeze + if: > + needs.build-info.outputs.in-workflow-build == 'true' && + needs.build-info.outputs.default-branch == 'main' + - name: > + Build Bullseye PROD Images + ${{needs.build-info.outputs.all-python-versions-list-as-string}}:${{env.IMAGE_TAG}} + uses: ./.github/actions/build-prod-images + if: > + needs.build-info.outputs.in-workflow-build == 'true' && + needs.build-info.outputs.default-branch == 'main' + with: + build-provider-packages: ${{ needs.build-info.outputs.default-branch == 'main' }} + chicken-egg-providers: ${{ needs.build-info.outputs.chicken-egg-providers }} + env: + UPGRADE_TO_NEWER_DEPENDENCIES: ${{ needs.build-info.outputs.upgrade-to-newer-dependencies }} + DOCKER_CACHE: ${{ needs.build-info.outputs.cache-directive }} + PYTHON_VERSIONS: ${{needs.build-info.outputs.all-python-versions-list-as-string}} + DEBUG_RESOURCES: ${{ needs.build-info.outputs.debug-resources }} + DEBIAN_VERSION: "bullseye" + # Do not override the "bookworm" image - just push a new bullseye image + # TODO: improve caching for that build + IMAGE_TAG: "bullseye-${{ github.event.pull_request.head.sha || github.sha }}" + + build-prod-images-release-branch: + timeout-minutes: 80 + name: > + ${{needs.build-info.outputs.build-job-description}} PROD images + ${{needs.build-info.outputs.all-python-versions-list-as-string}} + runs-on: ${{fromJSON(needs.build-info.outputs.runs-on)}} + needs: [build-info, generate-constraints] + env: + DEFAULT_BRANCH: ${{ needs.build-info.outputs.default-branch }} + DEFAULT_CONSTRAINTS_BRANCH: ${{ needs.build-info.outputs.default-constraints-branch }} + RUNS_ON: "${{needs.build-info.outputs.runs-on}}" + BACKEND: sqlite + VERSION_SUFFIX_FOR_PYPI: "dev0" + DEBUG_RESOURCES: ${{needs.build-info.outputs.debug-resources}} + # Force more parallelism for build even on public images + PARALLELISM: 6 + steps: + - name: Cleanup repo + run: docker run -v "${GITHUB_WORKSPACE}:/workspace" -u 0:0 bash -c "rm -rf /workspace/*" + if: > + needs.build-info.outputs.in-workflow-build == 'true' && + needs.build-info.outputs.default-branch != 'main' + - uses: actions/checkout@v4 + with: + ref: ${{ needs.build-info.outputs.targetCommitSha }} + persist-credentials: false + if: > + needs.build-info.outputs.in-workflow-build == 'true' && + needs.build-info.outputs.default-branch != 'main' + - name: "Install Breeze" + uses: ./.github/actions/breeze + if: > + needs.build-info.outputs.in-workflow-build == 'true' && + needs.build-info.outputs.default-branch != 'main' + - name: > + Build PROD Images + ${{needs.build-info.outputs.all-python-versions-list-as-string}}:${{env.IMAGE_TAG}} + uses: ./.github/actions/build-prod-images + if: > + needs.build-info.outputs.in-workflow-build == 'true' && + needs.build-info.outputs.default-branch != 'main' + with: + build-provider-packages: ${{ needs.build-info.outputs.default-branch == 'main' }} + chicken-egg-providers: ${{ needs.build-info.outputs.chicken-egg-providers }} + env: + UPGRADE_TO_NEWER_DEPENDENCIES: ${{ needs.build-info.outputs.upgrade-to-newer-dependencies }} + DOCKER_CACHE: ${{ needs.build-info.outputs.cache-directive }} + PYTHON_VERSIONS: ${{needs.build-info.outputs.all-python-versions-list-as-string}} + DEBUG_RESOURCES: ${{ needs.build-info.outputs.debug-resources }} + + build-prod-images-bullseye-release-branch: + timeout-minutes: 80 + name: > + Build Bullseye PROD images + ${{needs.build-info.outputs.all-python-versions-list-as-string}} + runs-on: ${{fromJSON(needs.build-info.outputs.runs-on)}} + needs: [build-info, generate-constraints] + if: needs.build-info.outputs.canary-run == 'true' + env: + DEFAULT_BRANCH: ${{ needs.build-info.outputs.default-branch }} + DEFAULT_CONSTRAINTS_BRANCH: ${{ needs.build-info.outputs.default-constraints-branch }} + RUNS_ON: "${{needs.build-info.outputs.runs-on}}" + BACKEND: sqlite + VERSION_SUFFIX_FOR_PYPI: "dev0" + DEBUG_RESOURCES: ${{needs.build-info.outputs.debug-resources}} + # Force more parallelism for build even on public images + PARALLELISM: 6 + steps: + - name: Cleanup repo + run: docker run -v "${GITHUB_WORKSPACE}:/workspace" -u 0:0 bash -c "rm -rf /workspace/*" + if: > + needs.build-info.outputs.in-workflow-build == 'true' && + needs.build-info.outputs.default-branch != 'main' - uses: actions/checkout@v3 with: ref: ${{ needs.build-info.outputs.targetCommitSha }} persist-credentials: false submodules: recursive + if: > + needs.build-info.outputs.in-workflow-build == 'true' && + needs.build-info.outputs.default-branch != 'main' - name: "Install Breeze" uses: ./.github/actions/breeze + if: > + needs.build-info.outputs.in-workflow-build == 'true' && + needs.build-info.outputs.default-branch != 'main' - name: > Build Bullseye PROD Images ${{needs.build-info.outputs.all-python-versions-list-as-string}}:${{env.IMAGE_TAG}} uses: ./.github/actions/build-prod-images + if: > + needs.build-info.outputs.in-workflow-build == 'true' && + needs.build-info.outputs.default-branch != 'main' with: build-provider-packages: ${{ needs.build-info.outputs.default-branch == 'main' }} chicken-egg-providers: ${{ needs.build-info.outputs.chicken-egg-providers }} @@ -1676,7 +1802,7 @@ jobs: timeout-minutes: 80 name: "Wait for PROD images" runs-on: ${{fromJSON(needs.build-info.outputs.runs-on)}} - needs: [build-info, wait-for-ci-images, build-prod-images] + needs: [build-info, wait-for-ci-images, build-prod-images, build-prod-images-release-branch] if: needs.build-info.outputs.prod-image-build == 'true' env: RUNS_ON: "${{needs.build-info.outputs.runs-on}}" @@ -1698,7 +1824,7 @@ jobs: if: needs.build-info.outputs.in-workflow-build == 'false' - name: Wait for PROD images ${{ env.PYTHON_VERSIONS }}:${{ env.IMAGE_TAG }} # We wait for the images to be available either from "build-images.yml' run as pull_request_target - # or from build-prod-images above. + # or from build-prod-images (or build-prod-images-release-branch) above. # We are utilising single job to wait for all images because this job merely waits # For the images to be available. run: breeze prod-image pull --wait-for-image --run-in-parallel