Repository navigation
Add Dockerfile and workflow to publish image to GHCR #499
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ce87d82
Add Dockerfile and workflow to publish image to GHCR
bpinsard 9962c3e
Update .dockerignore
bpinsard c4a7c29
Update .github/workflows/docker-publish.yml
bpinsard 359a900
Update .github/workflows/docker-publish.yml
bpinsard 9268305
do not push to registry on PR
bpinsard d1af147
add pointers to Dockerfile and ghcr registry in the README
bpinsard 28034f2
tag with latest too
bpinsard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # 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 | ||
| .*rc | ||
| .zenodo.json | ||
| .pre-commit-config.yaml | ||
| .readthedhocs.yml | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| # Build the phys2bids container image and push it to GitHub Container Registry (ghcr.io). | ||
| # | ||
| # - Pull requests: build only, nothing is pushed. | ||
| # - Published releases and manual runs: build and push. | ||
|
|
||
| name: Docker | ||
|
|
||
| on: | ||
| release: | ||
| types: [created] | ||
|
|
||
| pull_request: | ||
| branches: [master] | ||
|
smoia marked this conversation as resolved.
Resolved
|
||
| 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@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@v4.4.0 | ||
|
|
||
| - name: Set up Docker Buildx | ||
| 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@v4.8.0 | ||
| with: | ||
| registry: ghcr.io | ||
| username: ${{ github.actor }} | ||
| password: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Extract image metadata (tags, labels) | ||
| id: meta | ||
| uses: docker/metadata-action@v6.2.0 | ||
| 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=${{ github.event_name == 'release' }} | ||
|
|
||
| - name: Build and push | ||
| 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 }} | ||
| cache-from: type=gha | ||
| cache-to: type=gha,mode=max | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.