Skip to content

Commit

Permalink
Merge pull request #1 from Remi-Gau/update
Browse files Browse the repository at this point in the history
[ENH] set up CI
  • Loading branch information
Remi-Gau authored Aug 20, 2024
2 parents f5281d9 + f51d4ea commit 5f9dd98
Show file tree
Hide file tree
Showing 15 changed files with 230 additions and 130 deletions.
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# ignoring this might speed up build
# by preventing passing extra content to the docker daemon

.github
tests

*.simg
*.def
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
**/.git* annex.largefiles=nothing
CHANGELOG.md annex.largefiles=nothing
README.md annex.largefiles=nothing
.github/**/*.yml annex.largefiles=nothing
*.def annex.largefiles=nothing
14 changes: 14 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
# Documentation
# https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: monthly

- package-ecosystem: gitsubmodule
directory: /
schedule:
interval: monthly
28 changes: 28 additions & 0 deletions .github/workflows/apptainer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
name: apptainer build

on:
push:
branches: [master]
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
strategy:
matrix:
image: [Singularity_MCR.def, Singularity.def]
fail-fast: false
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: eWaterCycle/setup-apptainer@v2
with:
apptainer-version: 1.3.0
- name: build sif image
run: apptainer build cat12.sif ${{ matrix.image }}
30 changes: 30 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
name: docker build

on:
push:
branches: [master]
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: get test data
run: make tests/data/MoAEpilot
- name: Build the Docker image
run: |
docker build . --tag cat12
docker images
- name: help
run: docker run --rm cat12 view cat_standalone_segment.m
- name: test
run: docker run -v ${PWD}/tests/data/MoAEpilot:/data --rm cat12 /data/sub-01/anat/sub-01_T1w.nii -b cat_standalone_segment.m
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.simg
.simg

tests/data
23 changes: 23 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-yaml
- id: check-json
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-case-conflict
- id: check-merge-conflict
- id: mixed-line-ending

- repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt
rev: 0.2.3
hooks:
- id: yamlfmt
args: [--mapping, '4', --sequence, '4', --offset, '0']

- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
hooks:
- id: codespell
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

<!--
### Added
### Changed
### Deprecated
### Removed
### Fixed
### Security
-->

## [Unreleased]
112 changes: 63 additions & 49 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,58 +1,72 @@
FROM debian:bookworm-slim
FROM ubuntu:22.04@sha256:340d9b015b194dc6e2a13938944e0d016e57b9679963fdeb9ce021daac430221

LABEL org.opencontainers.image.authors="[email protected], Malgorzata Wierzba ([email protected]), Felix Hoffstaedter ([email protected])"
LABEL org.opencontainers.image.authors="[email protected], Malgorzata Wierzba ([email protected]), Felix Hoffstaedter ([email protected]), Remi Gau ([email protected])"
LABEL org.opencontainers.image.source="https://gin.g-node.org/felixh/cat12-container"
LABEL org.opencontainers.image.version="v1.1"

ARG DEBIAN_FRONTEND="noninteractive"

ENV CATversion="r2560"
ENV STANDALONE="/opt/spm12/toolbox/cat12/standalone"

