diff --git a/.github/workflows/build_docker.yml b/.github/workflows/build_docker.yml index e670084..4053e2a 100644 --- a/.github/workflows/build_docker.yml +++ b/.github/workflows/build_docker.yml @@ -2,7 +2,7 @@ name: Build and Push Docker Image on: push: - branches: [main] + branches: [main, 'djay/pin-python-dockerfile'] workflow_dispatch: jobs: build-and-push: diff --git a/Dockerfile b/Dockerfile index d7728ee..0e3288d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,33 +1,42 @@ -FROM --platform=linux/amd64 condaforge/miniforge3:latest +# --- Stage 1: Build & Environment Prep --- +FROM ghcr.io/prefix-dev/pixi:latest AS build -WORKDIR /src/ +WORKDIR /src +COPY . /src -# Copy your code -COPY . /src/ +# Install git so pip can clone remote repository dependencies +RUN apt-get update && apt-get install -y --no-install-recommends \ + libgomp1 git wget unzip \ + && rm -rf /var/lib/apt/lists/* -# Disable user site packages -ENV PYTHONNOUSERSITE=1 +# Create the environment based on your lockfile and install dependencies +# This creates an isolated, self-contained environment in /src/.pixi/envs/default +RUN pixi install --locked -# Use bash for the following RUNs -SHELL ["/bin/bash", "-c"] - -# ---- ONE SINGLE RUN ---- -RUN set -e && \ - conda install -n base -c conda-forge mamba -y && \ - mamba create -y -n snakebids-env -c conda-forge -c bioconda python=3.11 snakebids appdirs unzip && \ - source /opt/conda/etc/profile.d/conda.sh && \ - conda activate snakebids-env && \ - ./autoafids/run.py test_data/bids_T1w test_out participant --participant-label 002 --use-conda --conda-create-envs-only --cores all --conda-prefix /src/conda-envs && \ - ./autoafids/run.py test_data/bids_T2w test_out participant --modality T2w --use-conda --conda-create-envs-only --cores all --conda-prefix /src/conda-envs && \ - ./autoafids/run.py test_data/bids_ct test_out participant --modality ct --use-conda --conda-create-envs-only --cores all --conda-prefix /src/conda-envs && \ - ./autoafids/run.py test_data/bids_T1w test_out participant --participant-label 002 --stereotaxy STN --use-conda --conda-create-envs-only --cores all --conda-prefix /src/conda-envs && \ - ./autoafids/run.py test_data/bids_T1w test_out participant --participant-label 002 --fidqc --use-conda --conda-create-envs-only --cores all --conda-prefix /src/conda-envs && \ - conda clean --all -y && \ - rm -rf /opt/conda/pkgs /root/.caches - -# Set snakemake profile -ENV SNAKEMAKE_PROFILE=/src/autoafids/workflow/profiles/docker-conda +# Run your autoafids pre-caching tasks inside the pixi environment +RUN pixi run ./autoafids/run.py test_data/bids_T1w test_out participant --participant-label 002 --use-conda --conda-create-envs-only --cores all --conda-prefix /src/conda-envs && \ + pixi run ./autoafids/run.py test_data/bids_T1w test_out participant --participant-label 002 --use-conda --conda-create-envs-only --cores all --conda-prefix /src/conda-envs --detect_with_nnlm && \ + pixi run ./autoafids/run.py test_data/bids_T2w test_out participant --modality T2w --use-conda --conda-create-envs-only --cores all --conda-prefix /src/conda-envs && \ + pixi run ./autoafids/run.py test_data/bids_ct test_out participant --modality ct --use-conda --conda-create-envs-only --cores all --conda-prefix /src/conda-envs && \ + pixi run ./autoafids/run.py test_data/bids_T1w test_out participant --participant-label 002 --stereotaxy STN --use-conda --conda-create-envs-only --cores all --conda-prefix /src/conda-envs && \ + pixi run ./autoafids/run.py test_data/bids_T1w test_out participant --participant-label 002 --fidqc --use-conda --conda-create-envs-only --cores all --conda-prefix /src/conda-envs + +# --- Stage 2: Tiny Production Image --- +# Use a lightweight glibc base image instead of a heavy Conda/Miniforge image +FROM ubuntu:24.04 AS production + +WORKDIR /src -# Set entrypoint -ENTRYPOINT ["/src/entrypoint.sh"] +RUN apt-get update && apt-get install -y --no-install-recommends \ + libgomp1 wget unzip \ + && rm -rf /var/lib/apt/lists/* + +# Copy your source code, pre-cached conda environments, and the built Pixi environment +COPY --from=build /src /src + +# Add the pixi environment binaries straight to the PATH so you don't have to "activate" it +ENV PATH="/src/.pixi/envs/default/bin:$PATH" +ENV SNAKEMAKE_PROFILE=/src/autoafids/workflow/profiles/docker-conda +ENV PYTHONNOUSERSITE=1 +ENTRYPOINT ["/src/entrypoint.sh"] \ No newline at end of file diff --git a/autoafids/workflow/rules/nnlm.smk b/autoafids/workflow/rules/nnlm.smk index fdbddff..462a57b 100644 --- a/autoafids/workflow/rules/nnlm.smk +++ b/autoafids/workflow/rules/nnlm.smk @@ -123,7 +123,7 @@ rule run_nnlm: cp $TMPDIR/output_dir/{wildcards.subject}.json {output.coords_json} # Cleanup temp dir - rm -rf $TMPDIR + # rm -rf $TMPDIR """ diff --git a/entrypoint.sh b/entrypoint.sh index c92d427..910adf8 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,4 +1,2 @@ #!/bin/bash -source /opt/conda/etc/profile.d/conda.sh -conda activate snakebids-env exec /src/autoafids/run.py "$@" \ No newline at end of file