Skip to content

fix: Handle asyncio.get_event_loop() deprecation in reload module #38

fix: Handle asyncio.get_event_loop() deprecation in reload module

fix: Handle asyncio.get_event_loop() deprecation in reload module #38

name: Docker
on:
push:
branches: [ main, beta ]
tags: [ 'v*.*.*' ]
pull_request:
branches: [ main, beta ]
workflow_dispatch:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-dev-image:
name: Build Dev Image
runs-on: ubuntu-latest
permissions:
contents: read
strategy:
matrix:
python-version: [ '3.12', '3.13' ]
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build Dev Image
uses: docker/build-push-action@v6
with:
context: .
file: ./dockerfile
target: dev
push: false
load: true
tags: dev-image:${{ matrix.python-version }}
# tags: ${{ steps.meta.outputs.tags }}
# labels: ${{ steps.meta.outputs.labels }}
build-args: |
PYTHON_VERSION=${{ matrix.python-version }}
cache-from: type=gha
cache-to: type=gha,mode=max
provenance: false
sbom: false
- name: Save image as tar
run: |
docker save dev-image:${{ matrix.python-version }} -o dev-image-${{ matrix.python-version }}.tar
- name: Upload image artifact
uses: actions/upload-artifact@v4
with:
name: dev-image-${{ matrix.python-version }}
path: dev-image-${{ matrix.python-version }}.tar
test-dev-image:
name: Test Dev Container
runs-on: ubuntu-latest
needs: build-dev-image
if: ${{ !startsWith(github.ref, 'refs/tags/') }} # Only run on branches or PRs, not tags
permissions:
contents: read
strategy:
matrix:
python-version: ['3.12', '3.13']
fail-fast: false
steps:
- name: Download image artifact
uses: actions/download-artifact@v4
with:
name: dev-image-${{ matrix.python-version }}
- name: Load image
run: |
docker load -i dev-image-${{ matrix.python-version }}.tar
- name: Run Container Tests
run: |
docker run --rm -e MAGG_LOG_LEVEL= dev-image:${{ matrix.python-version }} pytest -v
push-dev-image:
name: Push Dev Images
runs-on: ubuntu-latest
needs: [build-dev-image, test-dev-image]
if: ${{ always() && needs.build-dev-image.result == 'success' && (needs.test-dev-image.result == 'success' || needs.test-dev-image.result == 'skipped') }}
permissions:
contents: read
packages: write
strategy:
matrix:
python-version: ['3.12', '3.13']
fail-fast: false
steps:
- name: Download image artifact
uses: actions/download-artifact@v4
with:
name: dev-image-${{ matrix.python-version }}
- name: Load image
run: |
docker load -i dev-image-${{ matrix.python-version }}.tar
- name: Log in to registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
# pr-NN-dev-py3.XX or pr-NN-dev for 3.13
type=ref,event=pr,suffix=-dev-py${{ matrix.python-version }}
type=ref,event=pr,suffix=-dev,enable=${{ matrix.python-version == '3.13' }}
# branch-dev-py3.XX
type=ref,event=branch,suffix=-dev-py${{ matrix.python-version }}
# dev for main branch, only for 3.13
type=raw,value=dev,enable=${{ matrix.python-version == '3.13' && github.ref_name == 'main' }}
# branch-dev for other branches, only for 3.13
type=raw,value=${{ github.ref_name }}-dev,enable=${{ matrix.python-version == '3.13' && github.ref_name != 'main' && startsWith(github.ref, 'refs/heads/') }}
# This matches v1.2.3 and outputs 1.2.3-dev-py3.XX or 1.2.3-dev for 3.13
type=semver,pattern=v{{major}}.{{minor}}.{{patch}},pattern={{major}}.{{minor}}.{{patch}},suffix=-dev-py${{ matrix.python-version }}
type=semver,pattern=v{{major}}.{{minor}}.{{patch}},pattern={{major}}.{{minor}}.{{patch}},suffix=-dev,enable=${{ matrix.python-version == '3.13' }}
# This matches v1.2 and outputs 1.2-dev-py3.XX or 1.2-dev for 3.13
type=semver,pattern=v{{major}}.{{minor}},pattern={{major}}.{{minor}},suffix=-dev-py${{ matrix.python-version }}
type=semver,pattern=v{{major}}.{{minor}},pattern={{major}}.{{minor}},suffix=-dev,enable=${{ matrix.python-version == '3.13' }}
- name: Tag image with all tags
run: |
echo "${{ steps.meta.outputs.tags }}" | while read TAG; do
docker tag dev-image:${{ matrix.python-version }} $TAG
done
shell: bash
- name: Push all tags
run: |
echo "${{ steps.meta.outputs.tags }}" | while read TAG; do
docker push $TAG
done
shell: bash
build-and-push-image:
name: Build and Push Image
runs-on: ubuntu-latest
needs: [build-dev-image, test-dev-image]
if: ${{ always() && needs.build-dev-image.result == 'success' && (needs.test-dev-image.result == 'success' || needs.test-dev-image.result == 'skipped') }}
permissions:
contents: read
packages: write
strategy:
matrix:
include:
- target: pre
suffix: "-pre"
- target: pro
suffix: ""
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch,suffix=${{ matrix.suffix }}
type=ref,event=pr,suffix=${{ matrix.suffix }}
type=semver,pattern=v{{major}}.{{minor}}.{{patch}},pattern={{major}}.{{minor}}.{{patch}},suffix=${{ matrix.suffix }}
type=semver,pattern=v{{major}}.{{minor}}.{{patch}},pattern={{major}}.{{minor}},suffix=${{ matrix.suffix }}
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' && matrix.target == 'pro' }}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
file: ./dockerfile
target: ${{ matrix.target }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
# labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
provenance: false
sbom: false
cleanup-untagged:
name: Cleanup Untagged Images
runs-on: ubuntu-latest
needs: [push-dev-image, build-and-push-image]
if: ${{ github.event_name != 'pull_request' }}
permissions:
packages: write
steps:
- name: Delete untagged images
uses: actions/delete-package-versions@v5
with:
package-name: 'magg'
package-type: 'container'
delete-only-untagged-versions: 'true'
min-versions-to-keep: 0
token: ${{ secrets.GITHUB_TOKEN }}