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