From ce87d824236292af54cc7b5b44f5cc060c98ac4a Mon Sep 17 00:00:00 2001 From: bpinsard Date: Tue, 24 Nov 2026 09:14:28 -0500 Subject: [PATCH 1/7] Add Dockerfile and workflow to publish image to GHCR Multi-stage Dockerfile installing phys2bids with the acq and mat extras into a venv, running as a non-root user with the CLI as entrypoint. A GitHub Actions workflow builds multi-arch images and pushes them to ghcr.io on master pushes, tags and manual runs; pull requests build without pushing. Co-Authored-By: Claude Haiku 5.5 --- .dockerignore | 18 +++++++ .github/workflows/docker-publish.yml | 75 ++++++++++++++++++++++++++++ Dockerfile | 47 +++++++++++++++++ 3 files changed, 140 insertions(+) create mode 100644 .dockerignore create mode 100644 .github/workflows/docker-publish.yml create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..92cf081f8 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,18 @@ +# Keep .git in the context: versioneer needs it to compute the package version. +# It is not copied into the final image (see the multi-stage Dockerfile). +.claude +.circleci +.github +.pytest_cache +.coverage* +.venv +venv +build +dist +docs +htmlcov +**/__pycache__ +**/*.pyc +**/*.egg-info +Dockerfile +.dockerignore diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 000000000..19c8496ab --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,75 @@ +# Build the phys2bids container image and push it to GitHub Container Registry (ghcr.io). +# +# - Pull requests: build only, nothing is pushed. +# - Pushes to master, version tags (v*) and manual runs: build and push. + +name: Docker + +on: + push: + branches: [master] + tags: ["*"] + pull_request: + branches: [master] + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: docker-${{ github.ref }} + cancel-in-progress: true + +jobs: + build-and-push: + name: Build and push image + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + # Full history so versioneer can derive the package version from tags. + fetch-depth: 0 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to GitHub Container Registry + # Pull requests from forks get no write token, so skip login for them. + if: github.event_name != 'pull_request' + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract image metadata (tags, labels) + id: meta + uses: docker/metadata-action@v5 + with: + images: ghcr.io/${{ github.repository }} + tags: | + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=raw,value=latest,enable={{is_default_branch}} + + - name: Build and push + uses: docker/build-push-action@v6 + with: + context: . + file: ./Dockerfile + platforms: linux/amd64,linux/arm64 + 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 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..f344e17f2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,47 @@ +# syntax=docker/dockerfile:1 +# +# phys2bids container image. +# +# Build: docker build -t phys2bids . +# Run: docker run --rm -v "$PWD":/data -w /data phys2bids -h + +ARG PYTHON_VERSION=3.12 + +# ---- Build stage: install phys2bids and its optional readers into a venv ---- +FROM python:${PYTHON_VERSION}-slim AS builder + +ENV PIP_NO_CACHE_DIR=1 \ + PIP_DISABLE_PIP_VERSION_CHECK=1 + +RUN python -m venv /opt/venv +ENV PATH="/opt/venv/bin:$PATH" + +WORKDIR /src +COPY . . + +# versioneer reads the version from git metadata, so .git must be present in +# the build context (it is not copied into the final image). +RUN pip install --upgrade pip \ + && pip install ".[acq,mat]" + +# ---- Runtime stage: only the virtualenv, no build tooling or sources ---- +FROM python:${PYTHON_VERSION}-slim + +LABEL org.opencontainers.image.title="phys2bids" \ + org.opencontainers.image.description="Python library to convert physiological data files into BIDS format" \ + org.opencontainers.image.licenses="Apache-2.0" \ + org.opencontainers.image.source="https://github.com/physiopy/phys2bids" + +COPY --from=builder /opt/venv /opt/venv +ENV PATH="/opt/venv/bin:$PATH" \ + PYTHONUNBUFFERED=1 + +# Run as an unprivileged user; mount data at /data. +RUN useradd --create-home --uid 1000 phys2bids \ + && mkdir /data \ + && chown phys2bids:phys2bids /data +USER phys2bids +WORKDIR /data + +ENTRYPOINT ["phys2bids"] +CMD ["-h"] From 9962c3e10afa039bfcc6ef4758ac4c9b2af2b2e1 Mon Sep 17 00:00:00 2001 From: Basile Date: Tue, 24 Nov 2026 12:43:59 -0500 Subject: [PATCH 2/7] Update .dockerignore Co-authored-by: Stefano Moia --- .dockerignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.dockerignore b/.dockerignore index 92cf081f8..8b7d8cb4c 100644 --- a/.dockerignore +++ b/.dockerignore @@ -16,3 +16,7 @@ htmlcov **/*.egg-info Dockerfile .dockerignore +.*rc +.zenodo.json +.pre-commit-config.yaml +.readthedhocs.yml From c4a7c2929787f87b0b0c115e2cf4ddd824e4df11 Mon Sep 17 00:00:00 2001 From: Basile Date: Tue, 24 Nov 2026 12:44:08 -0500 Subject: [PATCH 3/7] Update .github/workflows/docker-publish.yml Co-authored-by: Stefano Moia --- .github/workflows/docker-publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 19c8496ab..055820c22 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -30,7 +30,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@v7 with: # Full history so versioneer can derive the package version from tags. fetch-depth: 0 From 359a9002eb2a23dddd71959379f5f648a2805830 Mon Sep 17 00:00:00 2001 From: Basile Date: Tue, 24 Nov 2026 12:44:21 -0500 Subject: [PATCH 4/7] Update .github/workflows/docker-publish.yml Co-authored-by: Stefano Moia --- .github/workflows/docker-publish.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 055820c22..3256df467 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -6,9 +6,9 @@ name: Docker on: - push: - branches: [master] - tags: ["*"] + release: + types: [created] + pull_request: branches: [master] workflow_dispatch: From 9268305868df56623c0fddf4d335adb20de9b35d Mon Sep 17 00:00:00 2001 From: bpinsard Date: Tue, 24 Nov 2026 12:48:15 -0500 Subject: [PATCH 5/7] do not push to registry on PR --- .github/workflows/docker-publish.yml | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 3256df467..558b4f73a 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -1,7 +1,7 @@ # Build the phys2bids container image and push it to GitHub Container Registry (ghcr.io). # # - Pull requests: build only, nothing is pushed. -# - Pushes to master, version tags (v*) and manual runs: build and push. +# - Published releases and manual runs: build and push. name: Docker @@ -30,21 +30,21 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v7 + uses: actions/checkout@v7.0.1 with: # Full history so versioneer can derive the package version from tags. fetch-depth: 0 - name: Set up QEMU - uses: docker/setup-qemu-action@v3 + uses: docker/setup-qemu-action@v4.4.0 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 + uses: docker/setup-buildx-action@v4.4.1 - name: Log in to GitHub Container Registry # Pull requests from forks get no write token, so skip login for them. if: github.event_name != 'pull_request' - uses: docker/login-action@v3 + uses: docker/login-action@v4.8.0 with: registry: ghcr.io username: ${{ github.actor }} @@ -52,7 +52,7 @@ jobs: - name: Extract image metadata (tags, labels) id: meta - uses: docker/metadata-action@v5 + uses: docker/metadata-action@v6.2.0 with: images: ghcr.io/${{ github.repository }} tags: | @@ -63,11 +63,12 @@ jobs: type=raw,value=latest,enable={{is_default_branch}} - name: Build and push - uses: docker/build-push-action@v6 + uses: docker/build-push-action@v7.4.0 with: context: . file: ./Dockerfile platforms: linux/amd64,linux/arm64 + # Never push from pull requests: they only build to check the Dockerfile. push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} From d1af147dd824c8144f5913857bbb5ddc6aa98332 Mon Sep 17 00:00:00 2001 From: bpinsard Date: Tue, 24 Nov 2026 12:53:26 -0500 Subject: [PATCH 6/7] add pointers to Dockerfile and ghcr registry in the README --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index d6f6aac7e..926bf3a91 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,7 @@ Shortcuts: - [Developer installation](https://phys2bids.readthedocs.io/en/latest/contributing.html#linux-and-mac-developer-installation) - [**Contributor guide**](https://phys2bids.readthedocs.io/en/latest/contributorfile.html) - [**Code of Conduct**](https://phys2bids.readthedocs.io/en/latest/conduct.html) +- [Docker image](#docker) - [Developer calls calendar](https://calendar.google.com/calendar/u/0?cid=amoycDQ1MTdhMWdpaHNuNzlnOW1ucHJkMjRAZ3JvdXAuY2FsZW5kYXIuZ29vZ2xlLmNvbQ) ## Tested OSs @@ -60,6 +61,17 @@ Hence, while **we cannot ensure that phys2bids will run on Windows or MacOS/iOS* We apologise for any discomfort. +## Docker +A container image with `phys2bids` installed is published to the GitHub Container Registry: [`ghcr.io/physiopy/phys2bids`](https://github.com/physiopy/phys2bids/pkgs/container/phys2bids). The image is built from the [`Dockerfile`](https://github.com/physiopy/phys2bids/blob/master/Dockerfile) at the root of the repository. + +```bash +docker pull ghcr.io/physiopy/phys2bids:latest +docker run --rm -v "$PWD":/data ghcr.io/physiopy/phys2bids:latest -h +``` + +The container runs as a non-root user with `/data` as its working directory, so mount the folder holding your physiological files there. +That image do not support spike2. +