RUN apt-get update -qq && \
apt-get -qq -y --no-install-recommends install \
build-essential \
ca-certificates \
curl \
unzip \
liboctave-dev \
libxext6 \
libxt6 \
moreutils \
octave \
wget \
&& apt-get clean \
&& rm -rf \
/tmp/hsperfdata* \
/var/*/apt/*/partial \
/var/lib/apt/lists/* \
/var/log/apt/term*

# install SPM12
RUN mkdir /opt/spm12 \
&& curl -fsSL --retry 5 https://github.com/spm/spm12/archive/r7771.tar.gz | tar -xzC /opt/spm12 --strip-components 1 \
&& curl -fsSL --retry 5 https://raw.githubusercontent.com/spm/spm-octave/main/spm12_r7771.patch | patch -p0 \
&& make -C /opt/spm12/src PLATFORM=octave distclean \
&& make -C /opt/spm12/src PLATFORM=octave \
&& make -C /opt/spm12/src PLATFORM=octave install \
&& ln -s /opt/spm12/bin/spm12-octave /usr/local/bin/spm12
LABEL org.opencontainers.image.version="v1.1dev"
LABEL org.opencontainers.image.licenses="MIT"
LABEL org.opencontainers.image.title="cat12-container"

ENV LANG="en_US.UTF-8" \
LC_ALL="en_US.UTF-8" \
FORCE_SPMMCR="1" \
SPM_HTML_BROWSER="0" \
MCR_INHIBIT_CTF_LOCK="1" \
MCR_VERSION="2017b"
ENV LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/lib/x86_64-linux-gnu:/opt/MCR-${MCR_VERSION}/v93/runtime/glnxa64:/opt/MCR-${MCR_VERSION}/v93/bin/glnxa64:/opt/MCR-${MCR_VERSION}/v93/sys/os/glnxa64:/opt/MCR-${MCR_VERSION}/v93/extern/bin/glnxa64" \
MATLABCMD="/opt/MCR-${MCR_VERSION}/v93/toolbox/matlab" \
XAPPLRESDIR="/opt//opt/MCR-${MCR_VERSION}/v93/x11/app-defaults" \
MCRROOT="/opt/MCR-${MCR_VERSION}/v93" \
CAT_VERSION=".8.1_r2042_R${MCR_VERSION}"
ENV SPMROOT="/opt/CAT12${CAT_VERSION}" \
PATH="/opt/CAT12${CAT_VERSION}:$PATH" \
STANDALONE="/opt/CAT12${CAT_VERSION}/standalone"

RUN export ND_ENTRYPOINT="/neurodocker/startup.sh" \
&& apt-get update -qq \
&& apt-get install -y -q --no-install-recommends \
apt-utils \
bc \
bzip2 \
ca-certificates \
curl \
dbus-x11 \
libncurses5 \
libxext6 \
libxmu6 \
libxpm-dev \
libxt6 \
locales \
openjdk-8-jre \
unzip \
&& rm -rf /var/lib/apt/lists/* \
&& sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen \
&& dpkg-reconfigure --frontend=noninteractive locales \
&& update-locale LANG="en_US.UTF-8" \
&& chmod 777 /opt && chmod a+s /opt

RUN echo "Downloading MATLAB Compiler Runtime ..." \
&& export TMPDIR="$(mktemp -d)" \
&& curl -o "$TMPDIR/mcr.zip" https://ssd.mathworks.com/supportfiles/downloads/R${MCR_VERSION}/deployment_files/R${MCR_VERSION}/installers/glnxa64/MCR_R${MCR_VERSION}_glnxa64_installer.zip \
&& unzip -q "$TMPDIR/mcr.zip" -d "$TMPDIR/mcrtmp" \
&& "$TMPDIR/mcrtmp/install" -destinationFolder /opt/MCR-${MCR_VERSION} -mode silent -agreeToLicense yes \
&& rm -rf "$TMPDIR" \
&& unset TMPDIR

RUN echo "Downloading standalone CAT12 ..." \
&& curl -fL -o /tmp/cat12.zip http://www.neuro.uni-jena.de/cat12/CAT12${CAT_VERSION}_MCR_Linux.zip \
&& unzip -q /tmp/cat12.zip -d /tmp \
&& rm -rf /tmp/cat12.zip \
&& mkdir -p /opt/CAT12${CAT_VERSION} \
&& mv /tmp/*${CAT_VERSION}*/* /opt/CAT12${CAT_VERSION}/ \
&& chmod -R 777 /opt/CAT12${CAT_VERSION} \
# Test
&& /opt/CAT12${CAT_VERSION}/spm12 function exit

# transfer code and set permission
RUN mkdir -p /code
COPY ./code /code
RUN ls /code && find /code -type f -print0 | xargs -0 chmod +r

