Python basic images #5972
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Python basic images | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| release_tag: | |
| description: 'Tag for the images (e.g.: "latest" or "beta")' | |
| required: true | |
| rebuild_images: | |
| description: "Rebuilds images even if the cache state matches the current state." | |
| required: false | |
| type: boolean | |
| trigger_templates_pr: | |
| description: "When set to true, always triggers the workflow on actor-templates." | |
| required: false | |
| type: boolean | |
| repository_dispatch: | |
| types: [build-python-images] | |
| pull_request: | |
| paths: | |
| - "python/**" | |
| - ".github/workflows/release-python.yaml" | |
| - ".github/actions/version-matrix/**" | |
| - ".github/scripts/prepare-python-image-tags.js" | |
| - "Makefile" | |
| schedule: | |
| - cron: 0 */2 * * * | |
| env: | |
| RELEASE_TAG: ${{ github.event.inputs.release_tag || github.event.client_payload.release_tag }} | |
| SKIP_CACHE_CHECK: ${{ github.event_name == 'pull_request' || github.event.inputs.rebuild_images == 'true' }} | |
| jobs: | |
| matrix: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| matrix: ${{ steps.set-matrix.outputs.matrix }} | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }} | |
| fetch-depth: 0 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version-file: .github/actions/version-matrix/package.json | |
| cache: yarn | |
| cache-dependency-path: .github/actions/version-matrix/yarn.lock | |
| - run: yarn | |
| working-directory: ./.github/actions/version-matrix | |
| - name: Generate matrix | |
| id: set-matrix | |
| run: echo "matrix=$(yarn python:normal)" >> $GITHUB_OUTPUT | |
| working-directory: ./.github/actions/version-matrix | |
| - name: Print matrix | |
| run: | | |
| echo '${{ steps.set-matrix.outputs.matrix }}' | jq -r '.include[] | "python-version=\(.["python-version"])"' | |
| echo "" | |
| echo "Raw matrix:" | |
| echo "" | |
| echo '${{ steps.set-matrix.outputs.matrix }}' | jq -e | |
| - name: Commit updated matrix | |
| id: commit | |
| if: github.event_name != 'pull_request' | |
| uses: apify/actions/signed-commit@v1.2.0 | |
| with: | |
| message: "chore(docker): update ${{ env.RELEASE_TAG || 'latest' }} python:normal cache" | |
| add: ./.github/actions/version-matrix/data/*.json | |
| retries: 5 | |
| pull: '--rebase --autostash' | |
| github-token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }} | |
| - name: Trigger workflow on actor-templates | |
| if: (steps.commit.outputs.committed == 'true' || github.event.inputs.trigger_templates_pr == 'true') && steps.set-matrix.outputs.latest-runtime-version != '' | |
| uses: peter-evans/repository-dispatch@v4 | |
| with: | |
| token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }} | |
| repository: apify/actor-templates | |
| event-type: update-templates | |
| client-payload: |- | |
| { | |
| "base_image": "apify/actor-python", | |
| "default_runtime_version": "${{ steps.set-matrix.outputs.latest-runtime-version }}" | |
| } | |
| # Build master images that are not dependent on existing builds. | |
| build-main: | |
| needs: [matrix] | |
| runs-on: ubuntu-latest | |
| if: ${{ toJson(fromJson(needs.matrix.outputs.matrix).include) != '[]' }} | |
| strategy: | |
| fail-fast: false | |
| matrix: ${{ fromJson(needs.matrix.outputs.matrix) }} | |
| name: "py: ${{ matrix.python-version }}" | |
| steps: | |
| - name: Set default inputs if event is pull request | |
| if: github.event_name == 'pull_request' | |
| run: | | |
| if [[ -z "$RELEASE_TAG" ]]; then echo "RELEASE_TAG=CI_TEST" >> $GITHUB_ENV; fi | |
| - name: Set default inputs if event is schedule | |
| if: github.event_name == 'schedule' | |
| run: | | |
| if [[ -z "$RELEASE_TAG" ]]; then echo "RELEASE_TAG=latest" >> $GITHUB_ENV; fi | |
| - name: Check if inputs are set correctly | |
| run: | | |
| if [[ -z "$RELEASE_TAG" ]]; then echo "RELEASE_TAG input is empty!" >&2; exit 1; fi | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| - name: Prepare image tags | |
| id: prepare-tags | |
| uses: actions/github-script@v8 | |
| env: | |
| CURRENT_PYTHON: ${{ matrix.python-version }} | |
| LATEST_PYTHON: ${{ matrix.latest-python-version }} | |
| RELEASE_TAG: ${{ env.RELEASE_TAG }} | |
| IMAGE_NAME: apify/actor-${{ matrix.image-name }} | |
| # Force this to true, as these images have no browsers | |
| IS_LATEST_BROWSER_IMAGE: "true" | |
| with: | |
| script: | | |
| const generateTags = require("./.github/scripts/prepare-python-image-tags.js"); | |
| return generateTags() | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v4 | |
| - name: Build and tag image for testing | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: ./${{ matrix.image-name }} | |
| file: ./${{ matrix.image-name }}/Dockerfile | |
| build-args: | | |
| PYTHON_VERSION=${{ matrix.python-version }} | |
| platforms: linux/amd64 | |
| provenance: false | |
| load: true | |
| tags: ${{ fromJson(steps.prepare-tags.outputs.result).allTags }} | |
| cache-from: type=gha,scope=${{ matrix.image-name }}-${{ matrix.python-version }} | |
| cache-to: type=gha,mode=max,scope=${{ matrix.image-name }}-${{ matrix.python-version }} | |
| - name: Test image | |
| run: docker run ${{ fromJson(steps.prepare-tags.outputs.result).firstImageName }} | |
| - name: Login to DockerHub | |
| if: github.event_name != 'pull_request' | |
| uses: docker/login-action@v4 | |
| with: | |
| username: ${{ secrets.APIFY_SERVICE_ACCOUNT_DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.APIFY_SERVICE_ACCOUNT_DOCKERHUB_TOKEN }} | |
| - name: Build and push OCI image | |
| if: github.event_name != 'pull_request' | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: ./${{ matrix.image-name }} | |
| file: ./${{ matrix.image-name }}/Dockerfile | |
| build-args: | | |
| PYTHON_VERSION=${{ matrix.python-version }} | |
| platforms: linux/amd64,linux/arm64 | |
| provenance: true | |
| push: true | |
| tags: ${{ fromJson(steps.prepare-tags.outputs.result).allTags }} | |
| outputs: type=image,oci-mediatypes=true | |
| cache-from: type=gha,scope=${{ matrix.image-name }}-${{ matrix.python-version }} |