-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
166 lines (119 loc) · 3.76 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
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
ARG version=standard
ARG build=0
##########################
####### Base Image #######
##########################
FROM nvidia/cuda:12.5.1-devel-ubuntu22.04 AS base
ARG USERNAME=dev
ARG CODE_LOCATION=/src/DSI-Bench
# install basic packages
RUN apt update -y &&\
apt install -y \
vim \
htop \
git \
tmux \
wget \
binutils \
build-essential \
g++ && \
apt clean && \
rm -rf /var/lib/apt/lists/*
# set password of root to root
RUN echo 'root:root' | chpasswd
# create user dev
RUN groupadd ${USERNAME}
RUN useradd -m -g ${USERNAME} -p admin -s /bin/bash ${USERNAME}
# create directory to install mamba
RUN mkdir /mamba
RUN chown ${USERNAME}:${USERNAME} /mamba
USER ${USERNAME}
# install mamba
RUN wget -P /tmp/ https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh
RUN echo "\nyes\n/mamba/miniforge3\n" | /bin/bash /tmp/Miniforge3-$(uname)-$(uname -m).sh
RUN rm /tmp/Miniforge3-$(uname)-$(uname -m).sh
ENV PATH="$PATH:/mamba/miniforge3/bin"
RUN mamba init
# add channels
RUN conda config --add channels conda-forge
RUN mamba update --all -y && mamba clean --all --force-pkgs-dirs -y
# copy repository
USER root
COPY . ${CODE_LOCATION}/
RUN rm -rf ${CODE_LOCATION}/.git
RUN chown -R ${USERNAME}:${USERNAME} ${CODE_LOCATION}
##########################
###### Naked Image #######
##########################
FROM base as build-0
ARG USERNAME=dev
# deactivate autoactivation of base image
USER ${USERNAME}
SHELL ["mamba", "run", "-n", "base", "/bin/bash", "-c"]
RUN conda config --set auto_activate_base false
SHELL ["/bin/bash", "-c"]
USER root
RUN mamba init
SHELL ["/mamba/miniforge3/bin/mamba", "run", "-n", "base", "/bin/bash", "-c"]
RUN conda config --set auto_activate_base false
##########################
###### Built Image #######
##########################
FROM base as build-1
ARG USERNAME=dev
# install environment
USER ${USERNAME}
RUN mamba env create -n benchmark -f ${CODE_LOCATION}/environment/environment.yml
SHELL ["mamba", "run", "-n", "benchmark", "/bin/bash", "-c"]
RUN pip install --extra-index-url https://pypi.nvidia.com --upgrade nvidia-dali-tf-plugin-cuda120
RUN pip install git+https://github.com/facebookresearch/[email protected]
# install the packages of the project
WORKDIR ${CODE_LOCATION}
RUN poetry install
WORKDIR /
SHELL ["/bin/bash", "-c"]
RUN mamba clean -aqy
# deactivate autoactivation of base image
SHELL ["mamba", "run", "-n", "base", "/bin/bash", "-c"]
RUN conda config --set auto_activate_base false
SHELL ["/bin/bash", "-c"]
USER root
RUN mamba init
SHELL ["/mamba/miniforge3/bin/mamba", "run", "-n", "base", "/bin/bash", "-c"]
RUN conda config --set auto_activate_base false
SHELL ["/bin/bash", "-c"]
##########################
##### Standard Image #####
##########################
FROM build-${build} as version-standard
ARG USERNAME=dev
WORKDIR ${CODE_LOCATION}
USER ${USERNAME}
CMD ["/bin/bash"]
##########################
###### Runai Image #######
##########################
FROM build-${build} as version-runai
ARG USERNAME=dev
USER root
SHELL ["/bin/sh", "-c"]
# change home directory to /myhome
RUN usermod -d /myhome ${USERNAME}
# install ssh
RUN apt update -y &&\
apt install -y \
openssh-server & \
apt clean && \
rm -rf /var/lib/apt/lists/*
# ssh configuration
RUN mkdir /var/run/sshd
RUN echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config
RUN wget -O /etc/pam.d/sshd http://exampleconfig.com/static/raw/openssh/debian9/etc/pam.d/sshd
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
EXPOSE 22
# start ssh daemon
CMD ["/usr/sbin/sshd", "-D"]
##########################
###### Final Image #######
##########################
FROM version-${version} AS final