Skip to content

Publish Docker image #28

Publish Docker image

Publish Docker image #28

Workflow file for this run

name: Publish Docker image
on:
push:
branches:
- 'main'
- 'master'
tags:
- '*.*.*'
paths:
- 'Dockerfile'
- 'pyproject.toml'
- 'poetry.lock'
- 'requirements.txt'
- '**.py'
- '**.sh'
- '**.js'
- '**.css'
- '.dockerignore'
- '.env.example'
- '.github/workflows/**'
- 'static/**'
workflow_run:
workflows: ["Run pytest"]
types:
- completed
env:
REGISTRY_URL: ghcr.io
REGISTRY_USER: ${{ github.repository_owner }}
IMAGE: ${{ vars.IMAGE }}
jobs:
push_to_registry:
name: Push Docker image to container registry
if: |
(github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/'))) ||
(github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success')
runs-on: ubuntu-latest
concurrency:
group: ${{ github.workflow }}-${{ github.event.workflow_run.head_branch || github.ref }}
cancel-in-progress: true
permissions:
packages: write
contents: read
steps:
- name: Check out the repo
uses: actions/checkout@v4
# - name: Log into Docker Hub
# if: ${{ github.event_name != 'pull_request' }}
# uses: docker/login-action@v3
# with:
# username: ${{ secrets.DOCKERHUB_USERNAME }}
# password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY_URL }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: |
name=${{ env.REGISTRY_URL }}/${{ env.REGISTRY_USER }}/${{ env.IMAGE }}
tags: |
type=raw,value=latest,enable=${{ endsWith(github.ref, 'main') }}
type=ref,event=branch,enable=${{ !endsWith(github.ref, 'main') }}
type=semver,pattern={{version}}
flavor: |
latest=false
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile.web
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64/v8
cache-from: type=gha
cache-to: type=gha,mode=max