Skip to content

Commit 2bc792a

Browse files
alexander-penevvgvassilev
authored andcommitted
Fix dockerfile
1 parent daac759 commit 2bc792a

File tree

3 files changed

+111
-58
lines changed

3 files changed

+111
-58
lines changed

Dockerfile

Lines changed: 100 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,19 @@
44
# https://hub.docker.com/r/jupyter/base-notebook/tags
55
ARG BASE_CONTAINER=jupyter/base-notebook
66
#ARG BASE_TAG=latest
7-
###ARG BASE_TAG=ubuntu-20.04
7+
ARG BASE_TAG=ubuntu-22.04
88
#TODO: Next ARG line(s) is temporary workaround.
99
# Remove them when we can build xeus-clang-repl with Xeus>=3.0
10-
ARG BASE_TAG=7285848c0a11
10+
#ARG BASE_TAG=7285848c0a11
1111
#ARG BASE_TAG=2023-01-24
12-
#ARG BASE_TAG=python-3.10.6
12+
#ENV VENV_PYTHON_VERSION=3.10.6
13+
ARG BASE_TAG=python-3.10.6
1314
FROM $BASE_CONTAINER:$BASE_TAG
1415

1516
LABEL maintainer="Xeus-clang-repl Project"
1617
#LABEL com.nvidia.volumes.needed="nvidia_driver"
1718

18-
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
19+
SHELL ["/bin/bash", "--login", "-o", "pipefail", "-c"]
1920

2021
USER root
2122

@@ -64,16 +65,63 @@ ENV LLVM_REQUIRED_VERSION=16
6465
# Copy git repository to home directory of container
6566
COPY --chown=${NB_UID}:${NB_GID} . "${HOME}"/
6667

68+
EXPOSE 8888 8889
69+
70+
# Configure container startup
71+
CMD ["start-notebook.sh", "--debug", "&>/home/jovyan/log.txt"]
72+
73+
USER root
74+
75+
# Fix start-notebook.sh
76+
RUN sed -i '2 i source /home/jovyan/.conda.init && conda activate .venv' /usr/local/bin/start-notebook.sh
77+
78+
# Make /home/runner directory and fix permisions
79+
RUN mkdir /home/runner && fix-permissions /home/runner
80+
81+
# Switch back to jovyan to avoid accidental container runs as root
82+
USER ${NB_UID}
83+
84+
ENV NB_PYTHON_PREFIX=${CONDA_DIR} \
85+
KERNEL_PYTHON_PREFIX=${CONDA_DIR} \
86+
CPLUS_INCLUDE_PATH="${CONDA_DIR}/include:/home/${NB_USER}/include:/home/runner/work/xeus-clang-repl/xeus-clang-repl/clang-dev/clang/include:/home/jovyan/clad/include:/home/jovyan/CppInterOp/include"
87+
88+
WORKDIR "${HOME}"
89+
90+
# CUDA
91+
ENV NVIDIA_VISIBLE_DEVICES=all
92+
ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility
93+
ENV NVIDIA_REQUIRE_CUDA "cuda>=12.1.1 driver>=530"
94+
95+
# VENV
96+
6797
# Jupyter Notebook, Lab, and Hub are installed in base image
6898
# ReGenerate a notebook server config
6999
# Cleanup temporary files
70100
# Correct permissions
71101
# Do all this in a single RUN command to avoid duplicating all of the
72102
# files across image layers when the permissions change
73-
WORKDIR /tmp
74103
#RUN mamba update --all --quiet --yes -c conda-forge && \
75-
RUN mamba install --quiet --yes -c conda-forge \
76-
# notebook,jpyterhub, jupyterlab are inherited from base-notebook container image
104+
RUN \
105+
set -x && \
106+
# setup virtual environment
107+
mamba create -y -n .venv python=3.10.6 && \
108+
#
109+
#echo "echo \"@ @ @ PROFILE @ @ @ \"" >> ~/.profile && \
110+
#echo "echo \"@ @ @ BASHRC @ @ @ \"" >> /home/jovyan/.bashrc && \
111+
mv /home/jovyan/.bashrc /home/jovyan/.bashrc.tmp && \
112+
touch /home/jovyan/.bashrc && \
113+
conda init bash && \
114+
mv /home/jovyan/.bashrc /home/jovyan/.conda.init && \
115+
mv /home/jovyan/.bashrc.tmp /home/jovyan/.bashrc && \
116+
conda init bash && \
117+
echo "source /home/jovyan/.conda.init && conda activate .venv" >> /home/jovyan/.bashrc && \
118+
#
119+
source /home/jovyan/.conda.init && \
120+
conda activate .venv && \
121+
fix-permissions "${CONDA_DIR}" && \
122+
#
123+
mamba install --quiet --yes -c conda-forge \
124+
# notebook, jpyterhub, jupyterlab are inherited from base-notebook container image
77125
# Other "our" conda installs
78126
cmake \
79127
#"clangdev=$LLVM_REQUIRED_VERSION" \
@@ -88,6 +136,7 @@ RUN mamba install --quiet --yes -c conda-forge \
88136
pytest \
89137
jupyter_kernel_test \
90138
&& \
139+
#rm /home/jovyan/.jupyter/jupyter_notebook_config.py && \
91140
jupyter notebook --generate-config -y && \
92141
mamba clean --all -f -y && \
93142
npm cache clean --force && \
@@ -96,38 +145,17 @@ RUN mamba install --quiet --yes -c conda-forge \
96145
fix-permissions "${CONDA_DIR}" && \
97146
fix-permissions "/home/${NB_USER}"
98147

