-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdockerfiles.py
More file actions
303 lines (236 loc) · 7.16 KB
/
dockerfiles.py
File metadata and controls
303 lines (236 loc) · 7.16 KB
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
from functools import partial
# IF you change the base image, you need to rebuild all images (run with --force_rebuild)
_DOCKERFILE_BASE = r"""
FROM --platform={platform} ubuntu:22.04
ARG DEBIAN_FRONTEND=noninteractive
ENV TZ=Etc/UTC
RUN apt update && apt install -y \
wget \
git \
build-essential \
libffi-dev \
libtiff-dev \
python3 \
python3-pip \
python-is-python3 \
jq \
curl \
locales \
locales-all \
tzdata \
&& rm -rf /var/lib/apt/lists/*
# Download and install conda
RUN wget 'https://repo.anaconda.com/miniconda/Miniconda3-py311_23.11.0-2-Linux-{conda_arch}.sh' -O miniconda.sh \
&& bash miniconda.sh -b -p /opt/miniconda3
# Add conda to PATH
ENV PATH=/opt/miniconda3/bin:$PATH
# Add conda to shell startup scripts like .bashrc (DO NOT REMOVE THIS)
RUN conda init --all
RUN conda config --append channels conda-forge
RUN adduser --disabled-password --gecos 'dog' nonroot
"""
_DOCKERFILE_BASE_JAVA = r"""
FROM --platform={platform} ubuntu:22.04
ARG DEBIAN_FRONTEND=noninteractive
ENV TZ=Etc/UTC
# 更新包列表并安装必要的软件包
RUN apt update && apt install -y \
wget \
git \
build-essential \
curl \
unzip \
zip \
ca-certificates \
locales \
locales-all \
tzdata \
&& rm -rf /var/lib/apt/lists/*
RUN adduser --disabled-password --gecos 'dogs' nonroot
"""
_DOCKERFILE_BASE_JS = r"""
FROM --platform={platform} ubuntu:22.04
ARG DEBIAN_FRONTEND=noninteractive
ENV TZ=Etc/UTC
# 更新包列表并安装必要的软件包
RUN apt update && apt install -y \
wget \
git \
build-essential \
libffi-dev \
libtiff-dev \
python3 \
python3-pip \
python-is-python3 \
jq \
curl \
locales \
locales-all \
tzdata \
&& rm -rf /var/lib/apt/lists/*
RUN curl https://get.volta.sh | bash
ENV VOLTA_HOME=/root/.volta
ENV PATH=$VOLTA_HOME/bin:$PATH
RUN adduser --disabled-password --gecos 'dog' nonroot
"""
_DOCKERFILE_BASE_JS_20 = r"""
FROM --platform={platform} ubuntu:20.04
ARG DEBIAN_FRONTEND=noninteractive
ENV TZ=Etc/UTC
# 更新包列表并安装必要的软件包
RUN apt update && apt install -y \
wget \
git \
build-essential \
libffi-dev \
libtiff-dev \
python3 \
python3-pip \
python-is-python3 \
jq \
curl \
locales \
locales-all \
tzdata \
&& rm -rf /var/lib/apt/lists/*
RUN curl https://get.volta.sh | bash
ENV VOLTA_HOME=/root/.volta
ENV PATH=$VOLTA_HOME/bin:$PATH
RUN adduser --disabled-password --gecos 'dog' nonroot
"""
_DOCKERFILE_BASE_16 = r"""
FROM --platform=linux/x86_64 ubuntu:{ubuntu_version}.04
ARG DEBIAN_FRONTEND=noninteractive
ENV TZ=Etc/UTC
RUN apt update && apt install -y \
wget \
git \
build-essential \
libffi-dev \
libtiff-dev \
python3 \
python3-pip \
jq \
curl \
locales \
locales-all \
tzdata \
&& rm -rf /var/lib/apt/lists/*
# Download and install conda
RUN wget 'https://repo.anaconda.com/miniconda/Miniconda3-py311_23.11.0-2-Linux-x86_64.sh' -O miniconda.sh \
&& bash miniconda.sh -b -p /opt/miniconda3
# Add conda to PATH
ENV PATH=/opt/miniconda3/bin:$PATH
# Add conda to shell startup scripts like .bashrc (DO NOT REMOVE THIS)
RUN conda init --all
RUN conda config --append channels conda-forge
RUN adduser --disabled-password --gecos 'dog' nonroot
"""
_DOCKERFILE_BASE_ = r"""
FROM --platform=linux/x86_64 ubuntu:{ubuntu_version}.04
ARG DEBIAN_FRONTEND=noninteractive
ENV TZ=Etc/UTC
RUN apt update && apt install -y \
wget \
git \
build-essential \
libffi-dev \
libtiff-dev \
python3 \
python3-pip \
python-is-python3 \
jq \
curl \
locales \
locales-all \
tzdata \
&& rm -rf /var/lib/apt/lists/*
# Download and install conda
RUN wget 'https://repo.anaconda.com/miniconda/Miniconda3-py311_23.11.0-2-Linux-x86_64.sh' -O miniconda.sh \
&& bash miniconda.sh -b -p /opt/miniconda3
# Add conda to PATH
ENV PATH=/opt/miniconda3/bin:$PATH
# Add conda to shell startup scripts like .bashrc (DO NOT REMOVE THIS)
RUN conda init --all
RUN conda config --append channels conda-forge
RUN adduser --disabled-password --gecos 'dog' nonroot
"""
_DOCKERFILE_ENV = r"""FROM --platform={platform} sweb.base.{arch}:latest
COPY ./setup_env.sh /root/
RUN chmod +x /root/setup_env.sh
RUN /bin/bash -c "source ~/.bashrc && /root/setup_env.sh"
WORKDIR /testbed/
# Automatically activate the testbed environment
RUN echo "source /opt/miniconda3/etc/profile.d/conda.sh && conda activate testbed" > /root/.bashrc
"""
_DOCKERFILE_ENV_JS = r"""FROM --platform={platform} sweb.base.{arch}:latest
COPY ./setup_env.sh /root/
RUN chmod +x /root/setup_env.sh
RUN /bin/bash -c "source ~/.bashrc && /root/setup_env.sh"
WORKDIR /testbed/
# Automatically activate the testbed environment
"""
_DOCKERFILE_ENV_JAVA = r"""FROM --platform={platform} sweb.base.{arch}:latest
COPY ./setup_env.sh /root/
# 赋予脚本执行权限
RUN chmod +x /root/setup_env.sh
# 手动加载 SDKMAN 并运行 setup_env.sh
RUN /bin/bash /root/setup_env.sh
WORKDIR /testbed/
"""
# -c "source ~/.bashrc
_DOCKERFILE_INSTANCE = r"""FROM --platform={platform} {env_image_name}
COPY ./setup_repo.sh /root/
RUN /bin/bash /root/setup_repo.sh
WORKDIR /testbed/
"""
_DOCKERFILE_INSTANCE_JAVA = r"""FROM --platform={platform} {env_image_name}
COPY ./setup_repo.sh /root/
ENV JAVA_HOME="/root/.sdkman/candidates/java/current"
ENV PATH="$JAVA_HOME/bin:/root/.sdkman/candidates/maven/current/bin:${{PATH}}"
ENV PATH="/root/.sdkman/candidates/maven/current/bin:${{PATH}}"
RUN /bin/bash /root/setup_repo.sh
WORKDIR /testbed/
"""
_DOCKERFILE_INSTANCE_JAVA_GRADLE = r"""FROM --platform={platform} {env_image_name}
COPY ./setup_repo.sh /root/
ENV JAVA_HOME="/root/.sdkman/candidates/java/current"
ENV PATH="$JAVA_HOME/bin:/root/.sdkman/candidates/gradle/current/bin:${{PATH}}"
ENV PATH="/root/.sdkman/candidates/gradle/current/bin:${{PATH}}"
RUN /bin/bash /root/setup_repo.sh
WORKDIR /testbed/
"""
def get_dockerfile_base(platform, arch):
if arch == "arm64":
conda_arch = "aarch64"
elif 'js' in arch:
if 'ubuntu_20' in arch:
return _DOCKERFILE_BASE_JS_20.format(platform=platform)
else:
return _DOCKERFILE_BASE_JS.format(platform=platform)
elif 'java' in arch:
# if 'ubuntu_20' in arch:
# return _DOCKERFILE_BASE_JS_20.format(platform=platform)
# else:
return _DOCKERFILE_BASE_JAVA.format(platform=platform)
else:
if 'ubuntu_20' in arch:
return _DOCKERFILE_BASE_.format(ubuntu_version=20)
elif 'ubuntu_16' in arch:
return _DOCKERFILE_BASE_16.format(ubuntu_version=16)
conda_arch = arch
return _DOCKERFILE_BASE.format(platform=platform, conda_arch=conda_arch)
def get_dockerfile_env(platform, arch):
if 'js' in arch:
return _DOCKERFILE_ENV_JS.format(platform=platform, arch=arch)
elif 'java' in arch:
return _DOCKERFILE_ENV_JAVA.format(platform=platform, arch=arch)
else:
return _DOCKERFILE_ENV.format(platform=platform, arch=arch)
def get_dockerfile_instance(platform, env_image_name):
if 'gradle' in env_image_name:
return _DOCKERFILE_INSTANCE_JAVA_GRADLE.format(platform=platform, env_image_name=env_image_name)
elif 'java' in env_image_name:
return _DOCKERFILE_INSTANCE_JAVA.format(platform=platform, env_image_name=env_image_name)
else:
return _DOCKERFILE_INSTANCE.format(platform=platform, env_image_name=env_image_name)