From 36f5ed4755b9b1b43c83f6645689f14b0fe10510 Mon Sep 17 00:00:00 2001 From: rancheng <752050943@qq.com> Date: Thu, 26 May 2022 15:15:23 +0800 Subject: [PATCH 1/2] add docker --- docker/2021-06-10-12_32_58.log | 0 docker/README.md | 44 +++++++ docker/build-dokcer-image.bash | 20 +++ docker/config/terminator/config | 30 +++++ docker/dockerfile | 215 +++++++++++++++++++++++++++++++ docker/entrypoint.bash | 3 + docker/requirements.txt | 17 +++ docker/run-docker-container.bash | 27 ++++ 8 files changed, 356 insertions(+) create mode 100644 docker/2021-06-10-12_32_58.log create mode 100644 docker/README.md create mode 100755 docker/build-dokcer-image.bash create mode 100644 docker/config/terminator/config create mode 100644 docker/dockerfile create mode 100644 docker/entrypoint.bash create mode 100644 docker/requirements.txt create mode 100755 docker/run-docker-container.bash diff --git a/docker/2021-06-10-12_32_58.log b/docker/2021-06-10-12_32_58.log new file mode 100644 index 0000000..e69de29 diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 0000000..1af7923 --- /dev/null +++ b/docker/README.md @@ -0,0 +1,44 @@ +# Tandem Docker + +This is the docker environment setup tutorial for `TUM Tandem`, it supports remote `OpenGL` display, thus you can render `Pangolin window` with remote ssh. + +### Build Image + +Run the following commands to build the image: + +```shell +cd docker +./build-dokcer-image.bash +``` + +and run + +```shell +./run-docker-container.bash +``` + +to run the container. + +Please note that you can customize your own `ssh port` by modifying the `run-docker-container.bash` file: + +```shell +docker run --rm \ + --ipc=host \ + --gpus all \ + --privileged \ + -p 3751:22 \ <======= please choose your own port + -v /tmp/.X11-unix:/tmp/.X11-unix:rw \ +``` + +Then in a new remote or local terminal, run the following command to connect the remote environment: + +```shell +ssh -p 3751 work@xx.xx.xx.xx +# default password: work123 +``` + +You can also pull the built image from `dockerhub.io`: + +```shell +docker pull chengran222/tumtandem:origin +``` \ No newline at end of file diff --git a/docker/build-dokcer-image.bash b/docker/build-dokcer-image.bash new file mode 100755 index 0000000..a305d0b --- /dev/null +++ b/docker/build-dokcer-image.bash @@ -0,0 +1,20 @@ +#!/bin/bash + +file_dir=`dirname $0` + +# get parameter from system +user=`id -un` +group=`id -gn` +uid=`id -u` +gid=`id -g` + +# --build-arg http_proxy=http://10.141.6.84:7890 \ +# --build-arg https_proxy=http://10.141.6.84:7890 \ + +# build docker images +docker build -t chengran222/tumtandem \ + --build-arg USER=${user} \ + --build-arg UID=${uid} \ + --build-arg GROUP=${group} \ + --build-arg GID=${gid} \ + ${file_dir} diff --git a/docker/config/terminator/config b/docker/config/terminator/config new file mode 100644 index 0000000..5a91884 --- /dev/null +++ b/docker/config/terminator/config @@ -0,0 +1,30 @@ +[global_config] + title_receive_bg_color = "#64d8ff" + enabled_plugins = TerminalShot, LaunchpadCodeURLHandler, APTURLHandler, Logger, LaunchpadBugURLHandler + title_transmit_bg_color = "#15b0dc" +[keybindings] + switch_to_tab_1=1 + switch_to_tab_2=2 + switch_to_tab_3=3 + switch_to_tab_4=4 + switch_to_tab_5=5 + switch_to_tab_6=6 + switch_to_tab_7=7 +[profiles] + [[default]] + use_system_font = False + background_darkness = 0.75 + background_type = image + scroll_background = False + font = Monospace 12 + scrollback_infinite = True + use_custom_command = False +[layouts] + [[default]] + [[[child1]]] + type = Terminal + parent = window0 + [[[window0]]] + type = Window + parent = "" +[plugins] diff --git a/docker/dockerfile b/docker/dockerfile new file mode 100644 index 0000000..3d537c0 --- /dev/null +++ b/docker/dockerfile @@ -0,0 +1,215 @@ +FROM nvidia/cuda:11.1.1-cudnn8-devel-ubuntu18.04 + +LABEL maintainer='ran.cheng2@mail.mcgill.ca' + +# Arguments +ARG USER=initial +ARG GROUP=initial +ARG UID=1000 +ARG GID=${UID} +ARG SHELL=/bin/bash + +# cuda apt source +# RUN apt-key del 7fa2af80 +RUN apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/3bf863cc.pub + +# Install packages +RUN apt-get update && apt install -y --no-install-recommends software-properties-common + +RUN apt-get update && add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main" && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + wget curl ssh \ + zsh terminator gnome-terminal git vim tig \ + dbus-x11 libglvnd0 libgl1 libglx0 libegl1 libxext6 libx11-6 \ + unzip \ + yasm \ + pkg-config \ + libjpeg-dev \ + libtiff-dev \ + libjasper-dev \ + libpng-dev \ + libavcodec-dev \ + libavformat-dev \ + libswscale-dev \ + libv4l-dev \ + libatlas-base-dev \ + gfortran \ + libtbb2 \ + libtbb-dev \ + libpq-dev \ + libeigen3-dev \ + libpython-dev \ + libopencv-dev \ + gdb \ + rsync \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +RUN mkdir -p /root/ + +WORKDIR /root/ + + +# install cmake +RUN apt install -y software-properties-common lsb-release && \ + wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null && \ + apt-add-repository "deb https://apt.kitware.com/ubuntu/ $(lsb_release -cs) main" && \ + apt update && apt install -y --no-install-recommends cmake + +RUN apt update && apt install -y --no-install-recommends build-essential libboost-all-dev + +# # build eigen +# RUN wget https://gitlab.com/libeigen/eigen/-/archive/3.3.7/eigen-3.3.7.tar.gz && \ +# tar -xvzf eigen-3.3.7.tar.gz && cd eigen-3.3.7 && mkdir build && cd build && cmake .. && make install && \ +# cd ../../ && rm -rf eigen-3.3.7 && rm eigen-3.3.7.tar.gz + +RUN apt update && apt install -y --no-install-recommends libglew-dev \ + pkg-config \ + libgtk-3-dev \ + libgtest-dev \ + libgoogle-glog-dev \ + google-mock \ + libgflags-dev \ + libavcodec-dev libavformat-dev libswscale-dev libv4l-dev \ + libxvidcore-dev libx264-dev \ + libatlas-base-dev \ + libsuitesparse-dev \ + qtdeclarative5-dev \ + qt5-qmake \ + pkg-config libgtk-3-dev \ + libqglviewer-dev-qt5 + + +# RUN git clone https://github.com/opencv/opencv.git && git clone https://github.com/opencv/opencv_contrib.git +# RUN cd /root/opencv && git checkout 3.4.5 && cd ../opencv_contrib && git checkout 3.4.5 && \ +# cd /root/opencv && mkdir build && cd build && \ +# cmake \ +# -DBUILD_TIFF=ON \ +# -DBUILD_opencv_java=OFF \ +# -DOPENCV_EXTRA_MODULES_PATH=/root/opencv_contrib/modules \ +# -DWITH_CUDA=OFF \ +# -DENABLE_AVX=ON \ +# -DWITH_OPENGL=ON \ +# -DWITH_OPENCL=ON \ +# -DWITH_IPP=ON \ +# -DWITH_TBB=ON \ +# -DWITH_EIGEN=ON \ +# -DWITH_V4L=ON \ +# -DBUILD_TESTS=OFF \ +# -DBUILD_PERF_TESTS=OFF \ +# -DCMAKE_BUILD_TYPE=RELEASE \ +# -DBUILD_opencv_python3=ON \ +# -DCMAKE_INSTALL_PREFIX=$(python3.6 -c "import sys; print(sys.prefix)") \ +# -DPYTHON_EXECUTABLE=$(which python3.6) \ +# -DPYTHON_INCLUDE_DIR=$(python3.6 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \ +# -DPYTHON_PACKAGES_PATH=$(python3.6 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") .. \ +# && make install \ +# && cd /root/ && rm -rf opencv && rm -rf opencv_contrib + +RUN apt update && apt install -y --no-install-recommends \ + freeglut3-dev pkg-config \ + libxmu-dev libxi-dev \ + libflann-dev + +# Pangolin +RUN cd /root/ && git clone https://github.com/stevenlovegrove/Pangolin.git && \ + cd /root/Pangolin/ && \ + git checkout v0.6 && \ + mkdir build && cd build && \ + cmake .. && \ + make -j12 install + + +# install yaml cpp +RUN apt install -y --no-install-recommends libyaml-cpp-dev python3-pip python3-setuptools python3-venv python3-wheel + +RUN apt install -y --no-install-recommends libxtst6 + +# Env vars for the nvidia-container-runtime. +ENV NVIDIA_VISIBLE_DEVICES all +ENV NVIDIA_DRIVER_CAPABILITIES graphics,utility,compute + +# change passwd +RUN echo 'root:work123' | chpasswd + +# modify the sshd_config +RUN sed -i 's/\#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config + +RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd + +RUN echo 'export DISPLAY=:0' >> /etc/profile + +ENV NOTVISIBLE "in users profile" + +RUN echo "export VISIBLE=now" >> /etc/profile + +RUN groupadd --gid 1000 work && \ + useradd --gid 1000 --uid 1000 -ms /bin/bash work + +RUN echo 'work:work123' | chpasswd + +# copy entrypoint +COPY entrypoint.bash /entrypoint.bash +RUN chmod 777 /entrypoint.bash + +RUN mkdir -p /home/work/.config/terminator +RUN mkdir -p /root/.config/terminator +COPY config/terminator/config /root/.config/terminator +COPY config/terminator/config /home/work/.config/terminator +RUN chown -R work:work /home/work/.config +RUN chown -R root:root /root/.config + +USER work + +WORKDIR /home/work/ + +# Conda +RUN wget \ + https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh \ + && bash Miniconda3-latest-Linux-x86_64.sh -b \ + && rm -f Miniconda3-latest-Linux-x86_64.sh + +ENV PATH="/home/work/miniconda3/bin:${PATH}" + +RUN conda install -y python=3.7 + +RUN wget https://download.pytorch.org/libtorch/cu111/libtorch-cxx11-abi-shared-with-deps-1.9.0%2Bcu111.zip + +RUN pip3 install wheel tqdm ruamel.yaml pyquaternion matplotlib tabulate + +RUN conda install -y pytorch==1.5.1 torchvision==0.6.1 cudatoolkit=10.2 -c pytorch + +COPY requirements.txt requirements.txt + +RUN pip install -r requirements.txt + +RUN unzip libtorch-cxx11-abi-shared-with-deps-1.9.0+cu111.zip + +USER root + +RUN echo 'export PATH=/home/work/miniconda3/bin:${PATH}' >> /etc/profile + +# RUN echo 'export TANDEM_CUDNN_LIBRARY=/usr/local/cuda-11.1/lib64:/usr/lib/x86_64-linux-gnu' >> /etc/profile + +# RUN echo 'export TANDEM_CUDNN_INCLUDE_PATH=/local/cuda-11.1/include:/usr/include' >> /etc/profile + +RUN echo 'export TANDEM_CUDNN_LIBRARY=/usr/lib/x86_64-linux-gnu' >> /etc/profile + +RUN echo 'export TANDEM_CUDNN_INCLUDE_PATH=/usr/include' >> /etc/profile + +RUN echo 'export TANDEM_LIBTORCH_DIR=/home/work/libtorch' >> /etc/profile + +USER root + +# CNPY +RUN git clone https://github.com/rogersce/cnpy.git && \ + cd cnpy && \ + mkdir build && cd build && cmake .. && make install + +# Sophus +RUN git clone https://github.com/strasdat/Sophus.git && cd Sophus && \ + git checkout v1.0.0 && mkdir build && cd build && cmake .. && make install + +EXPOSE 22 + +ENTRYPOINT ["/entrypoint.bash", "terminator"] \ No newline at end of file diff --git a/docker/entrypoint.bash b/docker/entrypoint.bash new file mode 100644 index 0000000..7c536b7 --- /dev/null +++ b/docker/entrypoint.bash @@ -0,0 +1,3 @@ +#! /bin/bash +service ssh restart +exec $@ diff --git a/docker/requirements.txt b/docker/requirements.txt new file mode 100644 index 0000000..50f8b4d --- /dev/null +++ b/docker/requirements.txt @@ -0,0 +1,17 @@ +pytorch-lightning==0.7.6 +numpy +pillow +tensorboardX +opencv-python +plyfile +yacs +pytest +nvidia-ml-py3 +psutil +hurry.filesize +pyyaml +matplotlib +tqdm +hurry.filesize +wget +scipy diff --git a/docker/run-docker-container.bash b/docker/run-docker-container.bash new file mode 100755 index 0000000..143f013 --- /dev/null +++ b/docker/run-docker-container.bash @@ -0,0 +1,27 @@ +#!/bin/bash + +# get parameter from system +user=`id -un` + +# start sharing xhost +xhost +local:root + +# incase if you need proxy +# uncomment and replace it with your own institution server: +# -e http_proxy=http://10.141.6.84:7890 \ +# -e https_proxy=http://10.141.6.84:7890 \ + +# run docker +docker run --rm \ + --ipc=host \ + --gpus all \ + --privileged \ + -p 3751:22 \ + -v /tmp/.X11-unix:/tmp/.X11-unix:rw \ + -v $HOME/.Xauthority:$docker/.Xauthority \ + -v $HOME/work:/home/work/projects \ + -v /mnt/Data/Datasets/dm-vio:/mnt/Data/Datasets/dm-vio \ + -e XAUTHORITY=$home_folder/.Xauthority \ + -e DISPLAY=$DISPLAY \ + -e QT_X11_NO_MITSHM=1 \ + -it chengran222/tumtandem From ed224ff3205d371649bd0855218f87cff7a4cd5e Mon Sep 17 00:00:00 2001 From: rancheng <752050943@qq.com> Date: Thu, 26 May 2022 15:18:04 +0800 Subject: [PATCH 2/2] update readme --- docker/README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docker/README.md b/docker/README.md index 1af7923..b3d4b86 100644 --- a/docker/README.md +++ b/docker/README.md @@ -41,4 +41,12 @@ You can also pull the built image from `dockerhub.io`: ```shell docker pull chengran222/tumtandem:origin +``` + +## Build Tandem + +You need to switch user to build the `Tandem` in docker if you are using the terminator gui launched locally: + +```shell +su - work ``` \ No newline at end of file