Skip to content

Commit

Permalink
Add container message to trackusage
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelzwiers committed Feb 6, 2025
1 parent df40db3 commit 199864c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
19 changes: 15 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,38 @@ RUN mkdir -p /opt/miniconda3; \
. /root/.bashrc; \
\
# Create a conda env and install FSL tools needed for (me)deface and slicereport. NB: Keep the version the same as the Docker base image
conda create -n fsl python=3.10; \
conda create -n fsl python=3.12; \
conda install -n fsl -c https://fsl.fmrib.ox.ac.uk/fsldownloads/fslconda/public/ -c conda-forge fsl-libvis fsl-avwutils fsl-flirt; \
\
# Pack the fsl environment into fsl.tar.gz and unpack it in /opt/fsl \
# Pack the fsl environment into fsl.tar.gz and unpack it in /opt/fsl
conda install -c conda-forge conda-pack; \
conda pack -n fsl; \
mkdir /opt/fsl && tar -xzf fsl.tar.gz -C /opt/fsl; \
/opt/fsl/bin/conda-unpack
/opt/fsl/bin/conda-unpack; \
\
# Clone bidscoin
git clone https://github.com/Donders-Institute/bidscoin.git /opt/bidscoin; \
cd /opt/bidscoin; \
rm -rf docs tests .git


FROM python:3.12-slim

# Install the dcm2niix build. NB: Obsolete with the new `pip install bidscoin[dcm2niix2bids]` extras option
COPY --from=builder /usr/local/bin/dcm2niix /usr/local/bin/dcm2niix
COPY --from=builder /opt/fsl /opt/fsl
# Only needed for pip install from GitHub
# COPY --from=builder /opt/bidscoin /opt/bidscoin

# Set environment variables
ENV FSLDIR=/opt/fsl FSLOUTPUTTYPE=NIFTI_GZ \
PATH=$PATH:/opt/fsl/bin \
PIP_NO_CACHE_DIR=off
PIP_NO_CACHE_DIR=off \
CONTAINER=Docker

# First install pyqt as Debian package to solve dependencies issues occurring when installed with pip
# Then install the latest stable BIDScoin release (add build-essential for newer python:3-slim base images (pip needs gcc and wayland support is not yet provided for))
RUN apt update && apt -y --no-install-recommends install pigz curl python3-pyqt6 build-essential libgl1 libxcb-cursor0 dbus qt6-wayland && apt clean; \
pip install bidscoin[spec2nii2bids,deface]
# pip install bidscoin[spec2nii2bids,deface]==VERSION
# pip install /opt/bidscoin[spec2nii2bids,deface] # = GitHub. NB: Also uncomment in xfiles from builder: `/opt/bidscoin /opt/bidscoin`
9 changes: 5 additions & 4 deletions apptainer.def
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Stage: builder
. /root/.bashrc

# Create a conda env and install FSL tools needed for (me)deface and slicereport. NB: Keep the version the same as the Docker base image
conda create -n fsl python=3.10
conda create -n fsl python=3.12
conda install -n fsl -c https://fsl.fmrib.ox.ac.uk/fsldownloads/fslconda/public/ -c conda-forge fsl-libvis fsl-avwutils fsl-flirt

# Pack the fsl environment into fsl.tar.gz and unpack it in /opt/fsl
Expand Down Expand Up @@ -63,14 +63,15 @@ Stage: final
3) The current image does not include the Freesurfer/synthstrip software (needed for `skullstrip`)

%files from builder
# /opt/bidscoin /opt/bidscoin # Only needed for pip install from github
/usr/local/bin/dcm2niix /usr/local/bin/dcm2niix
/opt/fsl /opt/fsl
# /opt/bidscoin /opt/bidscoin # Only needed for pip install from GitHub

%environment
export FSLDIR=/opt/fsl FSLOUTPUTTYPE=NIFTI_GZ
export PATH=$PATH:/opt/fsl/bin
export PIP_NO_CACHE_DIR=off
export CONTAINER=Apptainer

%post
# Install curl (sometimes needed by dcm2niix) and pigz (to speed up dcm2niix)
Expand All @@ -81,9 +82,9 @@ Stage: final
apt -y --no-install-recommends install python3-pyqt6 build-essential libgl1 libxcb-cursor0 dbus qt6-wayland && apt clean # Add build-essential for newer python:3-slim base images (pip needs gcc and wayland support is not yet provided for)

# Install BIDScoin
# pip install /opt/bidscoin[spec2nii2bids,deface] # Also uncomment in xfiles from builder: `/opt/bidscoin /opt/bidscoin`
# pip install bidscoin[spec2nii2bids,deface]==VERSION
pip install bidscoin[spec2nii2bids,deface]
# pip install bidscoin[spec2nii2bids,deface]==VERSION
# pip install /opt/bidscoin[spec2nii2bids,deface] # = GitHub. NB: Also uncomment in xfiles from builder: `/opt/bidscoin /opt/bidscoin`

# Uncomment the line below if you get errors like: ImportError: libQt5Core.so.5: cannot open shared object file: No such file or directory
# strip --remove-section=.note.ABI-tag /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
Expand Down
2 changes: 2 additions & 0 deletions bidscoin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ def trackusage(event: str, message='', dryrun: bool=False) -> dict:
'hostid': hashlib.md5(platform.node().encode('utf8')).hexdigest()}
if message:
data['message'] = str(message)
if container := os.getenv('CONTAINER'):
data['container'] = container

# Return if the user disallows tracking, if it is a dry-, pytest-, or a DRMAA-run, or if this is not a stable (#.#.#) version
if not (os.getenv('BIDSCOIN_TRACKUSAGE') or config['bidscoin'].get('trackusage','yes')).upper() in ('1', 'TRUE', 'Y', 'YES') or dryrun \
Expand Down

0 comments on commit 199864c

Please sign in to comment.