forked from PKU-Alignment/omnisafe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
86 lines (66 loc) · 2.67 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# Dockerfile for OmniSafe
#
# $ docker build --target base --tag omnisafe:latest .
#
# or
#
# $ docker build --target devel --tag omnisafe-devel:latest .
#
ARG cuda_docker_tag="11.7.1-cudnn8-devel-ubuntu22.04"
FROM nvidia/cuda:"${cuda_docker_tag}" AS builder
ENV DEBIAN_FRONTEND=noninteractive
SHELL ["/bin/bash", "-c"]
# Install packages
RUN apt-get update && \
apt-get install -y sudo ca-certificates openssl \
git ssh build-essential gcc g++ cmake make \
python3-dev python3-venv python3-opengl libosmesa6-dev && \
rm -rf /var/lib/apt/lists/*
ENV LANG C.UTF-8
ENV MUJOCO_GL osmesa
ENV PYOPENGL_PLATFORM osmesa
ENV CC=gcc CXX=g++
# Add a new user
RUN useradd -m -s /bin/bash omnisafe && \
echo "omnisafe ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
USER omnisafe
RUN echo "export PS1='[\[\e[1;33m\]\u\[\e[0m\]:\[\e[1;35m\]\w\[\e[0m\]]\$ '" >> ~/.bashrc
# Setup virtual environment
RUN /usr/bin/python3 -m venv --upgrade-deps ~/venv && rm -rf ~/.pip/cache
RUN PIP_EXTRA_INDEX_URL="https://download.pytorch.org/whl/cu$(echo "${CUDA_VERSION}" | cut -d'.' -f-2 | tr -d '.')" && \
echo "export PIP_EXTRA_INDEX_URL='${PIP_EXTRA_INDEX_URL}'" >> ~/venv/bin/activate && \
echo "source /home/omnisafe/venv/bin/activate" >> ~/.bashrc
# Install dependencies
WORKDIR /home/omnisafe/omnisafe
COPY --chown=omnisafe requirements.txt requirements.txt
RUN source ~/venv/bin/activate && \
python -m pip install -r requirements.txt && \
rm -rf ~/.pip/cache ~/.cache/pip
####################################################################################################
FROM builder AS devel-builder
# Install extra dependencies
RUN sudo apt-get update && \
sudo apt-get install -y golang && \
sudo chown -R "$(whoami):$(whoami)" "$(realpath /usr/lib/go)" && \
sudo rm -rf /var/lib/apt/lists/*
# Install addlicense
ENV GOROOT="/usr/lib/go"
ENV GOBIN="${GOROOT}/bin"
ENV PATH="${GOBIN}:${PATH}"
RUN go install github.com/google/addlicense@latest
# Install extra PyPI dependencies
COPY --chown=omnisafe tests/requirements.txt tests/requirements.txt
RUN source ~/venv/bin/activate && \
python -m pip install -r tests/requirements.txt && \
rm -rf ~/.pip/cache ~/.cache/pip
####################################################################################################
FROM builder AS base
COPY --chown=omnisafe . .
# Install omnisafe
RUN source ~/venv/bin/activate && \
make install-editable && \
rm -rf .eggs *.egg-info ~/.pip/cache ~/.cache/pip
ENTRYPOINT [ "/bin/bash", "--login" ]
####################################################################################################
FROM devel-builder AS devel
COPY --from=base /home/omnisafe/omnisafe .