|
|
@@ -1,4 +1,5 @@
|
|
|
import os
|
|
|
+import shutil
|
|
|
import tempfile
|
|
|
|
|
|
import docker
|
|
|
@@ -48,7 +49,9 @@ def generate_dockerfile_for_eventstream_runtime(
|
|
|
else:
|
|
|
dockerfile_content = (
|
|
|
f'FROM {base_image}\n'
|
|
|
+ # FIXME: make this more generic / cross-platform
|
|
|
'RUN apt update && apt install -y wget sudo\n'
|
|
|
+ 'RUN apt-get update && apt-get install -y libgl1-mesa-glx\n' # Extra dependency for OpenCV
|
|
|
'RUN mkdir -p /opendevin && mkdir -p /opendevin/logs && chmod 777 /opendevin/logs\n'
|
|
|
'RUN echo "" > /opendevin/bash.bashrc\n'
|
|
|
'RUN if [ ! -d /opendevin/miniforge3 ]; then \\\n'
|
|
|
@@ -58,8 +61,8 @@ def generate_dockerfile_for_eventstream_runtime(
|
|
|
' chmod -R g+w /opendevin/miniforge3 && \\\n'
|
|
|
' bash -c ". /opendevin/miniforge3/etc/profile.d/conda.sh && conda config --set changeps1 False && conda config --append channels conda-forge"; \\\n'
|
|
|
' fi\n'
|
|
|
- 'RUN /opendevin/miniforge3/bin/mamba install python=3.11\n'
|
|
|
- 'RUN /opendevin/miniforge3/bin/mamba install conda-forge::poetry\n'
|
|
|
+ 'RUN /opendevin/miniforge3/bin/mamba install python=3.11 -y\n'
|
|
|
+ 'RUN /opendevin/miniforge3/bin/mamba install conda-forge::poetry -y\n'
|
|
|
)
|
|
|
|
|
|
tarball_path = create_project_source_dist()
|
|
|
@@ -67,7 +70,9 @@ def generate_dockerfile_for_eventstream_runtime(
|
|
|
filename = filename.removesuffix('.tar.gz')
|
|
|
|
|
|
# move the tarball to temp_dir
|
|
|
- os.rename(tarball_path, os.path.join(temp_dir, 'project.tar.gz'))
|
|
|
+ _res = shutil.copy(tarball_path, os.path.join(temp_dir, 'project.tar.gz'))
|
|
|
+ if _res:
|
|
|
+ os.remove(tarball_path)
|
|
|
logger.info(
|
|
|
f'Source distribution moved to {os.path.join(temp_dir, "project.tar.gz")}'
|
|
|
)
|
|
|
@@ -88,6 +93,8 @@ def generate_dockerfile_for_eventstream_runtime(
|
|
|
'RUN cd /opendevin/code && '
|
|
|
'/opendevin/miniforge3/bin/mamba run -n base poetry env use python3.11 && '
|
|
|
'/opendevin/miniforge3/bin/mamba run -n base poetry install\n'
|
|
|
+ # for browser (update if needed)
|
|
|
+ 'RUN apt-get update && cd /opendevin/code && /opendevin/miniforge3/bin/mamba run -n base poetry run playwright install --with-deps chromium\n'
|
|
|
)
|
|
|
return dockerfile_content
|
|
|
|
|
|
@@ -162,10 +169,14 @@ def _build_sandbox_image(
|
|
|
raise e
|
|
|
|
|
|
|
|
|
-def _get_new_image_name(base_image: str, is_eventstream_runtime: bool) -> str:
|
|
|
+def _get_new_image_name(
|
|
|
+ base_image: str, is_eventstream_runtime: bool, dev_mode: bool = False
|
|
|
+) -> str:
|
|
|
prefix = 'od_sandbox'
|
|
|
if is_eventstream_runtime:
|
|
|
prefix = 'od_eventstream_runtime'
|
|
|
+ if dev_mode:
|
|
|
+ prefix += '_dev'
|
|
|
if ':' not in base_image:
|
|
|
base_image = base_image + ':latest'
|
|
|
|
|
|
@@ -202,10 +213,25 @@ def get_od_sandbox_image(
|
|
|
skip_init = False
|
|
|
if image_exists:
|
|
|
if is_eventstream_runtime:
|
|
|
- skip_init = True
|
|
|
+ # An eventstream runtime image is already built for the base image (with poetry and dev dependencies)
|
|
|
+ # but it might not contain the latest version of the source code and dependencies.
|
|
|
+ # So we need to build a new (dev) image with the latest source code and dependencies.
|
|
|
+ # FIXME: In production, we should just build once (since the source code will not change)
|
|
|
base_image = new_image_name
|
|
|
+ new_image_name = _get_new_image_name(
|
|
|
+ base_image, is_eventstream_runtime, dev_mode=True
|
|
|
+ )
|
|
|
+
|
|
|
+ # Delete the existing image named `new_image_name` if any
|
|
|
+ images = docker_client.images.list()
|
|
|
+ for image in images:
|
|
|
+ if new_image_name in image.tags:
|
|
|
+ docker_client.images.remove(image.id, force=True)
|
|
|
+
|
|
|
+ # We will reuse the existing image but will update the source code in it.
|
|
|
+ skip_init = True
|
|
|
logger.info(
|
|
|
- f'Reusing existing od_sandbox image [{new_image_name}] but will update the source code.'
|
|
|
+ f'Reusing existing od_sandbox image [{base_image}] but will update the source code into [{new_image_name}]'
|
|
|
)
|
|
|
else:
|
|
|
return new_image_name
|