Skip to content

Commit

Permalink
Optimize preparing packages for PROD image builds (#38539)
Browse files Browse the repository at this point in the history
With this change provider and airflow packages are prepared only
once for all PROD image builds and uploaded as artifacts. This saves
~ 4 minutes per PROD image build (which is multiplied by the number
of Python versions we have and by all the additional PROD image
checks we have.
  • Loading branch information
potiuk authored Mar 27, 2024
1 parent 8bf20dc commit 6ebbda5
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/additional-prod-image-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# under the License.
#
---
name: All PROD image tests
name: Additional PROD image tests
on: # yamllint disable-line rule:truthy
workflow_call:
inputs:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/build-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ jobs:
PR_LABELS: ${{ steps.get-latest-pr-labels.outputs.pull-request-labels }}
GITHUB_CONTEXT: ${{ toJson(github) }}


build-ci-images:
name: Build CI images
permissions:
Expand Down Expand Up @@ -203,6 +204,7 @@ jobs:
runs-on: '["ubuntu-22.04"]'
build-type: "Regular"
do-build: ${{ needs.build-info.outputs.ci-image-build }}
upload-package-artifact: "true"
target-commit-sha: ${{ needs.build-info.outputs.target-commit-sha }}
pull-request-target: "true"
is-committer-build: ${{ needs.build-info.outputs.is-committer-build }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ jobs:
runs-on: '["ubuntu-22.04"]'
build-type: "Regular"
do-build: ${{ needs.build-info.outputs.in-workflow-build }}
upload-package-artifact: "true"
image-tag: ${{ needs.build-info.outputs.image-tag }}
ci-image-tag: ${{ needs.build-info.outputs.image-tag }}
platform: "linux/amd64"
Expand Down
108 changes: 81 additions & 27 deletions .github/workflows/prod-image-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ on: # yamllint disable-line rule:truthy
required: false
default: "true"
type: string
upload-package-artifact:
description: >
Whether to upload package artifacts (true/false). If false, the job will rely on artifacts prepared
by the main prod-image build job.
required: true
type: string
target-commit-sha:
description: "The commit SHA to checkout for the build"
required: false
Expand Down Expand Up @@ -110,6 +116,74 @@ on: # yamllint disable-line rule:truthy
required: true
type: string
jobs:

build-prod-packages:
name: "${{ inputs.do-build == 'true' && 'Build' || 'Skip building' }} Airflow and provider packages"
timeout-minutes: 10
runs-on: ["ubuntu-22.04"]
env:
PYTHON_MAJOR_MINOR_VERSION: "${{ inputs.default-python-version }}"
steps:
- name: "Cleanup repo"
shell: bash
run: docker run -v "${GITHUB_WORKSPACE}:/workspace" -u 0:0 bash -c "rm -rf /workspace/*"
if: inputs.do-build == 'true' && inputs.upload-package-artifact == 'true'
- name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )"
uses: actions/checkout@v4
with:
persist-credentials: false
if: inputs.do-build == 'true' && inputs.upload-package-artifact == 'true'
- name: Cleanup docker
uses: ./.github/actions/cleanup-docker
if: inputs.do-build == 'true' && inputs.upload-package-artifact == 'true'
- uses: actions/setup-python@v5
with:
python-version: "${{ inputs.default-python-version }}"
if: inputs.do-build == 'true' && inputs.upload-package-artifact == 'true'
- name: "Cleanup dist and context file"
shell: bash
run: rm -fv ./dist/* ./docker-context-files/*
if: inputs.do-build == 'true' && inputs.upload-package-artifact == 'true'
- name: "Install Breeze"
uses: ./.github/actions/breeze
if: inputs.do-build == 'true' && inputs.upload-package-artifact == 'true'
- name: "Prepare providers packages"
shell: bash
run: >
breeze release-management prepare-provider-packages
--package-list-file ./prod_image_installed_providers.txt
--package-format wheel --version-suffix-for-pypi dev0
if: >
inputs.do-build == 'true' &&
inputs.upload-package-artifact == '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
shell: bash
run: >
breeze release-management prepare-provider-packages
--package-format wheel --version-suffix-for-pypi dev0 ${{ inputs.chicken-egg-providers }}
if: >
inputs.do-build == 'true' &&
inputs.upload-package-artifact == 'true' &&
inputs.chicken-egg-providers != ''
- name: "Prepare airflow package"
shell: bash
run: >
breeze release-management prepare-airflow-package
--package-format wheel --version-suffix-for-pypi dev0
if: inputs.do-build == 'true' && inputs.upload-package-artifact == 'true'
- name: "Upload prepared packages as artifacts"
uses: actions/upload-artifact@v4
with:
name: prod-packages
path: ./dist
retention-days: 7
if-no-files-found: error
if: inputs.do-build == 'true' && inputs.upload-package-artifact == 'true'

build-prod-images:
strategy:
fail-fast: true
Expand All @@ -123,6 +197,8 @@ PROD ${{ inputs.build-type }} image\
${{ matrix.python-version }}${{ inputs.do-build == 'true' && ':' || '' }}\
${{ inputs.do-build == 'true' && inputs.image-tag || '' }}"
runs-on: ${{ fromJSON(inputs.runs-on) }}
needs:
- build-prod-packages
env:
BACKEND: sqlite
DEFAULT_BRANCH: ${{ inputs.branch }}
Expand Down Expand Up @@ -209,33 +285,11 @@ ${{ inputs.do-build == 'true' && inputs.image-tag || '' }}"
shell: bash
run: rm -fv ./dist/* ./docker-context-files/*
if: inputs.do-build == 'true'
- name: "Prepare providers packages"
shell: bash
run: >
breeze release-management prepare-provider-packages
--package-list-file ./prod_image_installed_providers.txt
--package-format wheel --version-suffix-for-pypi dev0
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
shell: bash
run: >
breeze release-management prepare-provider-packages
--package-format wheel --version-suffix-for-pypi dev0 ${{ inputs.chicken-egg-providers }}
if: >
inputs.do-build == 'true' && inputs.build-provider-packages != 'true' &&
inputs.chicken-egg-providers != ''
- name: "Prepare airflow package"
shell: bash
run: >
breeze release-management prepare-airflow-package
--package-format wheel --version-suffix-for-pypi dev0
if: inputs.do-build == 'true'
- name: "Copy dist packages to docker-context files"
shell: bash
run: cp -v --no-preserve=mode,ownership ./dist/*.whl ./docker-context-files
- name: "Download packages prepared as artifacts"
uses: actions/download-artifact@v4
with:
name: prod-packages
path: ./docker-context-files
if: inputs.do-build == 'true'
- name: "Download constraints from the CI build"
uses: actions/download-artifact@v4
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/prod-image-extra-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ jobs:
uses: ./.github/workflows/prod-image-build.yml
with:
build-type: "Bullseye"
upload-package-artifact: "false"
image-tag: bullseye-${{ inputs.image-tag }}
ci-image-tag: ${{ inputs.image-tag }}
debian-version: "bullseye"
Expand All @@ -75,6 +76,7 @@ jobs:
uses: ./.github/workflows/prod-image-build.yml
with:
build-type: "MySQL Client"
upload-package-artifact: "false"
image-tag: mysql-${{ inputs.image-tag }}
ci-image-tag: ${{ inputs.image-tag }}
install-mysql-client-type: "mysql"
Expand All @@ -94,6 +96,7 @@ jobs:
uses: ./.github/workflows/prod-image-build.yml
with:
build-type: "pip"
upload-package-artifact: "false"
image-tag: mysql-${{ inputs.image-tag }}
ci-image-tag: ${{ inputs.image-tag }}
install-mysql-client-type: "mysql"
Expand Down
14 changes: 5 additions & 9 deletions .github/workflows/push-image-cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,11 @@ jobs:
uses: ./.github/actions/breeze
- name: "Cleanup dist and context file"
run: rm -fv ./dist/* ./docker-context-files/*
- name: "Prepare airflow package for PROD build"
run: breeze release-management prepare-airflow-package --package-format wheel
- name: "Prepare providers packages for PROD build"
run: >
breeze release-management prepare-provider-packages
--package-list-file ./prod_image_installed_providers.txt
--package-format wheel
- name: "Copy dist packages to docker-context files"
run: cp -v --no-preserve=mode,ownership ./dist/*.whl ./docker-context-files
- name: "Download packages prepared as artifacts"
uses: actions/download-artifact@v4
with:
name: prod-packages
path: ./docker-context-files
- name: "Start ARM instance"
run: ./scripts/ci/images/ci_start_arm_instance_and_connect_to_docker.sh
if: inputs.platform == 'linux/arm64'
Expand Down

0 comments on commit 6ebbda5

Please sign in to comment.