| 1 |
######################################################### |
| 2 |
# file-normalizer stage |
| 3 |
# In order to use BuildKit remote caching, input files must have |
| 4 |
# not only the right content hash, but also the right permissions. |
| 5 |
# Git only tracks whether the owner can execute a file. |
| 6 |
# Here we bring in all files that are going to be used in the |
| 7 |
# subsequent stage and normalize the permissions. |
| 8 |
######################################################### |
| 9 |
|
| 10 |
FROM mcr.microsoft.com/oss/busybox/busybox:1.33.1 AS file-normalizer |
| 11 |
|
| 12 |
COPY environment.yml .devcontainer/devcontainer.bashrc /data/ |
| 13 |
RUN chmod -R 555 /data/ |
| 14 |
|
| 15 |
RUN mkdir -p /entrypoints |
| 16 |
COPY docker/entrypoint.sh /entrypoints/ |
| 17 |
COPY docker/entrypoint-stream.sh /entrypoints/ |
| 18 |
|
| 19 |
RUN sed -i 's/\r$//' /entrypoints/*.sh |
| 20 |
RUN chmod +x /entrypoints/*.sh |
| 21 |
|
| 22 |
FROM mcr.microsoft.com/devcontainers/base:ubuntu-24.04 AS basecontainer |
| 23 |
|
| 24 |
# Install needed packages and setup non-root user. |
| 25 |
ARG USERNAME="vscode" |
| 26 |
ARG USER_UID=1000 |
| 27 |
ARG USER_GID=$USER_UID |
| 28 |
ARG CONDA_GID=900 |
| 29 |
ARG CONDA_ENVIRONMENT_NAME=ismrmrd |
| 30 |
|
| 31 |
RUN apt-get update && apt-get install -y \ |
| 32 |
libc6-dbg \ |
| 33 |
&& rm -rf /var/lib/apt/lists/* |
| 34 |
|
| 35 |
ARG MINIFORGE_VERSION=25.11.0-1 |
| 36 |
|
| 37 |
# Based on https://github.com/conda-forge/miniforge-images/blob/master/ubuntu/Dockerfile |
| 38 |
RUN wget --no-hsts --quiet https://github.com/conda-forge/miniforge/releases/download/${MINIFORGE_VERSION}/Miniforge3-${MINIFORGE_VERSION}-Linux-$(uname -m).sh -O /tmp/miniforge.sh \ |
| 39 |
&& /bin/bash /tmp/miniforge.sh -b -p /opt/conda \ |
| 40 |
&& rm /tmp/miniforge.sh \ |
| 41 |
&& /opt/conda/bin/conda clean --tarballs --index-cache --packages --yes \ |
| 42 |
&& find /opt/conda -follow -type f -name '*.a' -delete \ |
| 43 |
&& find /opt/conda -follow -type f -name '*.pyc' -delete \ |
| 44 |
&& /opt/conda/bin/conda clean --force-pkgs-dirs --all --yes \ |
| 45 |
&& groupadd -r conda --gid ${CONDA_GID} \ |
| 46 |
&& usermod -aG conda ${USERNAME} \ |
| 47 |
&& chown -R :conda /opt/conda \ |
| 48 |
&& chmod -R g+w /opt/conda \ |
| 49 |
&& find /opt -type d | xargs -n 1 chmod g+s |
| 50 |
|
| 51 |
FROM basecontainer AS devcontainer |
| 52 |
|
| 53 |
ARG USER_UID |
| 54 |
ARG USER_GID |
| 55 |
|
| 56 |
# Create a conda environment from the environment file in the repo root. |
| 57 |
COPY --from=file-normalizer --chown=$USER_UID:conda /data/environment.yml /tmp/build/ |
| 58 |
RUN umask 0002 \ |
| 59 |
&& /opt/conda/bin/conda env create -f /tmp/build/environment.yml \ |
| 60 |
&& /opt/conda/bin/conda clean -fy \ |
| 61 |
&& sudo chown -R :conda /opt/conda/envs |
| 62 |
|
| 63 |
# Add a file that is to be sourced from .bashrc and from the devops pipeline stages |
| 64 |
COPY --from=file-normalizer /data/devcontainer.bashrc /opt/devcontainer/ |
| 65 |
|
| 66 |
# Add a section to /etc/bash.bashrc that ensures that a section is present at the end of ~/.bashrc. |
| 67 |
# We can't just write to .bashrc from here because it will be overwritten if the devcontainer user has |
| 68 |
# opted to use their own dotfiles repo. The dotfiles repo is cloned after the postCreateCommand |
| 69 |
# in the devcontainer.json file is executed. |
| 70 |
RUN echo "\n\ |
| 71 |
if ! grep -q \"^source /opt/devcontainer/devcontainer.bashrc\" \${HOME}/.bashrc; then\n\ |
| 72 |
echo \"source /opt/devcontainer/devcontainer.bashrc\" >> \${HOME}/.bashrc\n\ |
| 73 |
fi\n" >> /etc/bash.bashrc |
| 74 |
|
| 75 |
ENV CMAKE_GENERATOR=Ninja |
| 76 |
|
| 77 |
# Create a kits file for the VSCode CMake Tools extension, so you are not prompted for which kit to select whenever you open VSCode |
| 78 |
RUN mkdir -p /home/vscode/.local/share/CMakeTools \ |
| 79 |
&& echo '[{"name":"GCC-15","compilers":{"C":"/opt/conda/envs/ismrmrd/bin/x86_64-conda-linux-gnu-gcc","CXX":"/opt/conda/envs/ismrmrd/bin/x86_64-conda-linux-gnu-g++"}}]' > /home/vscode/.local/share/CMakeTools/cmake-tools-kits.json \ |
| 80 |
&& chown vscode:conda /home/vscode/.local/share/CMakeTools/cmake-tools-kits.json |
| 81 |
|
| 82 |
FROM devcontainer AS ismrmrd-build |
| 83 |
|
| 84 |
ARG USER_UID |
| 85 |
ARG USER_GID |
| 86 |
SHELL ["/bin/bash", "-c"] |
| 87 |
COPY --chown=$USER_UID:$USER_GID . /opt/code/ismrmrd/ |
| 88 |
|
| 89 |
RUN . /opt/conda/etc/profile.d/conda.sh && umask 0002 && conda activate ismrmrd && mkdir -p /opt/package && \ |
| 90 |
cd /opt/code/ismrmrd && \ |
| 91 |
mkdir build && \ |
| 92 |
cd build && \ |
| 93 |
cmake -GNinja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/opt/package ../ && \ |
| 94 |
ninja && \ |
| 95 |
ninja install |
| 96 |
|
| 97 |
FROM ismrmrd-build AS ismrmrd-test |
| 98 |
|
| 99 |
ENTRYPOINT [ "/opt/code/ismrmrd/docker/entrypoint.sh", "python", "/opt/code/ismrmrd/docker/validate_results.py" ] |
| 100 |
|
| 101 |
FROM basecontainer AS ismrmrd |
| 102 |
|
| 103 |
ARG USER_UID |
| 104 |
|
| 105 |
RUN apt-get update && apt-get install -y socat \ |
| 106 |
&& rm -rf /var/lib/apt/lists/* |
| 107 |
|
| 108 |
COPY --from=file-normalizer --chown=$USER_UID:conda /data/environment.yml /tmp/build/ |
| 109 |
RUN grep -v "#.*\<dev\>" /tmp/build/environment.yml > /tmp/build/filtered_environment.yml \ |
| 110 |
&& mv /tmp/build/filtered_environment.yml /tmp/build/environment.yml \ |
| 111 |
&& umask 0002 \ |
| 112 |
&& /opt/conda/bin/conda env create -f /tmp/build/environment.yml \ |
| 113 |
&& /opt/conda/bin/conda clean -fy \ |
| 114 |
&& sudo chown -R :conda /opt/conda/envs |
| 115 |
|
| 116 |
COPY --from=ismrmrd-build --chown=$USER_UID:conda /opt/package /opt/conda/envs/ismrmrd/ |
| 117 |
COPY --from=file-normalizer --chown=$USER_UID:conda /entrypoints/entrypoint.sh /opt/ |
| 118 |
COPY --from=file-normalizer --chown=$USER_UID:conda /entrypoints/entrypoint-stream.sh /opt/ |
| 119 |
|
| 120 |
ENTRYPOINT [ "/opt/entrypoint.sh" ] |
| 121 |
|
| 122 |
|
| 123 |
FROM ismrmrd AS ismrmrd-stream-recon |
| 124 |
|
| 125 |
ENTRYPOINT [ "/opt/entrypoint-stream.sh" ] |
| 126 |
|
| 127 |
FROM ismrmrd AS ismrmrd-stream-recon-server |
| 128 |
|
| 129 |
ENTRYPOINT [ "/opt/entrypoint-stream.sh", "--socket-port", "9002" ] |
| 130 |
EXPOSE 9002 |