| 1 |
name: Docker Publish |
| 2 |
|
| 3 |
on: |
| 4 |
push: |
| 5 |
branches: |
| 6 |
- main |
| 7 |
tags: [ 'v*' ] |
| 8 |
|
| 9 |
jobs: |
| 10 |
publish-docker: |
| 11 |
name: Publish Docker Images |
| 12 |
runs-on: ubuntu-latest |
| 13 |
environment: |
| 14 |
name: Docker Hub |
| 15 |
url: https://ghcr.io/pyo3/maturin |
| 16 |
steps: |
| 17 |
- uses: actions/checkout@v4 |
| 18 |
- uses: dorny/paths-filter@v3 |
| 19 |
id: changes |
| 20 |
with: |
| 21 |
filters: | |
| 22 |
changed: |
| 23 |
- 'Cargo.toml' |
| 24 |
- 'Cargo.lock' |
| 25 |
- 'src/**' |
| 26 |
- 'Dockerfile' |
| 27 |
- '.github/workflows/docker.yml' |
| 28 |
- '.dockerignore' |
| 29 |
- name: Setup QEMU |
| 30 |
if: ${{ steps.changes.outputs.changed == 'true' || startsWith(github.ref, 'refs/tags/') }} |
| 31 |
uses: dbhi/qus/action@main |
| 32 |
- uses: docker/setup-buildx-action@v3 |
| 33 |
if: ${{ steps.changes.outputs.changed == 'true' || startsWith(github.ref, 'refs/tags/') }} |
| 34 |
- uses: docker/metadata-action@v5 |
| 35 |
if: ${{ steps.changes.outputs.changed == 'true' || startsWith(github.ref, 'refs/tags/') }} |
| 36 |
id: meta |
| 37 |
with: |
| 38 |
images: ghcr.io/pyo3/maturin |
| 39 |
- name: Login to GitHub Container Registry |
| 40 |
if: ${{ steps.changes.outputs.changed == 'true' || startsWith(github.ref, 'refs/tags/') }} |
| 41 |
uses: docker/login-action@v3 |
| 42 |
with: |
| 43 |
registry: ghcr.io |
| 44 |
username: ${{ github.actor }} |
| 45 |
password: ${{ secrets.GITHUB_TOKEN }} |
| 46 |
- name: Build and push |
| 47 |
if: ${{ steps.changes.outputs.changed == 'true' || startsWith(github.ref, 'refs/tags/') }} |
| 48 |
uses: docker/build-push-action@v6 |
| 49 |
with: |
| 50 |
context: . |
| 51 |
platforms: linux/amd64,linux/arm64 |
| 52 |
push: true |
| 53 |
tags: ${{ steps.meta.outputs.tags }} |
| 54 |
labels: ${{ steps.meta.outputs.labels }} |
| 55 |
# https://github.com/docker/build-push-action/blob/master/docs/advanced/cache.md#registry-cache |
| 56 |
cache-from: type=registry,ref=ghcr.io/pyo3/maturin:buildcache |
| 57 |
cache-to: type=registry,ref=ghcr.io/pyo3/maturin:buildcache,mode=max |