Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build_docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
63 changes: 36 additions & 27 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
2 changes: 1 addition & 1 deletion autoafids/workflow/rules/nnlm.smk
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""


Expand Down
2 changes: 0 additions & 2 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
#!/bin/bash
source /opt/conda/etc/profile.d/conda.sh
conda activate snakebids-env
exec /src/autoafids/run.py "$@"
Loading