99-
EXPOSE 8888
100-
101-
# Configure container startup
102-
CMD ["start-notebook.sh", "--debug", "&>/home/jovyan/log.txt"]
103-
104-
USER root
105-
106-
# Make /home/runner directory and fix permisions
107-
RUN mkdir /home/runner && fix-permissions /home/runner
108-
109-
# Switch back to jovyan to avoid accidental container runs as root
110-
USER ${NB_UID}
111-
112-
ENV NB_PYTHON_PREFIX=${CONDA_DIR} \
113-
KERNEL_PYTHON_PREFIX=${CONDA_DIR} \
114-
CPLUS_INCLUDE_PATH="${CONDA_DIR}/include:/home/${NB_USER}/include:/home/runner/work/xeus-clang-repl/xeus-clang-repl/clang-dev/clang/include:/home/jovyan/clad/include"
115-
116-
WORKDIR "${HOME}"
117-
118-
# CUDA
119-
ENV NVIDIA_VISIBLE_DEVICES=all
120-
ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility
121-
#ENV NVIDIA_REQUIRE_CUDA "cuda>=12.1.1 driver>=530"
122-
ENV NVIDIA_REQUIRE_CUDA "cuda>=12.1.1 driver>=530"
123-
124148
### Post Build
125149
RUN \
150+
set -x && \
151+
source /home/jovyan/.conda.init && \
152+
conda activate .venv && \
153+
#
154+
artifact_name="clang-dev" && \
126155
#
127156
# Install clang-dev from GH Artifact or Release asset
128157
#
129-
artifact_name="clang-dev" && \
130-
git_remote_origin_url=$(git config --get remote.origin.url) && \
158+
echo $PWD && git_remote_origin_url=$(git config --get remote.origin.url) && \
131159
echo "Debug: Remote origin url: $git_remote_origin_url" && \
132160
arr=(${git_remote_origin_url//\// }) && \
133161
gh_repo_owner=${arr[2]} && \
@@ -138,21 +166,32 @@ RUN \
138166
gh_f_repo_name=${gh_repo_name} && \
139167
h=$(git rev-parse HEAD) && \
140168
echo "Debug: Head h: $h" && \
141-
br=$(git branch) && \
169+
br=$(git rev-parse --abbrev-ref HEAD) && \
142170
echo "Debug: Branch br: $br" && \
143-
arr1=$(git show-ref --head | grep "$h" | grep -E "remotes|tags" | grep -o '[^/ ]*$') && \
171+
#FIXME: if `$h` is not pushed upstream this fails. We should just diagnose and move on.
172+
#git show-ref --head && echo $? && \
173+
#git show-ref --head | grep "$h" && echo $? && \
174+
#git show-ref --head | grep "$h" | grep -E "remotes|tags" && echo $? && \
175+
#git show-ref --head | grep "$h" | grep -E "remotes|tags" | grep -o '[^/ ]*$' && echo $? && \
176+
#arr1=$(git show-ref --head | grep "$h" | grep -E "remotes|tags" | grep -o '[^/ ]*$') && echo $? && \
177+
arr1=$br && \
144178
gh_repo_branch="${arr1[*]//\|}" && \
145179
gh_repo_branch_regex=" ${gh_repo_branch//$'\n'/ | } " && \
146180
gh_repo_branch_regex=$(echo "$gh_repo_branch_regex" | sed -e 's/[]\/$*.^[]/\\\\&/g') && \
147181
echo "Debug: Repo Branch: $gh_repo_branch" && \
148182
echo "Debug: Repo Branch Regex: $gh_repo_branch_regex" && \
149-
#
150183
mkdir -p /home/runner/work/xeus-clang-repl/xeus-clang-repl && \
151184
pushd /home/runner/work/xeus-clang-repl/xeus-clang-repl && \
152185
# repo
153-
repository_id=$(curl -s -H "Accept: application/vnd.github+json" "https://api.github.com/repos/${gh_repo_owner}/${gh_repo_name}" | jq -r ".id") && \
186+
echo "Debug: Repo owner/name: ${gh_repo_owner} / ${gh_repo_name}" && \
187+
188+
#RUN \
189+
# set -x && \
190+
source /home/jovyan/.conda.init && \
191+
conda activate .venv && \
192+
repository_id=$(curl -s -H "Accept: application/vnd.github+json" "https://api.github.com/repos/${gh_repo}" | jq -r ".id") && \
154193
echo "Debug: Repo id: $repository_id" && \
155-
artifacts_info=$(curl -s -H "Accept: application/vnd.github+json" "https://api.github.com/repos/${gh_repo_owner}/${gh_repo_name}/actions/artifacts?per_page=100&name=${artifact_name}") && \
194+
artifacts_info=$(curl -s -H "Accept: application/vnd.github+json" "https://api.github.com/repos/${gh_repo}/actions/artifacts?per_page=100&name=${artifact_name}") && \
156195
artifact_id=$(echo "$artifacts_info" | jq -r "[.artifacts[] | select(.expired == false and .workflow_run.repository_id == ${repository_id} and (\" \"+.workflow_run.head_branch+\" \" | test(\"${gh_repo_branch_regex}\")))] | sort_by(.updated_at)[-1].id") && \
157196
#download_url="https://nightly.link/${gh_repo_owner}/${gh_repo_name}/actions/artifacts/${artifact_id}.zip" && \
158197
download_url="https://link-to.alexander-penev.info/${gh_repo_owner}/${gh_repo_name}/actions/artifacts/${artifact_id}.zip" && \
@@ -161,7 +200,7 @@ RUN \
161200
echo "Debug: Forked Repo id: $f_repository_id" && \
162201
f_artifacts_info=$(curl -s -H "Accept: application/vnd.github+json" "https://api.github.com/repos/${gh_f_repo_owner}/${gh_f_repo_name}/actions/artifacts?per_page=100&name=${artifact_name}") && \
163202
f_artifact_id=$(echo "$f_artifacts_info" | jq -r "[.artifacts[] | select(.expired == false and .workflow_run.repository_id == ${f_repository_id} and (\" \"+.workflow_run.head_branch+\" \" | test(\"${gh_repo_branch_regex}\")))] | sort_by(.updated_at)[-1].id") && \
164-
#f_download_url="https://nightly.link/${gh_f_repo_owner}/${gh_f_repo_name}/actions/artifacts/${f_artifact_id}.zip" && \
203+
#f_download_url="https://nightly.link/${gh_f_repo_owner}/${gh_f_repo_name}/actions/artifacts/${f_artifact_id}.zip"
165204
f_download_url="https://link-to.alexander-penev.info/${gh_f_repo_owner}/${gh_f_repo_name}/actions/artifacts/${f_artifact_id}.zip" && \
166205
# tag
167206
for download_tag in $gh_repo_branch; do echo "Debug: try tag $download_tag:"; download_tag_url="https://github.com/${gh_repo_owner}/${gh_repo_name}/releases/download/${download_tag}/${artifact_name}.tar.bz2"; if curl --head --silent --fail -L $download_tag_url 1>/dev/null; then echo "found"; break; fi; done && \
@@ -184,7 +223,7 @@ RUN \
184223
#
185224
echo "Debug clang path: $PATH_TO_CLANG_DEV" && \
186225
export PATH_TO_LLVM_BUILD=$PATH_TO_CLANG_DEV/inst && \
187-
export VENV=/home/jovyan/.venv && \
226+
export VENV=/opt/conda/venv/.venv && \
188227
export PATH=$VENV/bin:$PATH_TO_LLVM_BUILD/bin:$PATH && \
189228
export LD_LIBRARY_PATH=$PATH_TO_LLVM_BUILD/lib:$LD_LIBRARY_PATH && \
190229
echo "export VENV=$VENV" >> ~/.profile && \
@@ -194,8 +233,7 @@ RUN \
194233
# Build CppInterOp
195234
#
196235
sys_incs=$(LC_ALL=C c++ -xc++ -E -v /dev/null 2>&1 | LC_ALL=C sed -ne '/starts here/,/End of/p' | LC_ALL=C sed '/^ /!d' | cut -c2- | tr '\n' ':') && \
197-
#export CPLUS_INCLUDE_PATH="${PATH_TO_LLVM_BUILD}/../llvm/include:${PATH_TO_LLVM_BUILD}/../clang/include:${PATH_TO_LLVM_BUILD}/include:${PATH_TO_LLVM_BUILD}/tools/clang/include:${sys_incs%:}"
198-
export CPLUS_INCLUDE_PATH="${PATH_TO_LLVM_BUILD}/include/llvm:${PATH_TO_LLVM_BUILD}/include/clange:${sys_incs%:}" && \
236+
export CPLUS_INCLUDE_PATH="${PATH_TO_LLVM_BUILD}/include/llvm:${PATH_TO_LLVM_BUILD}/include/clange:$CPLUS_INCLUDE_PATH:${sys_incs%:}" && \
199237
echo $CPLUS_INCLUDE_PATH && \
200238
git clone https://github.com/compiler-research/CppInterOp.git && \
201239
export CB_PYTHON_DIR="$PWD/cppyy-backend/python" && \
@@ -204,9 +242,9 @@ RUN \
204242
mkdir build && \
205243
cd build && \
206244
export CPPINTEROP_BUILD_DIR=$PWD && \
207-
cmake -DCMAKE_BUILD_TYPE=Release -DUSE_CLING=OFF -DUSE_REPL=ON -DLLVM_DIR=$PATH_TO_LLVM_BUILD -DLLVM_USE_LINKER=gold -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=$CPPINTEROP_DIR .. && \
245+
cmake -DCMAKE_BUILD_TYPE=Debug -DUSE_CLING=OFF -DUSE_REPL=ON -DLLVM_DIR=$PATH_TO_LLVM_BUILD -DLLVM_USE_LINKER=gold -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=$CPPINTEROP_DIR .. && \
208246
cmake --build . --parallel $(nproc --all) && \
209-
#make install -j$(nproc --all) && \
247+
#make install -j$(nproc --all)
210248
export CPLUS_INCLUDE_PATH="$CPPINTEROP_DIR/include:$CPLUS_INCLUDE_PATH" && \
211249
export LD_LIBRARY_PATH="${CONDA_DIR}/lib:$CPPINTEROP_DIR/lib:$LD_LIBRARY_PATH" && \
212250
echo "export LD_LIBRARY_PATH=$CPPINTEROP_DIR/lib:$LD_LIBRARY_PATH" >> ~/.profile && \
@@ -220,47 +258,42 @@ RUN \
220258
# Install CppInterOp
221259
(cd $CPPINTEROP_BUILD_DIR && cmake --build . --target install --parallel $(nproc --all)) && \
222260
# Build and Install cppyy-backend
223-
cmake -DCppInterOp_DIR=$CPPINTEROP_DIR .. && \
261+
cmake -DCMAKE_BUILD_TYPE=Debug -DCppInterOp_DIR=$CPPINTEROP_DIR .. && \
224262
cmake --build . --parallel $(nproc --all) && \
225263
cp libcppyy-backend.so $CPPINTEROP_DIR/lib/ && \
226264
cd ../.. && \
227265
#
228266
# Build and Install CPyCppyy
229267
#
230-
# setup virtual environment
231-
python3 -m venv .venv && \
232-
source $VENV/bin/activate && \
233268
# Install CPyCppyy
234269
git clone https://github.com/compiler-research/CPyCppyy.git && \
235270
cd CPyCppyy && \
236271
mkdir build && cd build && \
237-
cmake .. && \
272+
cmake -DCMAKE_BUILD_TYPE=Debug .. && \
238273
cmake --build . --parallel $(nproc --all) && \
239274
export CPYCPPYY_DIR=$PWD && \
240275
cd ../.. && \
241276
#
242277
# Build and Install cppyy
243278
#
244-
# source virtual environment
245-
source $VENV/bin/activate && \
246279
# Install cppyy
247280
git clone https://github.com/compiler-research/cppyy.git && \
248281
cd cppyy && \
249282
python -m pip install --upgrade . --no-deps && \
250283
cd .. && \
251284
# Run cppyy
252-
source $VENV/bin/activate && \
253285
#TODO: Fix cppyy path (/home/jovyan) to path to installed module
254286
export PYTHONPATH=$PYTHONPATH:$CPYCPPYY_DIR:$CB_PYTHON_DIR:/home/jovyan && \
255287
echo "export PYTHONPATH=$PYTHONPATH" >> ~/.profile && \
256-
echo "source $VENV/bin/activate" >> ~/.profile && \
257288
python -c "import cppyy" && \
258289
#
259290
# Build and Install xeus-clang-repl
260291
#
261292
mkdir build && \
262293
cd build && \
263294
export CPLUS_INCLUDE_PATH="/home/jovyan/clad/include:$CPLUS_INCLUDE_PATH" && \
295+
echo "export CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH" >> ~/.profile && \
296+
##echo "conda activate .venv" >> ~/.profile
264297
cmake -DCMAKE_BUILD_TYPE=Debug -DLLVM_CMAKE_DIR=$PATH_TO_LLVM_BUILD -DCMAKE_PREFIX_PATH=$KERNEL_PYTHON_PREFIX -DCMAKE_INSTALL_PREFIX=$KERNEL_PYTHON_PREFIX -DCMAKE_INSTALL_LIBDIR=lib -DLLVM_CONFIG_EXTRA_PATH_HINTS=${PATH_TO_LLVM_BUILD}/lib -DCPPINTEROP_DIR=$CPPINTEROP_BUILD_DIR -DLLVM_REQUIRED_VERSION=$LLVM_REQUIRED_VERSION -DLLVM_USE_LINKER=gold .. && \
265298
make install -j$(nproc --all) && \
266299
cd .. && \
@@ -271,13 +304,22 @@ RUN \
271304
cd clad && \
272305
mkdir build && \
273306
cd build && \
274-
cmake .. -DClang_DIR=${PATH_TO_LLVM_BUILD}/lib/cmake/clang/ -DLLVM_DIR=${PATH_TO_LLVM_BUILD}/lib/cmake/llvm/ -DCMAKE_INSTALL_PREFIX=${CONDA_DIR} -DLLVM_EXTERNAL_LIT="$(which lit)" && \
275-
#make -j$(nproc --all) && \
276-
make && \
307+
cmake -DCMAKE_BUILD_TYPE=Debug .. -DClang_DIR=${PATH_TO_LLVM_BUILD}/lib/cmake/clang/ -DLLVM_DIR=${PATH_TO_LLVM_BUILD}/lib/cmake/llvm/ -DCMAKE_INSTALL_PREFIX=${CONDA_DIR} -DLLVM_EXTERNAL_LIT="$(which lit)" && \
308+
make -j$(nproc --all) && \
277309
make install && \
278310
# install clad in all exist kernels
279311
for i in "$KERNEL_PYTHON_PREFIX"/share/jupyter/kernels/*; do if [[ $i =~ .*/clad-xcpp.* ]]; then jq '.argv += ["-fplugin=$KERNEL_PYTHON_PREFIX/lib/clad.so"] | .display_name += " (with clad)"' "$i"/kernel.json > tmp.$$.json && mv tmp.$$.json "$i"/kernel.json; fi; done && \
280312
#
281313
# Add OpenMP to all kernels
282314
#
283-
for i in "$KERNEL_PYTHON_PREFIX"/share/jupyter/kernels/*; do if [[ $i =~ .*/xcpp.* ]]; then jq '.argv += ["-fopenmp"] | .display_name += " (with OpenMP)"' "$i"/kernel.json > tmp.$$.json && mv tmp.$$.json "$i"/kernel.json; fi; done
315+
for i in "$KERNEL_PYTHON_PREFIX"/share/jupyter/kernels/*; do if [[ $i =~ .*/xcpp.* ]]; then jq '.argv += ["-fopenmp"] | .display_name += " (with OpenMP)"' "$i"/kernel.json > tmp.$$.json && mv tmp.$$.json "$i"/kernel.json; fi; done && \
316+
#
317+
# CUDA
318+
#
319+
#echo "c = get_config()" >> /home/jovyan/.jupyter/jupyter_notebook_config.py && \
320+
#echo "c.NotebookApp.notebook_manager_class = 'jupyter_gpu.GPUNotebookManager'" >> /home/jovyan/.jupyter/jupyter_notebook_config.py && \
321+
cat /home/jovyan/.jupyter/jupyter_notebook_config.py && \
322+
echo "c.GPUNotebookManager.gpu_device = 0" >> /home/jovyan/.jupyter/jupyter_notebook_config.py && \
323+
# Web password and token set to ""
324+
echo "c.NotebookApp.token = ''" >> /home/jovyan/.jupyter/jupyter_notebook_config.py && \
325+
echo "c.NotebookApp.password = ''" >> /home/jovyan/.jupyter/jupyter_notebook_config.py

bash-docker.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
if [ "$#" -eq 0 ]; then
4+
user="root"
5+
else
6+
user="$1"
7+
fi
8+
9+
docker exec -u "$user" -t -i xeus-clang-repl-c /bin/bash --login

run-docker.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#!/bin/bash
2+
docker container run --rm -i hadolint/hadolint hadolint - < Dockerfile
3+
24
jupyter-repo2docker \
35
--no-run \
46
--user-name=jovyan \

0 commit comments

Comments
 (0)