├── .gitignore ├── CreateDockerFile.ipynb ├── Dockerfile ├── LICENSE ├── README.md ├── UI.odg ├── components ├── __init__.py ├── apt.py ├── catkin.py ├── cmake.py ├── cmake_update.py ├── copy.py ├── cuda.py ├── cudnn.py ├── custom.py ├── icub.py ├── jupyterlab.py ├── matlab.py ├── pip.py ├── pip3.py ├── repo.py ├── ros.py ├── source.py ├── tail.py └── ubuntu.py ├── form.py ├── roslab_create.py └── ui_form.png /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | -------------------------------------------------------------------------------- /CreateDockerFile.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "## ROSLab: RObotics Software with JupyterLab\n", 8 | "ROSLab is a [JupyterLab](https://jupyterlab.readthedocs.io/en/stable/)\n", 9 | "environment for a source code repository with robotics software. \n", 10 | "It automatically creates a [Dockerfile](https://docs.docker.com/engine/reference/builder/) from a simple UI form.\n", 11 | "\n", 12 | "Please select the cell below and press simultaneously `Ctrl+Enter`. Then fill in the form fields, and press the `Proceed` button." 13 | ] 14 | }, 15 | { 16 | "cell_type": "code", 17 | "execution_count": null, 18 | "metadata": {}, 19 | "outputs": [], 20 | "source": [ 21 | "import form\n", 22 | "form.ui" 23 | ] 24 | } 25 | ], 26 | "metadata": { 27 | "kernelspec": { 28 | "display_name": "Python 3", 29 | "language": "python", 30 | "name": "python3" 31 | }, 32 | "language_info": { 33 | "codemirror_mode": { 34 | "name": "ipython", 35 | "version": 3 36 | }, 37 | "file_extension": ".py", 38 | "mimetype": "text/x-python", 39 | "name": "python", 40 | "nbconvert_exporter": "python", 41 | "pygments_lexer": "ipython3", 42 | "version": "3.7.3" 43 | } 44 | }, 45 | "nbformat": 4, 46 | "nbformat_minor": 2 47 | } 48 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM jupyter/base-notebook:latest 2 | 3 | RUN conda install pyyaml 4 | 5 | RUN conda install -c conda-forge ipywidgets 6 | 7 | COPY roslab_create.py /home/jovyan/ 8 | 9 | COPY components /home/jovyan/components 10 | 11 | COPY --chown=1000:1000 CreateDockerFile.ipynb /home/jovyan/ 12 | 13 | COPY --chown=1000:1000 form.py /home/jovyan/ 14 | 15 | CMD ["jupyter", "notebook", "CreateDockerFile.ipynb"] 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Robotic Intelligence Lab 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ROSLab 2 | [](https://mybinder.org/v2/gh/RobInLabUJI/ROSLab/web?filepath=CreateDockerFile.ipynb) 3 | 4 | ## *RO*botics *S*oftware with Jupyter*Lab* 5 | 6 | ROSLab is a [JupyterLab](https://jupyterlab.readthedocs.io/en/stable/) 7 | environment for a source code repository with robotics software. 8 | It automatically creates a Dockerfile 9 | from the configuration data entered by the user in a simple web form: 10 | 11 |  12 | 13 | First, you must specify a name for your Docker image, then select an Ubuntu version (16.04 is the default). 14 | 15 | A number of options can be selected for the platform: 16 | * X11 17 | * OpenGL 18 | * CUDA 19 | * cuDNN 20 | * ROS 21 | * Build method 22 | 23 | In the middle column of the form, you can specify the package dependencies of your software: 24 | * APT packages 25 | * Python 2 packages 26 | * Python 3 packages 27 | 28 | You can also add any custom commands that will be executed at the end of the process, as well as the path 29 | to a local MATLAB install (for this to work, the guest and host OS must be compatible). 30 | 31 | In the rightmost column, you can specify other dependencies on source packages; for each one, you must indicate: 32 | * a name 33 | * the URL of the repository 34 | * the dependencies 35 | * the building method 36 | 37 | When the form is complete, you must press the `Proceed` button and the Dockerfile will be generated, which can be downloaded to your local folder. The commands for building and running the Docker image will be displayed too. 38 | 39 | ## Prerequisites 40 | 41 | [Docker](https://www.docker.com/) 42 | 43 | [nvidia-docker 2.0](https://github.com/nvidia/nvidia-docker/wiki/Installation-(version-2.0)) For running an image with `OpenGL` and/or `CUDA`. 44 | 45 | ## Usage 46 | 47 | Use it in [Binder](https://mybinder.org/v2/gh/RobInLabUJI/ROSLab/web?filepath=CreateDockerFile.ipynb), or in your local host with Docker: 48 | 1. Run in the command line: 49 | ``` 50 | docker run --rm -p 8888:8888 roslab/web:latest 51 | ``` 52 | 2. Copy and paste the displayed link in your browser: 53 | ``` 54 | http://127.0.0.1:8888?token=... 55 | ``` 56 | 3. Open the notebook `CreateDockerFile.ipynb` 57 | -------------------------------------------------------------------------------- /UI.odg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobInLabUJI/ROSLab/3a5047a204989dea108cb163fd1ca7516ec2f5c9/UI.odg -------------------------------------------------------------------------------- /components/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobInLabUJI/ROSLab/3a5047a204989dea108cb163fd1ca7516ec2f5c9/components/__init__.py -------------------------------------------------------------------------------- /components/apt.py: -------------------------------------------------------------------------------- 1 | DOCKER_CONTENTS = """ 2 | ##################################### APT ###################################### 3 | 4 | RUN apt-get -o Acquire::ForceIPv4=true update \\ 5 | && apt-get -o Acquire::ForceIPv4=true install -yq --no-install-recommends \\ 6 | %s && apt-get clean \\ 7 | && rm -rf /var/lib/apt/lists/* 8 | """ 9 | 10 | def write(DOCKER_FILE, package_list): 11 | pstr = '' 12 | for p in package_list: 13 | pstr += ' ' + p + ' \\\n' 14 | with open(DOCKER_FILE, "a") as dockerfile: 15 | dockerfile.write(DOCKER_CONTENTS % pstr) 16 | return 17 | 18 | -------------------------------------------------------------------------------- /components/catkin.py: -------------------------------------------------------------------------------- 1 | DOCKER_CONTENTS = """ 2 | #################################### CATKIN #################################### 3 | 4 | RUN mkdir -p ${HOME}/catkin_ws/src && ln -s ${HOME}/%s ${HOME}/catkin_ws/src/. 5 | 6 | RUN cd ${HOME}/catkin_ws \\ 7 | && apt-get -o Acquire::ForceIPv4=true update \\ 8 | && /bin/bash -c "source /opt/ros/${ROS_DISTRO}/setup.bash && rosdep update && rosdep install --as-root apt:false --from-paths src --ignore-src -r -y" \\ 9 | && apt-get clean \\ 10 | && rm -rf /var/lib/apt/lists/* \\ 11 | && /bin/bash -c "source /opt/ros/${ROS_DISTRO}/setup.bash && %s" 12 | 13 | RUN echo "source ~/catkin_ws/devel/setup.bash" >> ${HOME}/.bashrc 14 | """ 15 | 16 | build_string = {'catkin_make': 'catkin_make', 'catkin_build': 'catkin build'} 17 | 18 | def write(DOCKER_FILE, name, build_method): 19 | with open(DOCKER_FILE, "a") as dockerfile: 20 | dockerfile.write(DOCKER_CONTENTS % (name, build_string[build_method])) 21 | return 22 | 23 | -------------------------------------------------------------------------------- /components/cmake.py: -------------------------------------------------------------------------------- 1 | DOCKER_CONTENTS = """ 2 | #################################### CMAKE ##################################### 3 | 4 | RUN mkdir ${HOME}/%s/build \\ 5 | && cd ${HOME}/%s/build \\ 6 | && cmake %s .. \\ 7 | && make -j2 8 | """ 9 | 10 | def write(DOCKER_FILE, name, cmake_options): 11 | with open(DOCKER_FILE, "a") as dockerfile: 12 | dockerfile.write(DOCKER_CONTENTS % (name, name, cmake_options)) 13 | return 14 | 15 | -------------------------------------------------------------------------------- /components/cmake_update.py: -------------------------------------------------------------------------------- 1 | import os, sys 2 | 3 | #versions = ['3.7.2','3.13.4'] 4 | 5 | DOCKER_CORE_CONTENTS = """ 6 | ################################# CMAKE_UPDATE ################################# 7 | 8 | RUN apt remove -y --purge --auto-remove cmake 9 | 10 | RUN apt-get update \\ 11 | && apt-get install -yq --no-install-recommends wget libcurl4-openssl-dev zlib1g-dev\\ 12 | && apt-get clean \\ 13 | && rm -rf /var/lib/apt/lists/* 14 | 15 | RUN mkdir /temp_cmake && cd /temp_cmake \\ 16 | && wget https://cmake.org/files/v%s/cmake-%s.tar.gz \\ 17 | && tar -xzvf cmake-%s.tar.gz \\ 18 | && cd cmake-%s \\ 19 | && ./bootstrap --system-curl && make -j4 && make install \\ 20 | && rm -fr /temp_cmake 21 | """ 22 | 23 | def write(DOCKER_FILE, version): 24 | if True: #version in versions: 25 | major = '.'.join(version.split('.')[:-1]) 26 | with open(DOCKER_FILE, "a") as dockerfile: 27 | dockerfile.write(DOCKER_CORE_CONTENTS % (major, version, version, version)) 28 | return 29 | else: 30 | print("cmake_update: version %s not supported. Options: %s" % (version, versions)) 31 | sys.exit(1) 32 | 33 | 34 | -------------------------------------------------------------------------------- /components/copy.py: -------------------------------------------------------------------------------- 1 | DOCKER_CONTENTS = """ 2 | ##################################### COPY ##################################### 3 | 4 | RUN mkdir ${HOME}/%s 5 | 6 | COPY --chown=1000:1000 . ${HOME}/%s 7 | """ 8 | 9 | def write(DOCKER_FILE, name): 10 | with open(DOCKER_FILE, "a") as dockerfile: 11 | dockerfile.write(DOCKER_CONTENTS % (name, name)) 12 | return 13 | 14 | -------------------------------------------------------------------------------- /components/cuda.py: -------------------------------------------------------------------------------- 1 | import os, sys 2 | 3 | versions = ['8.0-runtime', '8.0-devel', '9.0-runtime', '9.0-devel', 4 | '9.2-runtime', '9.2-devel', '10.0-runtime', '10.0-devel'] 5 | 6 | DOCKER_CUDA_HEADER = """ 7 | ###################################### CUDA #################################### 8 | """ 9 | 10 | DOCKER_RUNTIME_CONTENTS = {} 11 | DOCKER_RUNTIME_CONTENTS['18.04'] = {} 12 | DOCKER_RUNTIME_CONTENTS['16.04'] = {} 13 | 14 | DOCKER_RUNTIME_CONTENTS['18.04']['10.0'] = """ 15 | RUN apt-get update && apt-get install -y --no-install-recommends gnupg2 curl ca-certificates && \\ 16 | curl -fsSL https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub | apt-key add - && \\ 17 | echo "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64 /" > /etc/apt/sources.list.d/cuda.list && \\ 18 | echo "deb https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64 /" > /etc/apt/sources.list.d/nvidia-ml.list && \\ 19 | apt-get purge --autoremove -y curl && \\ 20 | rm -rf /var/lib/apt/lists/* 21 | 22 | ENV CUDA_VERSION 10.0.130 23 | 24 | ENV CUDA_PKG_VERSION 10-0=$CUDA_VERSION-1 25 | # For libraries in the cuda-compat-* package: https://docs.nvidia.com/cuda/eula/index.html#attachment-a 26 | RUN apt-get update && apt-get install -y --no-install-recommends \\ 27 | cuda-cudart-$CUDA_PKG_VERSION \\ 28 | cuda-compat-10-0=410.48-1 && \\ 29 | ln -s cuda-10.0 /usr/local/cuda && \\ 30 | rm -rf /var/lib/apt/lists/* 31 | 32 | ENV PATH /usr/local/cuda/bin:${PATH} 33 | 34 | # nvidia-container-runtime 35 | ENV NVIDIA_VISIBLE_DEVICES all 36 | ENV NVIDIA_DRIVER_CAPABILITIES compute,utility 37 | ENV NVIDIA_REQUIRE_CUDA "cuda>=10.0 brand=tesla,driver>=384,driver<385" 38 | 39 | ENV NCCL_VERSION 2.4.2 40 | 41 | RUN apt-get update && apt-get install -y --no-install-recommends \\ 42 | cuda-libraries-$CUDA_PKG_VERSION \\ 43 | cuda-nvtx-$CUDA_PKG_VERSION \\ 44 | libnccl2=$NCCL_VERSION-1+cuda10.0 && \\ 45 | apt-mark hold libnccl2 && \\ 46 | rm -rf /var/lib/apt/lists/* 47 | """ 48 | 49 | DOCKER_RUNTIME_CONTENTS['18.04']['9.2'] = """ 50 | # CUDA 9.2 is not officially supported on ubuntu 18.04 yet, we use the ubuntu 17.10 repository for CUDA instead. 51 | RUN apt-get update && apt-get install -y --no-install-recommends gnupg2 curl ca-certificates && \\ 52 | curl -fsSL https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1710/x86_64/7fa2af80.pub | apt-key add - && \\ 53 | echo "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1710/x86_64 /" > /etc/apt/sources.list.d/cuda.list && \\ 54 | echo "deb https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1604/x86_64 /" > /etc/apt/sources.list.d/nvidia-ml.list && \\ 55 | apt-get purge --autoremove -y curl && \\ 56 | rm -rf /var/lib/apt/lists/* 57 | 58 | ENV CUDA_VERSION 9.2.148 59 | 60 | ENV CUDA_PKG_VERSION 9-2=$CUDA_VERSION-1 61 | RUN apt-get update && apt-get install -y --no-install-recommends \\ 62 | cuda-cudart-$CUDA_PKG_VERSION && \\ 63 | ln -s cuda-9.2 /usr/local/cuda && \\ 64 | rm -rf /var/lib/apt/lists/* 65 | 66 | # nvidia-docker 1.0 67 | LABEL com.nvidia.volumes.needed="nvidia_driver" 68 | LABEL com.nvidia.cuda.version="${CUDA_VERSION}" 69 | 70 | RUN echo "/usr/local/nvidia/lib" >> /etc/ld.so.conf.d/nvidia.conf && \\ 71 | echo "/usr/local/nvidia/lib64" >> /etc/ld.so.conf.d/nvidia.conf 72 | 73 | ENV PATH /usr/local/nvidia/bin:/usr/local/cuda/bin:${PATH} 74 | ENV LD_LIBRARY_PATH /usr/local/nvidia/lib:/usr/local/nvidia/lib64 75 | 76 | # nvidia-container-runtime 77 | ENV NVIDIA_VISIBLE_DEVICES all 78 | ENV NVIDIA_DRIVER_CAPABILITIES compute,utility 79 | ENV NVIDIA_REQUIRE_CUDA "cuda>=9.2" 80 | 81 | ENV NCCL_VERSION 2.3.7 82 | 83 | RUN apt-get update && apt-get install -y --no-install-recommends \\ 84 | cuda-libraries-$CUDA_PKG_VERSION \\ 85 | cuda-nvtx-$CUDA_PKG_VERSION \\ 86 | libnccl2=$NCCL_VERSION-1+cuda9.2 && \\ 87 | apt-mark hold libnccl2 && \\ 88 | rm -rf /var/lib/apt/lists/* 89 | """ 90 | 91 | DOCKER_RUNTIME_CONTENTS['16.04']['10.0'] = """ 92 | RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates apt-transport-https gnupg-curl && \\ 93 | rm -rf /var/lib/apt/lists/* && \\ 94 | NVIDIA_GPGKEY_SUM=d1be581509378368edeec8c1eb2958702feedf3bc3d17011adbf24efacce4ab5 && \\ 95 | NVIDIA_GPGKEY_FPR=ae09fe4bbd223a84b2ccfce3f60f4b3d7fa2af80 && \\ 96 | apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub && \\ 97 | apt-key adv --export --no-emit-version -a $NVIDIA_GPGKEY_FPR | tail -n +5 > cudasign.pub && \\ 98 | echo "$NVIDIA_GPGKEY_SUM cudasign.pub" | sha256sum -c --strict - && rm cudasign.pub && \\ 99 | echo "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64 /" > /etc/apt/sources.list.d/cuda.list && \\ 100 | echo "deb https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1604/x86_64 /" > /etc/apt/sources.list.d/nvidia-ml.list 101 | 102 | ENV CUDA_VERSION 10.0.130 103 | 104 | ENV CUDA_PKG_VERSION 10-0=$CUDA_VERSION-1 105 | # For libraries in the cuda-compat-* package: https://docs.nvidia.com/cuda/eula/index.html#attachment-a 106 | RUN apt-get update && apt-get install -y --no-install-recommends \\ 107 | cuda-cudart-$CUDA_PKG_VERSION \\ 108 | cuda-compat-10-0=410.48-1 && \\ 109 | ln -s cuda-10.0 /usr/local/cuda && \\ 110 | rm -rf /var/lib/apt/lists/* 111 | 112 | ENV PATH /usr/local/cuda/bin:${PATH} 113 | 114 | # nvidia-container-runtime 115 | ENV NVIDIA_VISIBLE_DEVICES all 116 | ENV NVIDIA_DRIVER_CAPABILITIES compute,utility 117 | ENV NVIDIA_REQUIRE_CUDA "cuda>=10.0 brand=tesla,driver>=384,driver<385" 118 | 119 | ENV NCCL_VERSION 2.4.2 120 | 121 | RUN apt-get update && apt-get install -y --no-install-recommends \\ 122 | cuda-libraries-$CUDA_PKG_VERSION \\ 123 | cuda-nvtx-$CUDA_PKG_VERSION \\ 124 | libnccl2=$NCCL_VERSION-1+cuda10.0 && \\ 125 | apt-mark hold libnccl2 && \\ 126 | rm -rf /var/lib/apt/lists/* 127 | """ 128 | 129 | DOCKER_RUNTIME_CONTENTS['16.04']['9.0'] = """ 130 | RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates apt-transport-https gnupg-curl && \\ 131 | rm -rf /var/lib/apt/lists/* && \\ 132 | NVIDIA_GPGKEY_SUM=d1be581509378368edeec8c1eb2958702feedf3bc3d17011adbf24efacce4ab5 && \\ 133 | NVIDIA_GPGKEY_FPR=ae09fe4bbd223a84b2ccfce3f60f4b3d7fa2af80 && \\ 134 | apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub && \\ 135 | apt-key adv --export --no-emit-version -a $NVIDIA_GPGKEY_FPR | tail -n +5 > cudasign.pub && \\ 136 | echo "$NVIDIA_GPGKEY_SUM cudasign.pub" | sha256sum -c --strict - && rm cudasign.pub && \\ 137 | echo "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64 /" > /etc/apt/sources.list.d/cuda.list && \\ 138 | echo "deb https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1604/x86_64 /" > /etc/apt/sources.list.d/nvidia-ml.list 139 | 140 | ENV CUDA_VERSION 9.0.176 141 | 142 | ENV CUDA_PKG_VERSION 9-0=$CUDA_VERSION-1 143 | RUN apt-get update && apt-get install -y --no-install-recommends \\ 144 | cuda-cudart-$CUDA_PKG_VERSION && \\ 145 | ln -s cuda-9.0 /usr/local/cuda && \\ 146 | rm -rf /var/lib/apt/lists/* 147 | 148 | # nvidia-docker 1.0 149 | LABEL com.nvidia.volumes.needed="nvidia_driver" 150 | LABEL com.nvidia.cuda.version="${CUDA_VERSION}" 151 | 152 | RUN echo "/usr/local/nvidia/lib" >> /etc/ld.so.conf.d/nvidia.conf && \\ 153 | echo "/usr/local/nvidia/lib64" >> /etc/ld.so.conf.d/nvidia.conf 154 | 155 | ENV PATH /usr/local/nvidia/bin:/usr/local/cuda/bin:${PATH} 156 | ENV LD_LIBRARY_PATH /usr/local/nvidia/lib:/usr/local/nvidia/lib64 157 | 158 | # nvidia-container-runtime 159 | ENV NVIDIA_VISIBLE_DEVICES all 160 | ENV NVIDIA_DRIVER_CAPABILITIES compute,utility 161 | ENV NVIDIA_REQUIRE_CUDA "cuda>=9.0" 162 | 163 | ENV NCCL_VERSION 2.4.2 164 | 165 | RUN apt-get update && apt-get install -y --no-install-recommends \\ 166 | cuda-libraries-$CUDA_PKG_VERSION \\ 167 | cuda-cublas-9-0=9.0.176.4-1 \\ 168 | libnccl2=$NCCL_VERSION-1+cuda9.0 && \\ 169 | apt-mark hold libnccl2 && \\ 170 | rm -rf /var/lib/apt/lists/* 171 | """ 172 | 173 | DOCKER_RUNTIME_CONTENTS['16.04']['8.0'] = """ 174 | RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates apt-transport-https gnupg-curl && \\ 175 | rm -rf /var/lib/apt/lists/* && \\ 176 | NVIDIA_GPGKEY_SUM=d1be581509378368edeec8c1eb2958702feedf3bc3d17011adbf24efacce4ab5 && \\ 177 | NVIDIA_GPGKEY_FPR=ae09fe4bbd223a84b2ccfce3f60f4b3d7fa2af80 && \\ 178 | apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub && \\ 179 | apt-key adv --export --no-emit-version -a $NVIDIA_GPGKEY_FPR | tail -n +5 > cudasign.pub && \\ 180 | echo "$NVIDIA_GPGKEY_SUM cudasign.pub" | sha256sum -c --strict - && rm cudasign.pub && \\ 181 | echo "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64 /" > /etc/apt/sources.list.d/cuda.list 182 | 183 | ENV CUDA_VERSION 8.0.61 184 | 185 | ENV CUDA_PKG_VERSION 8-0=$CUDA_VERSION-1 186 | RUN apt-get update && apt-get install -y --no-install-recommends \\ 187 | cuda-nvrtc-$CUDA_PKG_VERSION \\ 188 | cuda-nvgraph-$CUDA_PKG_VERSION \\ 189 | cuda-cusolver-$CUDA_PKG_VERSION \\ 190 | cuda-cublas-8-0=8.0.61.2-1 \\ 191 | cuda-cufft-$CUDA_PKG_VERSION \\ 192 | cuda-curand-$CUDA_PKG_VERSION \\ 193 | cuda-cusparse-$CUDA_PKG_VERSION \\ 194 | cuda-npp-$CUDA_PKG_VERSION \\ 195 | cuda-cudart-$CUDA_PKG_VERSION && \\ 196 | ln -s cuda-8.0 /usr/local/cuda && \\ 197 | rm -rf /var/lib/apt/lists/* 198 | 199 | # nvidia-docker 1.0 200 | LABEL com.nvidia.volumes.needed="nvidia_driver" 201 | LABEL com.nvidia.cuda.version="${CUDA_VERSION}" 202 | 203 | RUN echo "/usr/local/nvidia/lib" >> /etc/ld.so.conf.d/nvidia.conf && \\ 204 | echo "/usr/local/nvidia/lib64" >> /etc/ld.so.conf.d/nvidia.conf 205 | 206 | ENV PATH /usr/local/nvidia/bin:/usr/local/cuda/bin:${PATH} 207 | ENV LD_LIBRARY_PATH /usr/local/nvidia/lib:/usr/local/nvidia/lib64 208 | 209 | # nvidia-container-runtime 210 | ENV NVIDIA_VISIBLE_DEVICES all 211 | ENV NVIDIA_DRIVER_CAPABILITIES compute,utility 212 | ENV NVIDIA_REQUIRE_CUDA "cuda>=8.0" 213 | """ 214 | 215 | DOCKER_DEVEL_CONTENTS = {} 216 | DOCKER_DEVEL_CONTENTS['18.04'] = {} 217 | DOCKER_DEVEL_CONTENTS['16.04'] = {} 218 | 219 | DOCKER_DEVEL_CONTENTS['18.04']['10.0'] = """ 220 | RUN apt-get update && apt-get install -y --no-install-recommends \\ 221 | cuda-libraries-dev-$CUDA_PKG_VERSION \\ 222 | cuda-nvml-dev-$CUDA_PKG_VERSION \\ 223 | cuda-minimal-build-$CUDA_PKG_VERSION \\ 224 | cuda-command-line-tools-$CUDA_PKG_VERSION \\ 225 | libnccl-dev=$NCCL_VERSION-1+cuda10.0 && \\ 226 | rm -rf /var/lib/apt/lists/* 227 | 228 | ENV LIBRARY_PATH /usr/local/cuda/lib64/stubs 229 | """ 230 | 231 | DOCKER_DEVEL_CONTENTS['18.04']['9.2'] = """ 232 | RUN apt-get update && apt-get install -y --no-install-recommends \\ 233 | cuda-libraries-dev-$CUDA_PKG_VERSION \\ 234 | cuda-nvml-dev-$CUDA_PKG_VERSION \\ 235 | cuda-minimal-build-$CUDA_PKG_VERSION \\ 236 | cuda-command-line-tools-$CUDA_PKG_VERSION \\ 237 | libnccl-dev=$NCCL_VERSION-1+cuda9.2 && \\ 238 | rm -rf /var/lib/apt/lists/* 239 | 240 | ENV LIBRARY_PATH /usr/local/cuda/lib64/stubs 241 | """ 242 | 243 | DOCKER_DEVEL_CONTENTS['16.04']['10.0'] = """ 244 | RUN apt-get update && apt-get install -y --no-install-recommends \\ 245 | cuda-libraries-dev-$CUDA_PKG_VERSION \\ 246 | cuda-nvml-dev-$CUDA_PKG_VERSION \\ 247 | cuda-minimal-build-$CUDA_PKG_VERSION \\ 248 | cuda-command-line-tools-$CUDA_PKG_VERSION \\ 249 | libnccl-dev=$NCCL_VERSION-1+cuda10.0 && \\ 250 | rm -rf /var/lib/apt/lists/* 251 | 252 | ENV LIBRARY_PATH /usr/local/cuda/lib64/stubs 253 | """ 254 | 255 | DOCKER_DEVEL_CONTENTS['16.04']['9.0'] = """ 256 | RUN apt-get update && apt-get install -y --no-install-recommends \\ 257 | cuda-libraries-dev-$CUDA_PKG_VERSION \\ 258 | cuda-nvml-dev-$CUDA_PKG_VERSION \\ 259 | cuda-minimal-build-$CUDA_PKG_VERSION \\ 260 | cuda-command-line-tools-$CUDA_PKG_VERSION \\ 261 | cuda-core-9-0=9.0.176.3-1 \\ 262 | cuda-cublas-dev-9-0=9.0.176.4-1 \\ 263 | libnccl-dev=$NCCL_VERSION-1+cuda9.0 && \\ 264 | rm -rf /var/lib/apt/lists/* 265 | 266 | ENV LIBRARY_PATH /usr/local/cuda/lib64/stubs 267 | """ 268 | 269 | DOCKER_DEVEL_CONTENTS['16.04']['8.0'] = """ 270 | RUN apt-get update && apt-get install -y --no-install-recommends \\ 271 | cuda-core-$CUDA_PKG_VERSION \\ 272 | cuda-misc-headers-$CUDA_PKG_VERSION \\ 273 | cuda-command-line-tools-$CUDA_PKG_VERSION \\ 274 | cuda-nvrtc-dev-$CUDA_PKG_VERSION \\ 275 | cuda-nvml-dev-$CUDA_PKG_VERSION \\ 276 | cuda-nvgraph-dev-$CUDA_PKG_VERSION \\ 277 | cuda-cusolver-dev-$CUDA_PKG_VERSION \\ 278 | cuda-cublas-dev-8-0=8.0.61.2-1 \\ 279 | cuda-cufft-dev-$CUDA_PKG_VERSION \\ 280 | cuda-curand-dev-$CUDA_PKG_VERSION \\ 281 | cuda-cusparse-dev-$CUDA_PKG_VERSION \\ 282 | cuda-npp-dev-$CUDA_PKG_VERSION \\ 283 | cuda-cudart-dev-$CUDA_PKG_VERSION \\ 284 | cuda-driver-dev-$CUDA_PKG_VERSION && \\ 285 | rm -rf /var/lib/apt/lists/* 286 | 287 | ENV LIBRARY_PATH /usr/local/cuda/lib64/stubs 288 | """ 289 | 290 | def write(DOCKER_FILE, version, ubuntu): 291 | if version in versions: 292 | with open(DOCKER_FILE, "a") as dockerfile: 293 | dockerfile.write(DOCKER_CUDA_HEADER) 294 | cuda = version.split('-')[0] 295 | try: 296 | dockerfile.write(DOCKER_RUNTIME_CONTENTS[ubuntu][cuda]) 297 | if 'devel' in version: 298 | dockerfile.write(DOCKER_DEVEL_CONTENTS[ubuntu][cuda]) 299 | except KeyError as e: 300 | print("CUDA version %s not supported in Ubuntu %s" % (cuda, ubuntu) ) 301 | sys.exit(1) 302 | return 303 | else: 304 | print("cuda: version %s not supported. Options: %s" % (version, versions)) 305 | sys.exit(1) 306 | 307 | -------------------------------------------------------------------------------- /components/cudnn.py: -------------------------------------------------------------------------------- 1 | import os, sys 2 | 3 | versions = ['5-runtime', '5-devel', '6-runtime', '6-devel', '7-runtime', '7-devel'] 4 | 5 | DOCKER_CUDNN_HEADER = """ 6 | ###################################### CUDNN ################################### 7 | """ 8 | 9 | DOCKER_RUNTIME_CONTENTS = {} 10 | DOCKER_RUNTIME_CONTENTS['18.04'] = {} 11 | DOCKER_RUNTIME_CONTENTS['16.04'] = {} 12 | DOCKER_RUNTIME_CONTENTS['18.04']['10.0'] = {} 13 | DOCKER_RUNTIME_CONTENTS['18.04']['9.2'] = {} 14 | DOCKER_RUNTIME_CONTENTS['16.04']['10.0'] = {} 15 | DOCKER_RUNTIME_CONTENTS['16.04']['9.0'] = {} 16 | DOCKER_RUNTIME_CONTENTS['16.04']['8.0'] = {} 17 | 18 | DOCKER_RUNTIME_CONTENTS['18.04']['10.0']['7'] = """ 19 | ENV CUDNN_VERSION 7.4.2.24 20 | 21 | LABEL com.nvidia.cudnn.version="${CUDNN_VERSION}" 22 | 23 | RUN apt-get update && apt-get install -y --no-install-recommends \\ 24 | libcudnn7=$CUDNN_VERSION-1+cuda10.0 && \\ 25 | apt-mark hold libcudnn7 && \\ 26 | rm -rf /var/lib/apt/lists/* 27 | """ 28 | 29 | DOCKER_RUNTIME_CONTENTS['18.04']['9.2']['7'] = """ 30 | ENV CUDNN_VERSION 7.4.1.5 31 | LABEL com.nvidia.cudnn.version="${CUDNN_VERSION}" 32 | 33 | RUN apt-get update && apt-get install -y --no-install-recommends \\ 34 | libcudnn7=$CUDNN_VERSION-1+cuda9.2 && \\ 35 | apt-mark hold libcudnn7 && \\ 36 | rm -rf /var/lib/apt/lists/* 37 | """ 38 | 39 | DOCKER_RUNTIME_CONTENTS['16.04']['10.0']['7'] = """ 40 | ENV CUDNN_VERSION 7.4.2.24 41 | LABEL com.nvidia.cudnn.version="${CUDNN_VERSION}" 42 | 43 | RUN apt-get update && apt-get install -y --no-install-recommends \\ 44 | libcudnn7=$CUDNN_VERSION-1+cuda10.0 && \\ 45 | apt-mark hold libcudnn7 && \\ 46 | rm -rf /var/lib/apt/lists/* 47 | """ 48 | 49 | DOCKER_RUNTIME_CONTENTS['16.04']['9.0']['7'] = """ 50 | RUN apt-get update && apt-get install -y --no-install-recommends \\ 51 | libcudnn7=$CUDNN_VERSION-1+cuda9.0 && \\ 52 | apt-mark hold libcudnn7 && \\ 53 | rm -rf /var/lib/apt/lists/* 54 | """ 55 | 56 | DOCKER_RUNTIME_CONTENTS['16.04']['8.0']['7'] = """ 57 | RUN echo "deb https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1604/x86_64 /" > /etc/apt/sources.list.d/nvidia-ml.list 58 | 59 | ENV CUDNN_VERSION 7.2.1.38 60 | LABEL com.nvidia.cudnn.version="${CUDNN_VERSION}" 61 | 62 | RUN apt-get update && apt-get install -y --no-install-recommends \\ 63 | libcudnn7=$CUDNN_VERSION-1+cuda8.0 && \\ 64 | apt-mark hold libcudnn7 && \\ 65 | rm -rf /var/lib/apt/lists/* 66 | """ 67 | 68 | DOCKER_RUNTIME_CONTENTS['16.04']['8.0']['6'] = """ 69 | RUN echo "deb https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1604/x86_64 /" > /etc/apt/sources.list.d/nvidia-ml.list 70 | 71 | ENV CUDNN_VERSION 6.0.21 72 | LABEL com.nvidia.cudnn.version="${CUDNN_VERSION}" 73 | 74 | RUN apt-get update && apt-get install -y --no-install-recommends \ 75 | libcudnn6=$CUDNN_VERSION-1+cuda8.0 && \ 76 | rm -rf /var/lib/apt/lists/* 77 | """ 78 | 79 | DOCKER_RUNTIME_CONTENTS['16.04']['8.0']['5'] = """ 80 | RUN echo "deb https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1604/x86_64 /" > /etc/apt/sources.list.d/nvidia-ml.list 81 | 82 | ENV CUDNN_VERSION 5.1.10 83 | LABEL com.nvidia.cudnn.version="${CUDNN_VERSION}" 84 | 85 | RUN apt-get update && apt-get install -y --no-install-recommends \\ 86 | libcudnn5=$CUDNN_VERSION-1+cuda8.0 && \\ 87 | rm -rf /var/lib/apt/lists/* 88 | """ 89 | 90 | DOCKER_DEVEL_CONTENTS = {} 91 | DOCKER_DEVEL_CONTENTS['18.04'] = {} 92 | DOCKER_DEVEL_CONTENTS['16.04'] = {} 93 | DOCKER_DEVEL_CONTENTS['18.04']['10.0'] = {} 94 | DOCKER_DEVEL_CONTENTS['18.04']['9.2'] = {} 95 | DOCKER_DEVEL_CONTENTS['16.04']['10.0'] = {} 96 | DOCKER_DEVEL_CONTENTS['16.04']['9.0'] = {} 97 | DOCKER_DEVEL_CONTENTS['16.04']['8.0'] = {} 98 | 99 | DOCKER_DEVEL_CONTENTS['18.04']['10.0']['7'] = """ 100 | ENV CUDNN_VERSION 7.4.2.24 101 | 102 | LABEL com.nvidia.cudnn.version="${CUDNN_VERSION}" 103 | 104 | RUN apt-get update && apt-get install -y --no-install-recommends \\ 105 | libcudnn7=$CUDNN_VERSION-1+cuda10.0 \\ 106 | libcudnn7-dev=$CUDNN_VERSION-1+cuda10.0 && \\ 107 | apt-mark hold libcudnn7 && \\ 108 | rm -rf /var/lib/apt/lists/* 109 | """ 110 | 111 | DOCKER_DEVEL_CONTENTS['18.04']['9.2']['7'] = """ 112 | ENV CUDNN_VERSION 7.4.1.5 113 | LABEL com.nvidia.cudnn.version="${CUDNN_VERSION}" 114 | 115 | RUN apt-get update && apt-get install -y --no-install-recommends \\ 116 | libcudnn7=$CUDNN_VERSION-1+cuda9.2 \\ 117 | libcudnn7-dev=$CUDNN_VERSION-1+cuda9.2 && \\ 118 | apt-mark hold libcudnn7 && \\ 119 | rm -rf /var/lib/apt/lists/* 120 | """ 121 | 122 | DOCKER_DEVEL_CONTENTS['16.04']['10.0']['7'] = """ 123 | ENV CUDNN_VERSION 7.4.1.5 124 | LABEL com.nvidia.cudnn.version="${CUDNN_VERSION}" 125 | 126 | RUN apt-get update && apt-get install -y --no-install-recommends \\ 127 | libcudnn7=$CUDNN_VERSION-1+cuda10.0 \\ 128 | libcudnn7-dev=$CUDNN_VERSION-1+cuda10.0 && \\ 129 | apt-mark hold libcudnn7 && \\ 130 | rm -rf /var/lib/apt/lists/* 131 | """ 132 | 133 | DOCKER_DEVEL_CONTENTS['16.04']['9.0']['7'] = """ 134 | ENV CUDNN_VERSION 7.4.2.24 135 | LABEL com.nvidia.cudnn.version="${CUDNN_VERSION}" 136 | 137 | RUN apt-get update && apt-get install -y --no-install-recommends \\ 138 | libcudnn7=$CUDNN_VERSION-1+cuda9.0 \\ 139 | libcudnn7-dev=$CUDNN_VERSION-1+cuda9.0 && \\ 140 | apt-mark hold libcudnn7 && \\ 141 | rm -rf /var/lib/apt/lists/* 142 | """ 143 | 144 | DOCKER_DEVEL_CONTENTS['16.04']['8.0']['7'] = """ 145 | RUN echo "deb https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1604/x86_64 /" > /etc/apt/sources.list.d/nvidia-ml.list 146 | 147 | ENV CUDNN_VERSION 7.2.1.38 148 | LABEL com.nvidia.cudnn.version="${CUDNN_VERSION}" 149 | 150 | RUN apt-get update && apt-get install -y --no-install-recommends \\ 151 | libcudnn7=$CUDNN_VERSION-1+cuda8.0 \\ 152 | libcudnn7-dev=$CUDNN_VERSION-1+cuda8.0 && \\ 153 | apt-mark hold libcudnn7 && \\ 154 | rm -rf /var/lib/apt/lists/* 155 | """ 156 | 157 | DOCKER_DEVEL_CONTENTS['16.04']['8.0']['6'] = """ 158 | RUN echo "deb https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1604/x86_64 /" > /etc/apt/sources.list.d/nvidia-ml.list 159 | 160 | ENV CUDNN_VERSION 6.0.21 161 | LABEL com.nvidia.cudnn.version="${CUDNN_VERSION}" 162 | 163 | RUN apt-get update && apt-get install -y --no-install-recommends \ 164 | libcudnn6=$CUDNN_VERSION-1+cuda8.0 \ 165 | libcudnn6-dev=$CUDNN_VERSION-1+cuda8.0 && \ 166 | rm -rf /var/lib/apt/lists/* 167 | """ 168 | 169 | DOCKER_DEVEL_CONTENTS['16.04']['8.0']['5'] = """ 170 | RUN echo "deb https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1604/x86_64 /" > /etc/apt/sources.list.d/nvidia-ml.list 171 | 172 | ENV CUDNN_VERSION 5.1.10 173 | LABEL com.nvidia.cudnn.version="${CUDNN_VERSION}" 174 | 175 | RUN apt-get update && apt-get install -y --no-install-recommends \\ 176 | libcudnn5=$CUDNN_VERSION-1+cuda8.0 \\ 177 | libcudnn5-dev=$CUDNN_VERSION-1+cuda8.0 && \\ 178 | rm -rf /var/lib/apt/lists/* 179 | """ 180 | 181 | def write(DOCKER_FILE, version, cuda, ubuntu): 182 | if version in versions: 183 | with open(DOCKER_FILE, "a") as dockerfile: 184 | dockerfile.write(DOCKER_CUDNN_HEADER) 185 | cuda = cuda.split('-')[0] 186 | cudnn = version.split('-')[0] 187 | try: 188 | if 'runtime' in version: 189 | dockerfile.write(DOCKER_RUNTIME_CONTENTS[ubuntu][cuda][cudnn]) 190 | elif 'devel' in version: 191 | dockerfile.write(DOCKER_DEVEL_CONTENTS[ubuntu][cuda][cudnn]) 192 | except KeyError as e: 193 | print("CUDNN version %s not supported in Ubuntu %s with CUDA %s" % (cudnn, ubuntu, cuda) ) 194 | sys.exit(1) 195 | return 196 | else: 197 | print("cudnn: version %s not supported. Options: %s" % (version, versions)) 198 | sys.exit(1) 199 | 200 | -------------------------------------------------------------------------------- /components/custom.py: -------------------------------------------------------------------------------- 1 | DOCKER_CONTENTS = """ 2 | ################################### CUSTOM ##################################### 3 | 4 | RUN %s 5 | """ 6 | 7 | def write(DOCKER_FILE, command_list): 8 | cstr = command_list[0] 9 | for c in command_list[1:]: 10 | cstr += ' \\\n && ' + c 11 | with open(DOCKER_FILE, "a") as dockerfile: 12 | dockerfile.write(DOCKER_CONTENTS % cstr) 13 | return 14 | 15 | -------------------------------------------------------------------------------- /components/icub.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | versions = ['binary'] 4 | 5 | DOCKER_CORE_CONTENTS = """ 6 | ##################################### ICUB ##################################### 7 | 8 | # install packages 9 | RUN apt-get -o Acquire::ForceIPv4=true update && apt-get -o Acquire::ForceIPv4=true install -q -y \\ 10 | dirmngr \\ 11 | gnupg2 \\ 12 | lsb-release \\ 13 | && rm -rf /var/lib/apt/lists/* 14 | 15 | # setup keys 16 | RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 57A5ACB6110576A6 17 | 18 | # setup sources.list 19 | RUN echo "deb http://www.icub.org/ubuntu `lsb_release -sc` contrib/science" > /etc/apt/sources.list.d/icub.list 20 | 21 | RUN apt-get -o Acquire::ForceIPv4=true update\\ 22 | && apt-get -o Acquire::ForceIPv4=true install --no-install-recommends -y \\ 23 | icub \\ 24 | && rm -rf /var/lib/apt/lists/* 25 | """ 26 | 27 | def write(DOCKER_FILE, version): 28 | if version in versions: 29 | with open(DOCKER_FILE, "a") as dockerfile: 30 | dockerfile.write(DOCKER_CORE_CONTENTS) 31 | return 32 | else: 33 | print("icub: version %s not supported. Options: %s" % (version, versions)) 34 | sys.exit(1) 35 | 36 | -------------------------------------------------------------------------------- /components/jupyterlab.py: -------------------------------------------------------------------------------- 1 | DOCKER_CONTENTS = """ 2 | ################################## JUPYTERLAB ################################## 3 | 4 | ENV DEBIAN_FRONTEND noninteractive 5 | ENV LANG C.UTF-8 6 | ENV LC_ALL C.UTF-8 7 | 8 | RUN apt-get -o Acquire::ForceIPv4=true update && apt-get -yq dist-upgrade \\ 9 | && apt-get -o Acquire::ForceIPv4=true install -yq --no-install-recommends \\ 10 | locales cmake git build-essential \\ 11 | python-pip \\ 12 | python3-pip python3-setuptools \\ 13 | && apt-get clean \\ 14 | && rm -rf /var/lib/apt/lists/* 15 | 16 | RUN pip3 install --upgrade pip setuptools \\ 17 | && python3 -m pip install jupyterlab==0.35.4 bash_kernel==0.7.1 tornado==5.1.1 \\ 18 | && python3 -m bash_kernel.install 19 | 20 | ENV SHELL=/bin/bash \\ 21 | NB_USER=jovyan \\ 22 | NB_UID=1000 \\ 23 | LANG=en_US.UTF-8 \\ 24 | LANGUAGE=en_US.UTF-8 25 | 26 | ENV HOME=/home/${NB_USER} 27 | 28 | RUN adduser --disabled-password \\ 29 | --gecos "Default user" \\ 30 | --uid ${NB_UID} \\ 31 | ${NB_USER} 32 | 33 | EXPOSE 8888 34 | 35 | CMD ["jupyter", "lab", "--no-browser", "--ip=0.0.0.0", "--NotebookApp.token=''"] 36 | """ 37 | 38 | def write(DOCKER_FILE): 39 | with open(DOCKER_FILE, "a") as dockerfile: 40 | dockerfile.write(DOCKER_CONTENTS) 41 | return 42 | 43 | -------------------------------------------------------------------------------- /components/matlab.py: -------------------------------------------------------------------------------- 1 | DOCKER_CONTENTS = """ 2 | #################################### MATLAB #################################### 3 | 4 | RUN apt-get update \\ 5 | && apt-get install -yq --no-install-recommends \\ 6 | libpng12-dev libfreetype6-dev \\ 7 | libblas-dev liblapack-dev gfortran build-essential xorg \\ 8 | && apt-get clean \\ 9 | && rm -rf /var/lib/apt/lists/* 10 | 11 | RUN pip3 install matlab_kernel 12 | 13 | ENV PATH="%s/bin:${PATH}" 14 | """ 15 | 16 | def write(DOCKER_FILE, host_path): 17 | with open(DOCKER_FILE, "a") as dockerfile: 18 | dockerfile.write(DOCKER_CONTENTS % host_path) 19 | return 20 | 21 | -------------------------------------------------------------------------------- /components/pip.py: -------------------------------------------------------------------------------- 1 | DOCKER_CONTENTS = """ 2 | ##################################### PIP ###################################### 3 | 4 | RUN pip2 install --upgrade pip 5 | 6 | RUN pip2 install %s 7 | """ 8 | 9 | def write(DOCKER_FILE, package_list): 10 | pstr = '' 11 | for p in package_list: 12 | pstr += ' \\\n ' + p 13 | with open(DOCKER_FILE, "a") as dockerfile: 14 | dockerfile.write(DOCKER_CONTENTS % pstr) 15 | return 16 | 17 | -------------------------------------------------------------------------------- /components/pip3.py: -------------------------------------------------------------------------------- 1 | DOCKER_CONTENTS = """ 2 | ##################################### PIP3 ##################################### 3 | 4 | RUN pip3 install %s 5 | """ 6 | 7 | def write(DOCKER_FILE, package_list): 8 | pstr = '' 9 | for p in package_list: 10 | pstr += ' \\\n ' + p 11 | with open(DOCKER_FILE, "a") as dockerfile: 12 | dockerfile.write(DOCKER_CONTENTS % pstr) 13 | return 14 | 15 | -------------------------------------------------------------------------------- /components/repo.py: -------------------------------------------------------------------------------- 1 | DOCKER_REPO_HEADER = """ 2 | ##################################### REPO ##################################### 3 | 4 | RUN apt-get update \\ 5 | && apt-get install -yq --no-install-recommends \\ 6 | software-properties-common \\ 7 | && apt-get clean \\ 8 | && rm -rf /var/lib/apt/lists/* 9 | """ 10 | DOCKER_REPO_ADD = """ 11 | RUN apt-add-repository %s 12 | """ 13 | 14 | def write(DOCKER_FILE, repo_list): 15 | pstr = DOCKER_REPO_HEADER 16 | for p in repo_list: 17 | pstr += DOCKER_REPO_ADD % p 18 | with open(DOCKER_FILE, "a") as dockerfile: 19 | dockerfile.write(pstr) 20 | return 21 | 22 | -------------------------------------------------------------------------------- /components/ros.py: -------------------------------------------------------------------------------- 1 | import os, sys 2 | 3 | versions = ['kinetic-ros-core', 'kinetic-ros-base', 'kinetic-robot', 4 | 'kinetic-perception', 'kinetic-desktop', 'kinetic-desktop-full', 5 | 'melodic-ros-core', 'melodic-ros-base', 'melodic-robot', 6 | 'melodic-perception', 'melodic-desktop', 'melodic-desktop-full'] 7 | 8 | DOCKER_CORE_CONTENTS = """ 9 | ###################################### ROS ##################################### 10 | 11 | # install packages 12 | RUN apt-get -o Acquire::ForceIPv4=true update && apt-get -o Acquire::ForceIPv4=true install -q -y \\ 13 | dirmngr \\ 14 | gnupg2 \\ 15 | lsb-release \\ 16 | && rm -rf /var/lib/apt/lists/* 17 | 18 | # setup keys 19 | RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654 20 | 21 | # setup sources.list 22 | RUN echo "deb http://packages.ros.org/ros/ubuntu `lsb_release -sc` main" > /etc/apt/sources.list.d/ros-latest.list 23 | 24 | # install bootstrap tools 25 | RUN apt-get -o Acquire::ForceIPv4=true update && apt-get -o Acquire::ForceIPv4=true install --no-install-recommends -y \\ 26 | python-rosdep \\ 27 | python-rosinstall \\ 28 | python-vcstools \\ 29 | python-catkin-tools \\ 30 | && rm -rf /var/lib/apt/lists/* 31 | 32 | # bootstrap rosdep 33 | RUN rosdep init \\ 34 | && rosdep update 35 | 36 | # install ros packages 37 | ENV ROS_DISTRO %s 38 | RUN apt-get -o Acquire::ForceIPv4=true update && apt-get -o Acquire::ForceIPv4=true install -y \\ 39 | %s \\ 40 | && rm -rf /var/lib/apt/lists/* 41 | 42 | # setup entrypoint 43 | COPY ./ros_entrypoint.sh / 44 | RUN chmod a+x /ros_entrypoint.sh 45 | 46 | ENTRYPOINT ["/ros_entrypoint.sh"] 47 | 48 | RUN mkdir -p /home/jovyan/.ros 49 | RUN chown jovyan.jovyan /home/jovyan/.ros 50 | """ 51 | 52 | PACKAGE_VERSION = {'kinetic': '1.3.2-0*', 53 | 'melodic': '1.4.1-0*'} 54 | 55 | def write(DOCKER_FILE, version): 56 | if version in versions: 57 | distro = version.split('-')[0] 58 | config = '-'.join(version.split('-')[1:]) 59 | with open(DOCKER_FILE, "a") as dockerfile: 60 | dockerfile.write(DOCKER_CORE_CONTENTS % (distro, 'ros-' + version + '=' + PACKAGE_VERSION[distro])) 61 | return 62 | else: 63 | print("ros: version %s not supported. Options: %s" % (version, versions)) 64 | sys.exit(1) 65 | 66 | ROS_ENTRYPOINT_CONTENTS = """#!/bin/bash 67 | set -e 68 | 69 | # setup ros environment 70 | source "/opt/ros/$ROS_DISTRO/setup.bash" 71 | exec "$@" 72 | """ 73 | 74 | def entry_point(): 75 | with open('ros_entrypoint.sh', 'w') as output_file: 76 | output_file.write(ROS_ENTRYPOINT_CONTENTS) 77 | os.chmod('ros_entrypoint.sh', 0o755) 78 | return 79 | 80 | 81 | -------------------------------------------------------------------------------- /components/source.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | DOCKER_SOURCE_HEADER = """ 4 | ################################### SOURCE ##################################### 5 | """ 6 | 7 | DEPENDENCIES = """ 8 | RUN apt-get -o Acquire::ForceIPv4=true update \\ 9 | && apt-get -o Acquire::ForceIPv4=true install -yq --no-install-recommends \\ 10 | %s && apt-get clean \\ 11 | && rm -rf /var/lib/apt/lists/* 12 | """ 13 | 14 | CLONE = """ 15 | RUN git clone %s /%s \\ 16 | && cd /%s \\""" 17 | 18 | CHECKOUT = """ 19 | && git checkout %s \\""" 20 | 21 | UNZIP = """ 22 | RUN mkdir /%s && cd /%s \\ 23 | && wget %s \\ 24 | && unzip %s && rm %s \\ 25 | && cd %s-%s \\""" 26 | 27 | BUILD_CMAKE = """ 28 | && mkdir build \\ 29 | && cd build \\ 30 | && cmake %s %s \\ 31 | && %s \\""" 32 | 33 | BUILD_CATKIN_MAKE = """ 34 | && mkdir -p ${HOME}/catkin_ws/src \\ 35 | && cp -R /%s ${HOME}/catkin_ws/src/. \\ 36 | && cd ${HOME}/catkin_ws \\ 37 | && apt-get -o Acquire::ForceIPv4=true update \\ 38 | && /bin/bash -c "source /opt/ros/${ROS_DISTRO}/setup.bash && rosdep update && rosdep install --as-root apt:false --from-paths src --ignore-src -r -y" \\ 39 | && apt-get clean \\ 40 | && rm -rf /var/lib/apt/lists/* \\ 41 | && /bin/bash -c "source /opt/ros/${ROS_DISTRO}/setup.bash && catkin_make" \\""" 42 | 43 | BUILD_CATKIN_BUILD = """ 44 | && mkdir -p ${HOME}/catkin_ws/src \\ 45 | && cp -R /%s ${HOME}/catkin_ws/src/. \\ 46 | && cd ${HOME}/catkin_ws \\ 47 | && apt-get -o Acquire::ForceIPv4=true update \\ 48 | && /bin/bash -c "source /opt/ros/${ROS_DISTRO}/setup.bash && rosdep update && rosdep install --as-root apt:false --from-paths src --ignore-src -r -y" \\ 49 | && apt-get clean \\ 50 | && rm -rf /var/lib/apt/lists/* \\ 51 | && /bin/bash -c "source /opt/ros/${ROS_DISTRO}/setup.bash && catkin build" \\""" 52 | 53 | KEEP_SOURCE = """ 54 | && cp -R /%s ${HOME}/. \\""" 55 | 56 | DELETE = """ 57 | && rm -fr /%s 58 | """ 59 | 60 | def write(DOCKER_FILE, package_list): 61 | s = DOCKER_SOURCE_HEADER 62 | for p in package_list: 63 | if 'depends' in p.keys() and p['depends']: 64 | pstr = '' 65 | for apt_pack in p['depends']: 66 | pstr += ' ' + apt_pack + ' \\\n' 67 | s += DEPENDENCIES % pstr 68 | if 'repo' in p.keys(): 69 | s += CLONE % (p['repo'], p['name'], p['name']) 70 | elif 'zip' in p.keys(): 71 | url = p['zip'] 72 | archive = url.split('/')[-1] 73 | version = '.'.join(archive.split('.')[:-1]) 74 | s += UNZIP % (p['name'], p['name'], url, archive, archive, p['name'], version) 75 | else: 76 | print('source: cannot get source for package %s' % p['name']) 77 | sys.exit(1) 78 | if 'checkout' in p.keys(): 79 | s += CHECKOUT % p['checkout'] 80 | if p['build'] == 'cmake': 81 | if 'cmake_options' in p.keys(): 82 | cmake_options = p['cmake_options'] 83 | else: 84 | cmake_options = '' 85 | if 'cmake_folder' in p.keys(): 86 | cmake_folder = p['cmake_folder'] 87 | else: 88 | cmake_folder = '../' 89 | if 'make_command' in p.keys(): 90 | make_command = p['make_command'] 91 | else: 92 | make_command = 'make -j4 install' 93 | s += BUILD_CMAKE % (cmake_options, cmake_folder, make_command) 94 | if 'keep_source' in p.keys() and p['keep_source'] == True: 95 | s += KEEP_SOURCE % p['name'] 96 | elif p['build'] == 'catkin_build': 97 | s += BUILD_CATKIN_BUILD % p['name'] 98 | elif p['build'] == 'catkin_make': 99 | s += BUILD_CATKIN_MAKE % p['name'] 100 | else: 101 | print("Warning: build method '%s' not defined for package '%s'" % (p['build'], p['name'])) 102 | s += DELETE % p['name'] 103 | 104 | with open(DOCKER_FILE, "a") as dockerfile: 105 | dockerfile.write(s) 106 | return 107 | 108 | -------------------------------------------------------------------------------- /components/tail.py: -------------------------------------------------------------------------------- 1 | DOCKER_CONTENTS = """ 2 | ##################################### TAIL ##################################### 3 | 4 | RUN chown ${NB_UID} ${HOME}/%s 5 | 6 | USER ${NB_USER} 7 | 8 | WORKDIR ${HOME}/%s 9 | """ 10 | 11 | def write(DOCKER_FILE, name): 12 | with open(DOCKER_FILE, "a") as dockerfile: 13 | dockerfile.write(DOCKER_CONTENTS % (name, name)) 14 | return 15 | 16 | -------------------------------------------------------------------------------- /components/ubuntu.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | versions = [16.04, '16.04', 'xenial', 4 | 18.04, '18.04', 'melodic'] 5 | 6 | DOCKER_CONTENTS = "FROM ubuntu:%s\n" 7 | 8 | DOCKER_CONTENTS_OPENGL_RUNTIME = "FROM nvidia/opengl:1.0-glvnd-runtime-ubuntu%s\n" 9 | 10 | DOCKER_CONTENTS_OPENGL_DEVEL = "FROM nvidia/opengl:1.0-glvnd-devel-ubuntu%s\n" 11 | 12 | def write(DOCKER_FILE, version, opengl): 13 | if version in versions: 14 | if opengl is None: 15 | with open(DOCKER_FILE, "w") as dockerfile: 16 | dockerfile.write(DOCKER_CONTENTS % version) 17 | else: 18 | if version == 'xenial': 19 | version = '16.04' 20 | elif version == 'melodic': 21 | version = '18.04' 22 | 23 | if opengl == 'runtime': 24 | with open(DOCKER_FILE, "w") as dockerfile: 25 | dockerfile.write(DOCKER_CONTENTS_OPENGL_RUNTIME % version) 26 | elif opengl == 'devel': 27 | with open(DOCKER_FILE, "w") as dockerfile: 28 | dockerfile.write(DOCKER_CONTENTS_OPENGL_DEVEL % version) 29 | else: 30 | print("opengl: option %s not supported. Options: %s" % (opengl, ['runtime', 'devel'])) 31 | sys.exit(1) 32 | return 33 | else: 34 | print("ubuntu: version %s not supported. Options: %s" % (version, versions)) 35 | sys.exit(1) 36 | 37 | def canonic_version(version): 38 | if version == 'xenial' or version == 16.04: 39 | version = '16.04' 40 | elif version == 'melodic' or version == 18.04: 41 | version = '18.04' 42 | return version 43 | 44 | FASTEST_MIRROR = """ 45 | ENV DEBIAN_FRONTEND noninteractive 46 | 47 | RUN apt-get update && apt-get install -y \\ 48 | wget \\ 49 | && rm -rf /var/lib/apt/lists/* 50 | 51 | RUN wget -q -nv -O- http://ftp.debian.org/debian/pool/main/n/netselect/netselect_0.3.ds1-26_amd64.deb > /tmp/netselect_0.3.ds1-26_amd64.deb 52 | 53 | RUN dpkg -i /tmp/netselect_0.3.ds1-26_amd64.deb 54 | 55 | RUN netselect -s1 -t20 `wget -q -nv -O- https://launchpad.net/ubuntu/+archivemirrors | grep -P -B8 "statusUP|statusSIX" | grep -o -P "(f|ht)tp.*\\"" | tr '"\\n' ' '` 2>/dev/null | awk '{ print $2 }' > /fastest-mirror 56 | 57 | RUN MIRROR=`cat /fastest-mirror` && sed -i "s#http://archive.ubuntu.com/ubuntu/#$MIRROR#g" /etc/apt/sources.list 58 | """ 59 | 60 | def select_fastest_mirror(DOCKER_FILE): 61 | with open(DOCKER_FILE, "a") as dockerfile: 62 | dockerfile.write(FASTEST_MIRROR) 63 | 64 | COUNTRY_MIRROR = """ 65 | RUN sed --in-place --regexp-extended "s/(\/\/)(archive\.ubuntu)/\\1%s.\\2/" /etc/apt/sources.list && \ 66 | apt-get update && apt-get upgrade --yes 67 | """ 68 | 69 | def select_country_mirror(DOCKER_FILE, country_code): 70 | with open(DOCKER_FILE, "a") as dockerfile: 71 | dockerfile.write(COUNTRY_MIRROR % country_code) 72 | 73 | -------------------------------------------------------------------------------- /form.py: -------------------------------------------------------------------------------- 1 | from ipywidgets import Layout, Button, Box, HBox, VBox, Text, Textarea, Dropdown, Output, Accordion 2 | 3 | 4 | def on_value_change(change): 5 | out.clear_output() 6 | 7 | def on_ubuntu_change(change): 8 | out.clear_output() 9 | if change['new']=='16.04': 10 | ros.options=['none', 'kinetic-ros-core', 'kinetic-ros-base', 'kinetic-robot', 11 | 'kinetic-perception', 'kinetic-desktop', 'kinetic-desktop-full'] 12 | cuda.options=['none', '8.0-runtime', '8.0-devel', '9.0-runtime', '9.0-devel', 13 | '10.0-runtime', '10.0-devel'] 14 | cudnn.options=['none', '5-runtime', '5-devel', '6-runtime', '6-devel', '7-runtime', '7-devel'] 15 | elif change['new']=='18.04': 16 | ros.options=['none', 'melodic-ros-core', 'melodic-ros-base', 'melodic-robot', 17 | 'melodic-perception', 'melodic-desktop', 'melodic-desktop-full'] 18 | cuda.options=['none', '9.2-runtime', '9.2-devel', '10.0-runtime', '10.0-devel'] 19 | cudnn.options=['none', '7-runtime', '7-devel'] 20 | 21 | def on_cuda_change(change): 22 | out.clear_output() 23 | if change['new']=='8.0-runtime' or change['new']=='8.0-devel': 24 | cudnn.options=['none', '5-runtime', '5-devel', '6-runtime', '6-devel', '7-runtime', '7-devel'] 25 | else: 26 | cudnn.options=['none', '7-runtime', '7-devel'] 27 | 28 | name = Text( 29 | value='', 30 | placeholder='name of the Docker image', 31 | description='Name:', 32 | disabled=False 33 | ) 34 | name.observe(on_value_change, names='value') 35 | 36 | ubuntu = Dropdown( 37 | options=['16.04', '18.04'], 38 | value='16.04', 39 | description='Ubuntu:', 40 | disabled=False 41 | ) 42 | ubuntu.observe(on_ubuntu_change, names='value') 43 | 44 | x11 = Dropdown( 45 | options=['no', 'yes'], 46 | value='no', 47 | description='X11:', 48 | disabled=False 49 | ) 50 | x11.observe(on_value_change, names='value') 51 | 52 | opengl = Dropdown( 53 | options=['none', 'runtime', 'devel'], 54 | value='none', 55 | description='OpenGL:', 56 | disabled=False 57 | ) 58 | opengl.observe(on_value_change, names='value') 59 | 60 | cuda = Dropdown( 61 | options=['none', '8.0-runtime', '8.0-devel', '9.0-runtime', '9.0-devel', '10.0-runtime', '10.0-devel'], 62 | value='none', 63 | description='CUDA:', 64 | disabled=False 65 | ) 66 | cuda.observe(on_cuda_change, names='value') 67 | 68 | cudnn = Dropdown( 69 | options=['none', '5-runtime', '5-devel', '6-runtime', '6-devel', 70 | '7-runtime', '7-devel'], 71 | value='none', 72 | description='cuDNN:', 73 | disabled=False 74 | ) 75 | cudnn.observe(on_value_change, names='value') 76 | 77 | ros = Dropdown( 78 | options=['none', 'kinetic-ros-core', 'kinetic-ros-base', 'kinetic-robot', 79 | 'kinetic-perception', 'kinetic-desktop', 'kinetic-desktop-full'], 80 | value='none', 81 | description='ROS:', 82 | disabled=False 83 | ) 84 | ros.observe(on_value_change, names='value') 85 | 86 | build = Dropdown( 87 | options=['none', 'cmake', 'catkin_make', 'catkin_build'], 88 | value='none', 89 | description='Build:', 90 | disabled=False 91 | ) 92 | build.observe(on_value_change, names='value') 93 | 94 | apt = Textarea( 95 | value='', 96 | placeholder='List of APT packages\n(one package per line)', 97 | description='APT:', 98 | disabled=False 99 | ) 100 | apt.observe(on_value_change, names='value') 101 | 102 | pip2 = Textarea( 103 | value='', 104 | placeholder='List of Python 2 packages\n(one package per line)', 105 | description='pip2:', 106 | disabled=False 107 | ) 108 | pip2.observe(on_value_change, names='value') 109 | 110 | pip3 = Textarea( 111 | value='', 112 | placeholder='List of Python 3 packages\n(one package per line)', 113 | description='pip3:', 114 | disabled=False 115 | ) 116 | pip3.observe(on_value_change, names='value') 117 | 118 | custom = Textarea( 119 | value='', 120 | placeholder='List of custom commands\n(one command per line)', 121 | description='custom:', 122 | disabled=False 123 | ) 124 | custom.observe(on_value_change, names='value') 125 | 126 | matlab = Text( 127 | value='', 128 | placeholder='path in the local host', 129 | description='MATLAB:', 130 | disabled=False 131 | ) 132 | matlab.observe(on_value_change, names='value') 133 | 134 | mac = Text( 135 | value='', 136 | placeholder='MAC address of local host', 137 | description=' ', 138 | disabled=False 139 | ) 140 | mac.observe(on_value_change, names='value') 141 | 142 | import os, yaml 143 | from roslab_create import write_docker_file 144 | from IPython.core.display import display, HTML 145 | from IPython.display import clear_output 146 | 147 | def generate_dockerfile(b): 148 | out.clear_output() 149 | with out: 150 | if name.value is '': 151 | print('Error: name is empty!') 152 | else: 153 | print("Generating Dockerfile...") 154 | base = {'ubuntu': ubuntu.value} 155 | if not opengl.value is 'none': 156 | base['opengl'] = opengl.value 157 | if not cuda.value is 'none': 158 | base['cuda'] = cuda.value 159 | if not cudnn.value is 'none': 160 | base['cudnn'] = cudnn.value 161 | if not ros.value is 'none': 162 | base['ros'] = ros.value 163 | data = {'name': name.value, 'base': base} 164 | if not build.value is 'none': 165 | data['build'] = build.value 166 | if not apt.value is '': 167 | data['apt'] = apt.value.splitlines() 168 | if not pip2.value is '': 169 | data['pip'] = pip2.value.splitlines() 170 | if not pip3.value is '': 171 | data['pip3'] = pip3.value.splitlines() 172 | if not custom.value is '': 173 | data['custom'] = custom.value.splitlines() 174 | if not matlab.value is '': 175 | data['matlab'] = {} 176 | data['matlab']['host_path'] = matlab.value 177 | data['matlab']['mac_address'] = mac.value 178 | if len(source_list.children) > 0: 179 | data['source'] = [] 180 | for sp in source_list.children: 181 | source_name = sp.children[0].value 182 | repo = sp.children[1].value 183 | if source_name != '' and repo != '': 184 | depends = sp.children[2].value.splitlines() 185 | source_build = sp.children[3].value 186 | data['source'].append({'name':source_name, 'repo':repo, 'depends':depends, 'build':source_build}) 187 | else: 188 | print('Ignoring source package with empty name and/or repo') 189 | with open('roslab.yaml', 'w') as outfile: 190 | yaml.dump(data, outfile, default_flow_style=False) 191 | write_docker_file(data) 192 | print('Done!') 193 | os.rename('roslab.dockerfile', 'Dockerfile') 194 | display(HTML('
It can be downloaded from here.
')) 195 | if not ros.value is 'none': 196 | display(HTML('Since you are using ROS, please also download ros_entrypoint.sh.
')) 197 | #display(HTML('WARNING: some browsers deactivate the execution permissions of this file. In that case, you shoudl run the following command in a terminal:
')) 198 | #display(HTML('''chmod a+x ros_entrypoint.sh
''')) 199 | display(HTML('1. Put the downloaded file(s) in your source repository, and build your Docker image with:docker build -t %s .
2. Run your Docker image with:%s
3. Open this link in your browser: http://localhost:8888
')) 215 | 216 | generate = Button( 217 | description='Proceed', 218 | disabled=False, 219 | button_style='', # 'success', 'info', 'warning', 'danger' or '' 220 | tooltip='Generate Dockerfile' 221 | ) 222 | generate.on_click(generate_dockerfile) 223 | 224 | def add_source_item(b): 225 | name = Text( 226 | value='', 227 | placeholder='name of source package', 228 | description='Name:', 229 | disabled=False 230 | ) 231 | name.observe(on_value_change, names='value') 232 | repo = Text( 233 | value='', 234 | placeholder='URL of git repository', 235 | description='repo:', 236 | disabled=False 237 | ) 238 | repo.observe(on_value_change, names='value') 239 | depends = Textarea( 240 | value='', 241 | placeholder='List of APT packages\n(one package per line)', 242 | description='depends:', 243 | disabled=False 244 | ) 245 | depends.observe(on_value_change, names='value') 246 | build = Dropdown( 247 | options=['cmake', 'catkin_make', 'catkin_build'], 248 | value='cmake', 249 | description='build:', 250 | disabled=False 251 | ) 252 | build.observe(on_value_change, names='value') 253 | source_items = [name, repo, depends, build] 254 | source_form = Box(source_items, layout=Layout( 255 | display='flex', 256 | flex_flow='column', 257 | #border='solid 1px', 258 | align_items='stretch' 259 | )) 260 | source_list.children += (source_form,) 261 | n = len(source_list.children) 262 | source_list.set_title(n-1, 'Source package %d' % n) 263 | 264 | add_source = Button( 265 | description='Add source package', 266 | disabled=False, 267 | button_style='', # 'success', 'info', 'warning', 'danger' or '' 268 | tooltip='Add source package' 269 | ) 270 | add_source.on_click(add_source_item) 271 | 272 | source_list = Accordion(children=[]) 273 | 274 | out = Output() 275 | 276 | form_item_layout = Layout( 277 | display='flex', 278 | flex_flow='row', 279 | justify_content='space-between' 280 | ) 281 | 282 | left_items = [name, ubuntu, x11, opengl, cuda, cudnn, ros, build, generate] 283 | mid_items = [apt, pip2, pip3, custom, matlab, mac] 284 | right_items = [add_source, source_list] 285 | 286 | left_form = Box(left_items, layout=Layout( 287 | display='flex', 288 | flex_flow='column', 289 | #border='solid 1px', 290 | align_items='stretch', 291 | width='32%' 292 | )) 293 | mid_form = Box(mid_items, layout=Layout( 294 | display='flex', 295 | flex_flow='column', 296 | #border='solid 1px', 297 | align_items='stretch', 298 | width='32%' 299 | )) 300 | right_form = Box(right_items, layout=Layout( 301 | display='flex', 302 | flex_flow='column', 303 | #border='solid 1px', 304 | align_items='stretch', 305 | width='36%' 306 | )) 307 | out.clear_output() 308 | ui = VBox([HBox([left_form, mid_form, right_form]), out]) 309 | -------------------------------------------------------------------------------- /roslab_create.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os, sys, yaml 3 | import os.path 4 | 5 | PROJECT_DIR = '/project' 6 | PROJECT_FILE = 'roslab.yaml' 7 | DOCKER_FILE = 'roslab.dockerfile' 8 | BUILD_FILE = 'roslab_build.sh' 9 | RUN_FILE = 'roslab_run.sh' 10 | 11 | def main(): 12 | os.chdir(PROJECT_DIR) 13 | yaml_file = read_yaml_file() 14 | write_docker_file(yaml_file) 15 | write_build_script(yaml_file) 16 | write_run_script(yaml_file) 17 | write_docker_ignore() 18 | write_readme_notebook() 19 | 20 | def read_yaml_file(): 21 | try: 22 | with open(PROJECT_FILE, 'r') as stream: 23 | try: 24 | yaml_file = yaml.load(stream, Loader=yaml.FullLoader) 25 | except yaml.YAMLError as e: 26 | print(e) 27 | sys.exit(1) 28 | except FileNotFoundError: 29 | print("File '%s' not found in folder '%s'" % (PROJECT_FILE, PROJECT_DIR)) 30 | sys.exit(1) 31 | return yaml_file 32 | 33 | def write_docker_file(yaml_file): 34 | try: 35 | base = yaml_file['base'] 36 | name = yaml_file['name'] 37 | 38 | if 'ubuntu' in base.keys(): 39 | import components.ubuntu 40 | ubuntu = components.ubuntu.canonic_version(base['ubuntu']) 41 | if 'opengl' in base.keys(): 42 | opengl = base['opengl'] 43 | else: 44 | opengl = None 45 | components.ubuntu.write(DOCKER_FILE, ubuntu, opengl) 46 | #components.ubuntu.select_fastest_mirror(DOCKER_FILE) 47 | #components.ubuntu.select_country_mirror(DOCKER_FILE, "es") 48 | 49 | import components.jupyterlab 50 | components.jupyterlab.write(DOCKER_FILE) 51 | 52 | if 'cuda' in base.keys(): 53 | import components.cuda 54 | version = base['cuda'] 55 | components.cuda.write(DOCKER_FILE, version, ubuntu) 56 | 57 | if 'cudnn' in base.keys(): 58 | if not 'cuda' in base.keys(): 59 | print('cudnn: cuda must be specified for using cudnn') 60 | sys.exit(1) 61 | import components.cudnn 62 | version = base['cudnn'] 63 | components.cudnn.write(DOCKER_FILE, version, base['cuda'], ubuntu) 64 | 65 | if 'ros' in base.keys(): 66 | import components.ros 67 | version = base['ros'] 68 | components.ros.write(DOCKER_FILE, version) 69 | components.ros.entry_point() 70 | 71 | if 'icub' in base.keys(): 72 | import components.icub 73 | version = base['icub'] 74 | components.icub.write(DOCKER_FILE, version) 75 | 76 | if 'cmake_update' in base.keys(): 77 | import components.cmake_update 78 | version = base['cmake_update'] 79 | components.cmake_update.write(DOCKER_FILE, version) 80 | 81 | if 'matlab' in yaml_file.keys(): 82 | import components.matlab 83 | host_path = yaml_file['matlab']['host_path'] 84 | components.matlab.write(DOCKER_FILE, host_path) 85 | 86 | if 'repo' in yaml_file.keys(): 87 | import components.repo 88 | repo_list = yaml_file['repo'] 89 | components.repo.write(DOCKER_FILE, repo_list) 90 | 91 | if 'apt' in yaml_file.keys(): 92 | import components.apt 93 | package_list = yaml_file['apt'] 94 | components.apt.write(DOCKER_FILE, package_list) 95 | 96 | if 'pip3' in yaml_file.keys(): 97 | import components.pip3 98 | package_list = yaml_file['pip3'] 99 | components.pip3.write(DOCKER_FILE, package_list) 100 | 101 | if 'pip' in yaml_file.keys(): 102 | import components.pip 103 | package_list = yaml_file['pip'] 104 | components.pip.write(DOCKER_FILE, package_list) 105 | 106 | if 'source' in yaml_file.keys(): 107 | import components.source 108 | package_list = yaml_file['source'] 109 | components.source.write(DOCKER_FILE, package_list) 110 | 111 | import components.copy 112 | components.copy.write(DOCKER_FILE, name) 113 | 114 | if 'build' in yaml_file.keys(): 115 | build_method = yaml_file['build'] 116 | if build_method == 'catkin_make' or build_method == 'catkin_build': 117 | import components.catkin 118 | components.catkin.write(DOCKER_FILE, name, build_method) 119 | elif build_method == 'cmake': 120 | if 'cmake_options' in yaml_file.keys(): 121 | cmake_options = yaml_file['cmake_options'] 122 | else: 123 | cmake_options = '' 124 | import components.cmake 125 | components.cmake.write(DOCKER_FILE, name, cmake_options) 126 | else: 127 | print('Unknown build method: %s, supported methods: %s' % (build_method, ['catkin_make', 'catkin_build', 'cmake'])) 128 | 129 | if 'custom' in yaml_file.keys(): 130 | import components.custom 131 | custom_commands = yaml_file['custom'] 132 | components.custom.write(DOCKER_FILE, custom_commands) 133 | 134 | import components.tail 135 | components.tail.write(DOCKER_FILE, name) 136 | 137 | except KeyError as e: 138 | print("Key %s not found in file %s" % (e, PROJECT_FILE) ) 139 | sys.exit(1) 140 | 141 | BUILD_SCRIPT = """#!/bin/sh 142 | docker build -f %s -t %s .""" 143 | 144 | def write_build_script(yaml_file): 145 | with open(BUILD_FILE, "w") as scriptfile: 146 | scriptfile.write(BUILD_SCRIPT % (DOCKER_FILE, yaml_file['name'])) 147 | os.chmod(BUILD_FILE, 0o755) 148 | 149 | RUN_SCRIPT = """#!/bin/sh 150 | docker run --rm %s %s -p 8888:8888 "$@" %s """ 151 | 152 | RUN_SCRIPT_NVIDIA = """#!/bin/sh 153 | XAUTH=/tmp/.docker.xauth 154 | if [ ! -f $XAUTH ] 155 | then 156 | xauth_list=$(xauth nlist :0 | sed -e 's/^..../ffff/') 157 | if [ ! -z "$xauth_list" ] 158 | then 159 | echo $xauth_list | xauth -f $XAUTH nmerge - 160 | else 161 | touch $XAUTH 162 | fi 163 | chmod a+r $XAUTH 164 | fi 165 | docker run --rm \\ 166 | --env="DISPLAY" \\ 167 | --env="QT_X11_NO_MITSHM=1" \\ 168 | --volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" \\ 169 | --env="XAUTHORITY=$XAUTH" \\ 170 | --volume="$XAUTH:$XAUTH" \\ 171 | --runtime=nvidia \\ 172 | %s %s -p 8888:8888 "$@" %s """ 173 | 174 | def write_run_script(yaml_file): 175 | vol_string = "" 176 | if 'volume' in yaml_file.keys(): 177 | for v in yaml_file['volume']: 178 | vol_string += '--volume="%s:%s:%s" ' % (v['host_path'], v['container_path'], v['options']) 179 | if 'matlab' in yaml_file.keys(): 180 | host_path = yaml_file['matlab']['host_path'] 181 | mac_address = yaml_file['matlab']['mac_address'] 182 | mat_string = "-v %s:%s -v /usr/local/lib/python3.5/dist-packages/matlab:/usr/local/lib/python3.5/dist-packages/matlab --mac-address=%s" % (host_path, host_path, mac_address) 183 | else: 184 | mat_string = "" 185 | with open(RUN_FILE, "w") as scriptfile: 186 | if 'opengl' in yaml_file['base'].keys() or 'cuda' in yaml_file['base'].keys(): 187 | scriptfile.write(RUN_SCRIPT_NVIDIA % (vol_string, mat_string, yaml_file['name'])) 188 | else: 189 | scriptfile.write(RUN_SCRIPT % (vol_string, mat_string, yaml_file['name'])) 190 | os.chmod(RUN_FILE, 0o755) 191 | 192 | DOCKER_IGNORE_FILE = ".dockerignore" 193 | 194 | DOCKER_IGNORE_CONTENTS = """README.md 195 | %s 196 | %s 197 | %s 198 | %s 199 | %s 200 | """ % (DOCKER_IGNORE_FILE, PROJECT_FILE, DOCKER_FILE, BUILD_FILE, RUN_FILE) 201 | 202 | def write_docker_ignore(): 203 | with open(DOCKER_IGNORE_FILE, "w") as ignorefile: 204 | ignorefile.write(DOCKER_IGNORE_CONTENTS) 205 | 206 | NOTEBOOK_TAIL = """ 207 | "metadata": { 208 | "kernelspec": { 209 | "display_name": "Bash", 210 | "language": "bash", 211 | "name": "bash" 212 | }, 213 | "language_info": { 214 | "codemirror_mode": "shell", 215 | "file_extension": ".sh", 216 | "mimetype": "text/x-sh", 217 | "name": "bash" 218 | } 219 | }, 220 | "nbformat": 4, 221 | "nbformat_minor": 2 222 | } 223 | """ 224 | 225 | def write_readme_notebook(): 226 | if os.path.isfile("README.md"): 227 | os.system("notedown README.md | head -n -4 > README.ipynb") 228 | with open("README.ipynb", "a") as myfile: 229 | myfile.write(NOTEBOOK_TAIL) 230 | 231 | 232 | if __name__ == "__main__": 233 | main() 234 | -------------------------------------------------------------------------------- /ui_form.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobInLabUJI/ROSLab/3a5047a204989dea108cb163fd1ca7516ec2f5c9/ui_form.png --------------------------------------------------------------------------------