1
1
import os
2
+ import shutil
2
3
import tempfile
3
4
4
5
import docker
@@ -48,7 +49,9 @@ def generate_dockerfile_for_eventstream_runtime(
48
49
else :
49
50
dockerfile_content = (
50
51
f'FROM { base_image } \n '
52
+ # FIXME: make this more generic / cross-platform
51
53
'RUN apt update && apt install -y wget sudo\n '
54
+ 'RUN apt-get update && apt-get install -y libgl1-mesa-glx\n ' # Extra dependency for OpenCV
52
55
'RUN mkdir -p /opendevin && mkdir -p /opendevin/logs && chmod 777 /opendevin/logs\n '
53
56
'RUN echo "" > /opendevin/bash.bashrc\n '
54
57
'RUN if [ ! -d /opendevin/miniforge3 ]; then \\ \n '
@@ -58,16 +61,18 @@ def generate_dockerfile_for_eventstream_runtime(
58
61
' chmod -R g+w /opendevin/miniforge3 && \\ \n '
59
62
' bash -c ". /opendevin/miniforge3/etc/profile.d/conda.sh && conda config --set changeps1 False && conda config --append channels conda-forge"; \\ \n '
60
63
' fi\n '
61
- 'RUN /opendevin/miniforge3/bin/mamba install python=3.11\n '
62
- 'RUN /opendevin/miniforge3/bin/mamba install conda-forge::poetry\n '
64
+ 'RUN /opendevin/miniforge3/bin/mamba install python=3.11 -y \n '
65
+ 'RUN /opendevin/miniforge3/bin/mamba install conda-forge::poetry -y \n '
63
66
)
64
67
65
68
tarball_path = create_project_source_dist ()
66
69
filename = os .path .basename (tarball_path )
67
70
filename = filename .removesuffix ('.tar.gz' )
68
71
69
72
# move the tarball to temp_dir
70
- os .rename (tarball_path , os .path .join (temp_dir , 'project.tar.gz' ))
73
+ _res = shutil .copy (tarball_path , os .path .join (temp_dir , 'project.tar.gz' ))
74
+ if _res :
75
+ os .remove (tarball_path )
71
76
logger .info (
72
77
f'Source distribution moved to { os .path .join (temp_dir , "project.tar.gz" )} '
73
78
)
@@ -88,6 +93,8 @@ def generate_dockerfile_for_eventstream_runtime(
88
93
'RUN cd /opendevin/code && '
89
94
'/opendevin/miniforge3/bin/mamba run -n base poetry env use python3.11 && '
90
95
'/opendevin/miniforge3/bin/mamba run -n base poetry install\n '
96
+ # for browser (update if needed)
97
+ 'RUN apt-get update && cd /opendevin/code && /opendevin/miniforge3/bin/mamba run -n base poetry run playwright install --with-deps chromium\n '
91
98
)
92
99
return dockerfile_content
93
100
@@ -162,10 +169,14 @@ def _build_sandbox_image(
162
169
raise e
163
170
164
171
165
- def _get_new_image_name (base_image : str , is_eventstream_runtime : bool ) -> str :
172
+ def _get_new_image_name (
173
+ base_image : str , is_eventstream_runtime : bool , dev_mode : bool = False
174
+ ) -> str :
166
175
prefix = 'od_sandbox'
167
176
if is_eventstream_runtime :
168
177
prefix = 'od_eventstream_runtime'
178
+ if dev_mode :
179
+ prefix += '_dev'
169
180
if ':' not in base_image :
170
181
base_image = base_image + ':latest'
171
182
@@ -202,10 +213,25 @@ def get_od_sandbox_image(
202
213
skip_init = False
203
214
if image_exists :
204
215
if is_eventstream_runtime :
205
- skip_init = True
216
+ # An eventstream runtime image is already built for the base image (with poetry and dev dependencies)
217
+ # but it might not contain the latest version of the source code and dependencies.
218
+ # So we need to build a new (dev) image with the latest source code and dependencies.
219
+ # FIXME: In production, we should just build once (since the source code will not change)
206
220
base_image = new_image_name
221
+ new_image_name = _get_new_image_name (
222
+ base_image , is_eventstream_runtime , dev_mode = True
223
+ )
224
+
225
+ # Delete the existing image named `new_image_name` if any
226
+ images = docker_client .images .list ()
227
+ for image in images :
228
+ if new_image_name in image .tags :
229
+ docker_client .images .remove (image .id , force = True )
230
+
231
+ # We will reuse the existing image but will update the source code in it.
232
+ skip_init = True
207
233
logger .info (
208
- f'Reusing existing od_sandbox image [{ new_image_name } ] but will update the source code. '
234
+ f'Reusing existing od_sandbox image [{ base_image } ] but will update the source code into [ { new_image_name } ] '
209
235
)
210
236
else :
211
237
return new_image_name
0 commit comments