# install CAT12
RUN mkdir -p /batch \
&& mkdir -p /downloads \
&& cd /downloads \
&& wget http://www.neuro.uni-jena.de/cat12/cat12_${CATversion}.zip && unzip -d /opt/spm12/toolbox/ cat12_${CATversion}.zip \
&& rm -fr /downloads \
&& cd ${STANDALONE} && chmod +rx *.sh \
&& cd /code && ln -s ${STANDALONE}/*.sh . \
&& cd /batch && ln -s ${STANDALONE}/*.m .

# clean
RUN rm -f /opt/spm12/src/*.{mex,o,a}
WORKDIR ${STANDALONE}

ENTRYPOINT ['/code/main "$@"']
ENTRYPOINT ["/code/main"]
27 changes: 22 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
# Project <insert name>
# CAT-12 container

## Dataset structure
Docker and Apptainer image for [CAT12](https://neuro-jena.github.io/cat/).

- All inputs (i.e. building blocks from other sources) are located in
`inputs/`.
- All custom code is located in `code/`.
CAT12 8.1 r2042
SPM12, version 7771 (standalone)
MATLAB, version 9.3.0.713579 (R2017b)


## Usage notes


### Example

```bash
docker build . --tag cat12
```

```bash
docker run -v ${PWD}/tests/data/MoAEpilot:/data \
--rm -it cat12 \
/data/sub-01/anat/sub-01_T1w.nii \
-b cat_standalone_segment.m
```
6 changes: 3 additions & 3 deletions Singularity → Singularity.def
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ From: debian:bookworm-slim
DEBIAN_FRONTEND=noninteractive apt-get --yes --quiet install \
octave \
liboctave-dev

mkdir /opt/spm12
curl -fsSL --retry 5 https://github.com/spm/spm12/archive/r7771.tar.gz | tar -xzC /opt/spm12 --strip-components 1
curl -fsSL --retry 5 https://github.com/spm/spm12/archive/r7771.tar.gz | tar -xzC /opt/spm12 --strip-components 1
curl -fsSL --retry 5 https://raw.githubusercontent.com/spm/spm-octave/main/spm12_r7771.patch | patch -p0
make -C /opt/spm12/src PLATFORM=octave distclean
make -C /opt/spm12/src PLATFORM=octave
make -C /opt/spm12/src PLATFORM=octave install
ln -s /opt/spm12/bin/spm12-octave /usr/local/bin/spm12

CATversion="r2560"

cd /downloads
Expand Down
2 changes: 1 addition & 1 deletion Singularity_MCR → Singularity_MCR.def
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ USAGE:
-a2 <STRING>| --arg2 <STRING> 2nd additional argument (otherwise use defaults or batch)
-a <STRING> | --add <STRING> add option to batch file

The first occurance of the parameter "<UNDEFINED>" in the batch file will be replaced by the
The first occurrence of the parameter "<UNDEFINED>" in the batch file will be replaced by the
list of input files. You can use the existing batch files in this folder or create your own batch
file with the SPM12 batch editor and leave the data field undefined. Please note that for creating
your own batch file CAT12 has to be called in expert mode because the CAT12 standalone installation
Expand Down
16 changes: 6 additions & 10 deletions code/main
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
#!/bin/bash

# Help
# Copy or view batch files

# Help
if [ "$#" = 0 ]
then
echo "ERROR: No arguments passed."
cat /.singularity.d/runscript.help
exec ${STANDALONE}/cat_standalone.sh
exit 1
fi

# Copy or view batch files

STANDALONE="/opt/spm12/toolbox/cat12/standalone"

if [ "$1" = "copy" ]
then
if [ "$2" = "all" ]
Expand All @@ -22,7 +19,7 @@ then
exit 0
elif [ -f ${STANDALONE}/"$2" ]
then
echo "Copying batch file to:"
echo "Copying batch file to:"
cp -vi ${STANDALONE}/"$2" "$3"
exit 0
else
Expand All @@ -37,13 +34,12 @@ then
cat ${STANDALONE}/"$2"
exit 0
else
echo "ERROR: batch file $2 not found. Available batch files are:"
echo "ERROR: batch file '$2' not found. Available batch files are:"
find ${STANDALONE} -name "*.m" -printf "%f\n"
exit 1
fi
fi

# Run CAT

NOW=$(date +%s)
exec /code/cat_standalone.sh "$@" 2>&1 |tee cat_$NOW.log
exec ${STANDALONE}/cat_standalone.sh "$@" 2>&1 | tee cat_$NOW.log
Loading

0 comments on commit 5f9dd98

Please sign in to comment.