Skip to content

Commit

Permalink
Merge pull request #8 from nipreps/enh/add-dockerfile
Browse files Browse the repository at this point in the history
ENH: Add ``Dockerfile``
  • Loading branch information
oesteban authored May 5, 2022
2 parents 2fbbe6f + a9cc214 commit 9a378ea
Show file tree
Hide file tree
Showing 3 changed files with 203 additions and 0 deletions.
33 changes: 33 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# python cache
.cache/
__pycache__/**/*
__pycache__
*.pyc

# python distribution
build/**/*
build
dist/**/*
dist
mriqc.egg-info/**/*
mriqc.egg-info
.eggs/**/*
.eggs
src/**/*
src/
notebooks/
.maint/

# releasing
Makefile

# git
.github/
.gitignore
.gitattributes
.git/**/*
.git


# local build of book
docs/_build
70 changes: 70 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@

name: Docker Image CI

on:
push:
# Publish `main` as Docker `latest` image.
branches:
- main
release:
types: [published]

# Run tests for any PRs.
pull_request:

env:
IMAGE_NAME: qc-book

jobs:
# Push image to GitHub Packages.
# See also https://docs.docker.com/docker-hub/builds/
push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Log into GitHub Container Registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin

- uses: satackey/[email protected]
# Ignore the failure of a step and avoid terminating the job.
continue-on-error: true

- name: Build image
run: docker build . --file Dockerfile --tag $IMAGE_NAME --build-arg GITHUB_PAT=${{ secrets.GITHUB_TOKEN }}

- name: Push image to GitHub Container Registry
if: github.event_name == 'release'
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "main" ] && VERSION=latest
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
- name: Log into DockerHub Container Registry
run: echo "${{ secrets.DOCKER_TOKEN }}" | docker login -u niprepsbot --password-stdin

- name: Push image to DockerHub Container Registry
if: github.event_name == 'release'
run: |
IMAGE_ID=nipreps/${IMAGE_NAME}
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "main" ] && VERSION=latest
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
100 changes: 100 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# NiPreps' QC-Book Docker Container Image distribution
#
# MIT License
#
# Copyright (c) 2021 The NiPreps Developers
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

FROM jupyter/datascience-notebook:2022-03-02

RUN arch=$(uname -m) && \
if [ "${arch}" == "aarch64" ]; then \
# Prevent libmamba from sporadically hanging on arm64 under QEMU
# <https://github.com/mamba-org/mamba/issues/1611>
export G_SLICE=always-malloc; \
fi && \
mamba install --quiet --yes 'r-rnifti' && \
mamba clean --all -f -y && \
fix-permissions "${CONDA_DIR}" && \
fix-permissions "/home/${NB_USER}"

USER root

# Prepare environment
RUN apt-get update && \
apt-get install -y --no-install-recommends \
ca-certificates \
curl \
dvipng \
fontconfig \
git \
unzip && \
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

USER $NB_UID

# Install Libre Franklin font
RUN curl -sSL "https://fonts.google.com/download?family=Libre%20Franklin" -o /tmp/LibreFranklin.zip \
&& mkdir -p /home/${NB_USER}/.fonts \
&& pushd /home/${NB_USER}/.fonts \
&& unzip -e /tmp/LibreFranklin.zip \
&& popd \
&& rm /tmp/LibreFranklin.zip \
&& fix-permissions /home/${NB_USER}/.fonts

RUN fc-cache -v

ARG GITHUB_PAT
RUN R -e "devtools::install_github('AWKruijt/eMergeR')"

# Installing precomputed python packages
RUN conda install -y -c conda-forge -c anaconda \
attr \
jupytext \
nibabel \
nilearn \
matplotlib \
numpy \
pandas \
pip \
requests \
scipy \
scikit-learn \
zlib && \
conda clean --all -f -y && \
fix-permissions "${CONDA_DIR}" && \
fix-permissions "/home/${NB_USER}"

# Installing nipreps-book
COPY requirements.txt /tmp/requirements.txt

USER root
RUN pip install --no-cache-dir -r /tmp/requirements.txt \
&& fix-permissions "${CONDA_DIR}" \
&& rm /tmp/requirements.txt

USER $NB_UID

# Precaching fonts, set 'Agg' as default backend for matplotlib
RUN rm -rf /home/${NB_USER}/.cache/matplotlib \
&& python -c "from matplotlib import font_manager" \
&& sed -i 's/\(backend *: \).*$/\1Agg/g' $( python -c "import matplotlib; print(matplotlib.matplotlib_fname())" ) \
&& mkdir -p /home/${NB_USER}/.config/ \
&& echo 'notebook_extensions = "ipynb,Rmd"' >> /home/${NB_USER}/.config/jupytext.toml

0 comments on commit 9a378ea

Please sign in to comment.