fix(CI): use updated build action v1 (with support for `--sdk VERSI…
#821
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: Container Images | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| release: | |
| types: [published] | |
| env: | |
| DEFAULT_PYTHON: "3.11" | |
| REGISTRY: ghcr.io | |
| IMAGE_NAME: ${{ github.repository }} | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| attestations: write | |
| id-token: write | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"] | |
| target: ["slim", "full"] | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v5 | |
| with: | |
| fetch-depth: 0 # Needed for setuptools-scm | |
| # NOTE: We need to store `uv.lock` for building with | |
| - uses: astral-sh/setup-uv@v7 | |
| - uses: actions/cache@v5 | |
| with: | |
| path: uv.lock | |
| key: ${{ matrix.python-version }}-uv-lock | |
| - run: uv lock --python ${{ matrix.python-version }} | |
| - name: Get version from setuptools-scm | |
| id: version | |
| run: | | |
| VERSION=$(uvx setuptools-scm) | |
| echo "version=${VERSION}" >> $GITHUB_OUTPUT | |
| - name: Check if default Python version | |
| id: is-default | |
| run: | | |
| if [ "${{ matrix.python-version }}" = "${{ env.DEFAULT_PYTHON }}" ]; then | |
| echo "value=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "value=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log into GitHub Container Registry | |
| if: github.event_name != 'pull_request' | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Generate Docker metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
| flavor: | | |
| latest=false | |
| suffix=${{ matrix.target == 'slim' && '-slim' || ''}} | |
| # NOTE: `latest=false` lets us manage it better here | |
| tags: | | |
| # For default Python version (unprefixed convenience tags) | |
| # - 'latest' on push to main | |
| type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' && steps.is-default.outputs.value == 'true' }} | |
| # - 'stable' on release | |
| type=raw,value=stable,enable=${{ github.event_name == 'release' && steps.is-default.outputs.value == 'true' }} | |
| # - version tag (e.g., v0.7.34) on release | |
| type=ref,event=tag,enable=${{ steps.is-default.outputs.value == 'true' }} | |
| # For all Python versions (including default): | |
| # - 'python3.x-latest' on push to main | |
| type=raw,value=python${{ matrix.python-version }}-latest,enable=${{ github.ref == 'refs/heads/main' }} | |
| # - 'python3.x-stable' on release | |
| type=raw,value=python${{ matrix.python-version }}-stable,enable=${{ github.event_name == 'release' }} | |
| # - 'python3.x-v*' on release | |
| type=ref,event=tag,prefix=python${{ matrix.python-version }}-,enable=${{ github.event_name == 'release' }} | |
| # PR tags for testing (not pushed) | |
| type=ref,event=pr,prefix=python${{ matrix.python-version }}-pr- | |
| labels: | | |
| org.opencontainers.image.title=silverback | |
| org.opencontainers.image.description=Listen and respond to on-chain events in real-time | |
| org.opencontainers.image.url=https://apeworx.io/silverback | |
| org.opencontainers.image.documentation=https://docs.apeworx.io/silverback/stable/userguides/quickstart | |
| org.opencontainers.image.source=https://github.com/ApeWorX/silverback | |
| org.opencontainers.image.vendor=ApeWorX LTD | |
| org.opencontainers.image.licenses=Apache-2.0 | |
| org.opencontainers.image.version=${{ steps.version.outputs.version }} | |
| org.opencontainers.image.revision=${{ github.sha }} | |
| org.opencontainers.image.authors=ApeWorX LTD | |
| org.opencontainers.image.base.name=ghcr.io/apeworx/ape:${{ matrix.python-version }}-stable-slim | |
| - name: Build and push (if required) slim image | |
| id: build | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| target: ${{ matrix.target }} | |
| build-args: | | |
| PYTHON_VERSION=${{ matrix.python-version }} | |
| VERSION=${{ steps.version.outputs.version }} | |
| push: ${{ github.event_name != 'pull_request' }} | |
| # NOTE: So examples can build in next job | |
| load: ${{ github.event_name == 'pull_request' }} | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=gha,scope=build-py${{ matrix.python-version }} | |
| platforms: ${{ github.event_name != 'pull_request' && 'linux/amd64,linux/arm64' || 'linux/amd64' }} | |
| # NOTE: Test that above built image functions as a base image (no push) | |
| examples-latest-sdk: | |
| if: ${{ github.event_name == 'pull_request' }} | |
| # NOTE: We want the silverback image built above to base ours on | |
| needs: build | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: read | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - name: Setup Python tool | |
| uses: astral-sh/setup-uv@v7 | |
| - name: Build Examples (using 'latest' SDK from above) | |
| uses: SilverbackLtd/build-action@v1 | |
| with: | |
| tag: pr-${{ github.event.pull_request.number }} | |
| sdk: latest | |
| # Build actual image using stable as base | |
| # NOTE: In PR, tests that build works with `stable` as well | |
| examples-stable-sdk: | |
| # NOTE: We want the silverback image built above to base ours on | |
| needs: build | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| id-token: write | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - name: Build Examples (Using last 'stable' version from ghcr.io) | |
| uses: SilverbackLtd/build-action@v1 | |
| with: | |
| push: ${{ github.event_name != 'pull_request' }} | |
| tag: latest | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| prune-registry: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| id-token: write | |
| steps: | |
| - name: Run container retention policy for Silverback images | |
| uses: snok/[email protected] | |
| with: | |
| account: ApeWorX | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| image-names: "silverback" | |
| # NOTE: Keep stable/stable-slim, latest/latest-slim, all 0.8.x series, and last in 0.7.x series | |
| # TODO: Add `!*v0.8*` when released, move `!*v0.7*` to last patch version | |
| image-tags: "!*stable* !*latest* !*v0.7*" | |
| tag-selection: both | |
| cut-off: 4w | |
| dry-run: ${{ github.event_name == 'pull_request' }} | |
| - name: Run container retention policy for Silverback examples | |
| uses: snok/[email protected] | |
| with: | |
| account: ApeWorX | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| # NOTE: List all examples under `bots/` here | |
| image-names: "silverback-example silverback-latency-test" | |
| image-tags: "!*latest" | |
| tag-selection: both | |
| cut-off: 4w | |
| dry-run: ${{ github.event_name == 'pull_request' }} |