Repository navigation
107 lines (103 loc) · 3.9 KB
/
Copy pathdocker.yml
File metadata and controls
107 lines (103 loc) · 3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
name: Docker image
# Builds the image for amd64 and arm64 (Apple silicon, ARM servers) and runs the unit tests in
# each, when the image or the dependencies change. A version tag (v*), or a manual run with
# "publish", also pushes both to Docker Hub (mattechlab/monalisa-python) and to the GitHub
# Container Registry (ghcr.io/mattechlab/monalisa-python). See docs/docker.md, "Published image".
#
# Secrets: DOCKERHUB_USERNAME (mattechlab) and DOCKERHUB_TOKEN (a personal access token of that
# account with Read, Write, Delete access: Delete is needed to update the description).
on:
push:
branches: [main]
tags: ["v*"] # path filters do not apply to tags: every version tag publishes
paths: [Dockerfile, .dockerignore, compose.yaml, pyproject.toml, .github/workflows/docker.yml]
pull_request:
paths: [Dockerfile, .dockerignore, compose.yaml, pyproject.toml, .github/workflows/docker.yml]
workflow_dispatch:
inputs:
publish:
description: "Publish the image (tag: latest)"
type: boolean
default: false
env:
DOCKERHUB_IMAGE: mattechlab/monalisa-python
GHCR_IMAGE: ghcr.io/mattechlab/monalisa-python
jobs:
test:
strategy:
fail-fast: false
matrix:
include:
- arch: amd64
runner: ubuntu-latest
- arch: arm64
runner: ubuntu-24.04-arm # native ARM runner (free for public repositories)
runs-on: ${{ matrix.runner }}
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- name: Build
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/${{ matrix.arch }}
load: true
tags: monalisa-python:test
cache-from: type=gha,scope=image-${{ matrix.arch }}
cache-to: type=gha,scope=image-${{ matrix.arch }},mode=max
- name: Unit tests in the image
run: docker run --rm monalisa-python:test xvfb-run -a pytest tests/unit -q
publish:
needs: test
if: startsWith(github.ref, 'refs/tags/v') || inputs.publish
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- name: Tags
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.DOCKERHUB_IMAGE }}
${{ env.GHCR_IMAGE }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=latest
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Log in to ghcr.io
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Both platforms in one multi-platform image. The layers come from the cache of the test
# job, so the arm64 build does not run again under emulation unless the cache missed.
- name: Publish
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: |
type=gha,scope=image-amd64
type=gha,scope=image-arm64
- name: Docker Hub description
uses: peter-evans/dockerhub-description@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
repository: ${{ env.DOCKERHUB_IMAGE }}
short-description: "Monalisa MRI reconstruction (Python port) with JupyterLab, napari and the tutorial"
readme-filepath: docs/dockerhub.md