|
| 1 | +FROM nvidia/cuda:12.6.3-devel-ubuntu22.04 |
| 2 | + |
| 3 | +# Prevent interactive prompts during package installation |
| 4 | +ENV DEBIAN_FRONTEND=noninteractive |
| 5 | + |
| 6 | +ARG DEVICE_TYPE=CPU |
| 7 | + |
| 8 | +# Install system dependencies |
| 9 | +RUN apt-get update && apt-get install -y --no-install-recommends \ |
| 10 | + python3.11 \ |
| 11 | + python3-pip \ |
| 12 | + python3.11-venv \ |
| 13 | + python3.11-dev \ |
| 14 | + bash-completion \ |
| 15 | + build-essential \ |
| 16 | + curl \ |
| 17 | + cmake \ |
| 18 | + git \ |
| 19 | + ssh \ |
| 20 | + sudo \ |
| 21 | + mesa-utils \ |
| 22 | + wget \ |
| 23 | + htop \ |
| 24 | + tmux \ |
| 25 | + nano \ |
| 26 | + && rm -rf /var/lib/apt/lists/* && apt-get clean |
| 27 | + |
| 28 | +# Create symbolic links for python |
| 29 | +RUN ln -sf /usr/bin/python3.11 /usr/bin/python \ |
| 30 | + && ln -sf /usr/bin/python3.11 /usr/bin/python3 |
| 31 | + |
| 32 | +# Create non-root user |
| 33 | +ARG USERNAME=vscode |
| 34 | +ARG USER_UID=1000 |
| 35 | +ARG USER_GID=$USER_UID |
| 36 | + |
| 37 | +RUN groupadd --gid $USER_GID $USERNAME \ |
| 38 | + && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME |
| 39 | + |
| 40 | +# Set environment variables for CUDA |
| 41 | +ENV PATH="/usr/local/cuda-12.0/bin:${PATH}" |
| 42 | +ENV LD_LIBRARY_PATH="/usr/local/cuda-12.0/lib64:${LD_LIBRARY_PATH}" |
| 43 | + |
| 44 | +ENV NVIDIA_VISIBLE_DEVICES ${NVIDIA_VISIBLE_DEVICES:-all} |
| 45 | +ENV NVIDIA_DRIVER_CAPABILITIES ${NVIDIA_DRIVER_CAPABILITIES:+$NVIDIA_DRIVER_CAPABILITIES,}graphics |
| 46 | + |
| 47 | +# Create and set proper permissions for workspace directory |
| 48 | +RUN mkdir -p /workspace && \ |
| 49 | + chmod -R 755 /workspace && \ |
| 50 | + chown -R $USERNAME:$USERNAME /workspace |
| 51 | + |
| 52 | +# Install Acados |
| 53 | +# Acados Part I: |
| 54 | +# Set the acados version. |
| 55 | +ARG TERA_RENDERER_VERSION=v0.0.34 |
| 56 | +# Set the acados installation directory, which must be consistent with the acados_template path set in pyproject.toml. |
| 57 | +ARG ACADOS_INSTALL_DIR=/opt |
| 58 | + |
| 59 | +# Acados Part II: |
| 60 | +# Install acados dependencies. |
| 61 | +# See: https://docs.acados.org/installation/#id1 |
| 62 | +# Clone acados repository and its submodules. |
| 63 | +WORKDIR $ACADOS_INSTALL_DIR |
| 64 | +RUN git config --global http.postBuffer 524288000 |
| 65 | +# NOTE: instead of blindly copying from GitHub, we should use a specific release tag. Use one of the following commands: |
| 66 | +# RUN git clone -b v0.4.3 --single-branch --depth=1 https://github.com/acados/acados.git |
| 67 | +# RUN git clone https://github.com/acados/acados.git && cd acados && git fetch --tags && git checkout tags/v0.4.3 |
| 68 | +RUN git clone --branch v0.5.0 --depth 1 https://github.com/acados/acados.git $ACADOS_INSTALL_DIR/acados |
| 69 | +WORKDIR $ACADOS_INSTALL_DIR/acados |
| 70 | +RUN git submodule update --recursive --init |
| 71 | + |
| 72 | + |
| 73 | + |
| 74 | +# Change ownership of the acados directory |
| 75 | +RUN chown -R $USERNAME:$USERNAME $ACADOS_INSTALL_DIR/acados |
| 76 | + |
| 77 | +# Create virtual environment with proper permissions |
| 78 | +ENV VIRTUAL_ENV=/home/vscode/venv |
| 79 | +RUN python -m venv $VIRTUAL_ENV && \ |
| 80 | + chown -R $USERNAME:$USERNAME $VIRTUAL_ENV |
| 81 | +ENV PATH="$VIRTUAL_ENV/bin:$PATH" |
| 82 | + |
| 83 | + |
| 84 | +# Switch to non-root user |
| 85 | +USER $USERNAME |
| 86 | + |
| 87 | +# Install development tools |
| 88 | +RUN pip install --no-cache-dir ipykernel termcolor |
| 89 | +# required for crazyflow |
| 90 | +RUN pip install --upgrade pip setuptools wheel |
| 91 | + |
| 92 | + |
| 93 | +# Acados Part III: |
| 94 | +# Build and install acados. |
| 95 | +# See: https://docs.acados.org/installation/#cmake-recommended |
| 96 | +# https://github.com/acados/acados/blob/v0.3.6/CMakeLists.txt#L80-L94 |
| 97 | +RUN rm -rf build \ |
| 98 | + && mkdir build \ |
| 99 | + && cd build \ |
| 100 | + && cmake -DACADOS_WITH_QPOASES=ON .. \ |
| 101 | + && make install -j4 |
| 102 | + |
| 103 | +# To successfully render C code templates, download the tera_renderer binaries and make them executable. |
| 104 | +# See: https://docs.acados.org/python_interface/index.html#installation |
| 105 | +RUN cd bin \ |
| 106 | + && wget https://github.com/acados/tera_renderer/releases/download/${TERA_RENDERER_VERSION}/t_renderer-${TERA_RENDERER_VERSION}-linux \ |
| 107 | + && mv t_renderer-${TERA_RENDERER_VERSION}-linux t_renderer \ |
| 108 | + && chmod +x t_renderer |
| 109 | + |
| 110 | +# Acados Part IV: |
| 111 | +# Set acados environment variables. |
| 112 | +# See: https://docs.acados.org/python_interface/index.html#installation |
| 113 | +ENV ACADOS_INSTALL_DIR=$ACADOS_INSTALL_DIR |
| 114 | +ENV LD_LIBRARY_PATH="$ACADOS_INSTALL_DIR/acados/lib" |
| 115 | +ENV ACADOS_SOURCE_DIR="$ACADOS_INSTALL_DIR/acados" |
| 116 | +RUN pip install --no-cache-dir -e ${ACADOS_SOURCE_DIR}/interfaces/acados_template |
| 117 | + |
| 118 | + |
| 119 | +# Create a temporary directory for installation with proper permissions and install crazyflow |
| 120 | +WORKDIR /tmp/install |
| 121 | + |
| 122 | +# Copy pyproject.toml |
| 123 | +COPY --chown=$USERNAME:$USERNAME pyproject.toml . |
| 124 | + |
| 125 | +# Install dependencies as non-root user |
| 126 | +# Enable cpu-only and gpu versions of torch |
| 127 | +ENV PIP_EXTRA_INDEX_URL="https://download.pytorch.org/whl/cu126 https://download.pytorch.org/whl/cpu" |
| 128 | + |
| 129 | +# prevent OOM: https://docs.jax.dev/en/latest/gpu_memory_allocation.html#common-causes-of-oom-failures |
| 130 | +ENV XLA_PYTHON_CLIENT_PREALLOCATE=false |
| 131 | + |
| 132 | +RUN if [ "$DEVICE_TYPE" = "GPU" ]; then \ |
| 133 | + pip install --no-cache-dir .[test,gpu,pin]; \ |
| 134 | + else \ |
| 135 | + pip install --no-cache-dir .[test,cpu,pin]; \ |
| 136 | + fi |
| 137 | + |
| 138 | +# The below PYTHONPATHS are only required for the development repository, and for GitHub CI |
| 139 | +# TODO move to .env file |
| 140 | +ENV PYTHONPATH "${PYTHONPATH}:/workspaces/Advanced-Robot-Learning-and-Decision-Making-Programming-Exercises/src/exercise01" |
| 141 | +ENV PYTHONPATH "${PYTHONPATH}:/workspaces/Advanced-Robot-Learning-and-Decision-Making-Programming-Exercises/src/exercise02" |
| 142 | +ENV PYTHONPATH "${PYTHONPATH}:/workspaces/Advanced-Robot-Learning-and-Decision-Making-Programming-Exercises/src/exercise03" |
| 143 | +ENV PYTHONPATH "${PYTHONPATH}:/workspaces/Advanced-Robot-Learning-and-Decision-Making-Programming-Exercises/src/exercise04" |
| 144 | +ENV PYTHONPATH "${PYTHONPATH}:/workspaces/Advanced-Robot-Learning-and-Decision-Making-Programming-Exercises/src/exercise05" |
| 145 | +ENV PYTHONPATH "${PYTHONPATH}:/workspaces/Advanced-Robot-Learning-and-Decision-Making-Programming-Exercises/src/exercise06" |
| 146 | + |
| 147 | +# Set final working directory |
| 148 | +WORKDIR /workspace |
0 commit comments