forked from agiachris/STAP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile.train
143 lines (118 loc) · 3.65 KB
/
Dockerfile.train
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
ARG MODE=root
# We use the if else method as described here: https://stackoverflow.com/a/60820156/13397059
FROM ubuntu:20.04 as base
ARG DEBIAN_FRONTEND=noninteractive
SHELL ["/bin/bash", "--login", "-c"]
# setup environment
ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8
RUN apt-get update --fix-missing && \
apt-get install --no-install-recommends -y \
tzdata \
dirmngr \
gnupg2 \
psmisc \
python3 \
python3-pip \
python-is-python3 \
mpich \
python3-tk \
python3-dev \
libosmesa6-dev \
libgl1-mesa-glx \
libglfw3 \
apt-utils dialog 2>&1 \
git \
iproute2 \
procps \
lsb-release \
nano \
libopenmpi-dev \
swig \
wget \
ca-certificates \
curl \
git \
bzip2 \
sudo \
cmake \
build-essential \
tar \
unzip \
curl \
g++ \
gcc-9 \
clang \
libgtest-dev \
libgmock-dev \
bc \
tmux
RUN apt-get upgrade libstdc++6 -y
RUN apt-get dist-upgrade
RUN apt-get autoremove -y && \
apt-get clean -y && \
rm -rf /var/lib/apt/lists/*
ENV DEBIAN_FRONTEND=dialog
# Install python dependencies
COPY requirements.txt .
RUN pip install --upgrade pip && \
pip install -r requirements.txt
# Pull and install eigen
RUN curl -LJO https://gitlab.com/libeigen/eigen/-/archive/3.4.0/eigen-3.4.0.tar.bz2 && \
tar -xvf eigen-3.4.0.tar.bz2 && \
rm eigen-3.4.0.tar.bz2
WORKDIR /eigen-3.4.0/build
RUN cmake .. && make install
#-------------------------------------------------------------------------------------------------------------
# User docker
#-------------------------------------------------------------------------------------------------------------
FROM base as branch-user
ARG USERNAME=robot
ARG USER_UID=1000
ARG USER_GID=$USER_UID
RUN groupadd --gid $USER_GID $USERNAME && \
useradd --create-home --no-log-init --uid $USER_UID --gid $USER_GID $USERNAME
# ARG is scoped -> has to be set as environment variable
ENV HOME_PATH=/home/$USERNAME
USER $USERNAME
#-------------------------------------------------------------------------------------------------------------
# Root docker
#-------------------------------------------------------------------------------------------------------------
FROM base as branch-root
ARG USERNAME=root
ENV HOME_PATH=/root
#-------------------------------------------------------------------------------------------------------------
# Final docker
#-------------------------------------------------------------------------------------------------------------
FROM branch-${MODE} AS final
WORKDIR $HOME_PATH
ARG USERNAME=root
WORKDIR $HOME_PATH
# Copy all required folders
COPY --chown=$USERNAME Pipfile pyproject.toml setup.cfg generate_primitive_dataset.py $HOME_PATH/
COPY --chown=$USERNAME configs/ $HOME_PATH/configs/
COPY --chown=$USERNAME scripts/ $HOME_PATH/scripts/
COPY --chown=$USERNAME stap/ $HOME_PATH/stap/
COPY --chown=$USERNAME third_party/ $HOME_PATH/third_party/
ENV STAP_PATH=$HOME_PATH
# Install python packages with root privileges
USER root
# Build SaRA shield
ENV CONDA_PREFIX="/usr/"
WORKDIR $HOME_PATH/third_party/sara-shield
RUN rm -rf build && \
rm -rf safety_shield/build
RUN export EIGEN3_INCLUDE_DIR="/eigen-3.4.0" && \
python setup.py install
WORKDIR $HOME_PATH
RUN pip install .
WORKDIR $HOME_PATH/third_party/scod-regression
RUN rm -rf scod-regression.egg-info && \
rm -rf build
RUN pip install .
WORKDIR $HOME_PATH
# Switch back to USER mode
USER $USERNAME
SHELL ["/bin/bash", "-c"]
ENTRYPOINT ["/bin/bash", "-c"]
CMD ["/bin/bash"]