build-python-images #134
This file contains 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: Release Python + Selenium images | |
on: | |
workflow_dispatch: | |
inputs: | |
release_tag: | |
description: 'Tag for the images (e.g.: "latest" or "beta")' | |
required: true | |
apify_version: | |
description: 'Apify Python SDK version (e.g.: "1.0.0")' | |
required: true | |
selenium_version: | |
description: 'Selenium version (e.g.: "4.14.0")' | |
required: true | |
repository_dispatch: | |
types: [ build-python-images ] | |
pull_request: | |
env: | |
RELEASE_TAG: ${{ github.event.inputs.release_tag || github.event.client_payload.release_tag }} | |
APIFY_VERSION: ${{ github.event.inputs.apify_version || github.event.client_payload.apify_version }} | |
SELENIUM_VERSION: ${{ github.event.inputs.selenium_version || github.event.client_payload.selenium_version || '4.14.0' }} | |
LATEST_PYTHON: "3.11" | |
jobs: | |
# Build master images that are not dependent on existing builds. | |
build-main: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
image-name: [python-selenium] | |
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] | |
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 | |
if [[ -z "$APIFY_VERSION" ]]; then echo "APIFY_VERSION=1.1.0" >> $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 | |
if [[ -z "$APIFY_VERSION" ]]; then echo "APIFY_VERSION input is empty!" >&2; exit 1; fi | |
- | |
name: Checkout | |
uses: actions/checkout@v3 | |
- | |
name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- | |
name: Update pip | |
run: python -m pip install --upgrade pip | |
- | |
# It seems that it takes a few minutes before a newly published version | |
# becomes available in the PyPI registry. We wait before starting the image builds. | |
name: Wait For Package Registry | |
uses: nick-fields/retry@v2 | |
with: | |
timeout_minutes: 2 # timeout for a single attempt | |
max_attempts: 3 | |
retry_wait_seconds: 60 # wait between retries | |
command: pip install apify~=$APIFY_VERSION | |
- | |
name: Prepare image tags | |
id: prepare-tags | |
uses: actions/github-script@v6 | |
env: | |
CURRENT_PYTHON: ${{ matrix.python-version }} | |
LATEST_PYTHON: ${{ env.LATEST_PYTHON }} | |
FRAMEWORK_VERSION: ${{ env.PLAYWRIGHT_VERSION }} | |
RELEASE_TAG: ${{ env.RELEASE_TAG }} | |
IMAGE_NAME: apify/actor-${{ matrix.image-name }} | |
with: | |
script: | | |
const generateTags = require("./.github/scripts/prepare-python-image-tags.js"); | |
return generateTags() | |
- | |
name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- | |
name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- | |
name: Build and tag image | |
uses: docker/build-push-action@v4 | |
with: | |
context: ./${{ matrix.image-name }} | |
file: ./${{ matrix.image-name }}/Dockerfile | |
build-args: | | |
PYTHON_VERSION=${{ matrix.python-version }} | |
APIFY_VERSION=${{ env.APIFY_VERSION }} | |
SELENIUM_VERSION=${{ env.SELENIUM_VERSION }} | |
load: true | |
tags: ${{ fromJson(steps.prepare-tags.outputs.result).allTags }} | |
- | |
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@v2 | |
with: | |
username: ${{ secrets.APIFY_SERVICE_ACCOUNT_DOCKERHUB_USERNAME }} | |
password: ${{ secrets.APIFY_SERVICE_ACCOUNT_DOCKERHUB_TOKEN }} | |
- | |
name: Push images | |
if: github.event_name != 'pull_request' | |
run: docker push apify/actor-${{ matrix.image-name }} --all-tags |