Skip to content

Commit

Permalink
Make sure the docker layer is not stale
Browse files Browse the repository at this point in the history
  • Loading branch information
Domiii committed Dec 8, 2024
1 parent e35d1c7 commit 2f470e5
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 43 deletions.
70 changes: 35 additions & 35 deletions openhands/resolver/resolve_issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
import re
import shutil
import subprocess
from pathlib import Path
from typing import Any
from uuid import uuid4

from git import Repo
# from git import Repo
from termcolor import colored

from openhands.controller.state.state import State
Expand Down Expand Up @@ -209,38 +208,38 @@ async def complete_runtime(
return {'git_patch': git_patch}


def init_replay(replay_dir: str | Path) -> None:
replay_dir = Path(replay_dir)
# def init_replay(replay_dir: str | Path) -> None:
# replay_dir = Path(replay_dir)

if not replay_dir.exists():
replay_dir.mkdir(parents=True)
# if not replay_dir.exists():
# replay_dir.mkdir(parents=True)

repo_urls = [
'https://github.com/replayio-public/replayapi',
'https://github.com/replayio/devtools',
]
for repo_url in repo_urls:
repo_name = repo_url.split('/')[-1]
repo_path = replay_dir / repo_name
logger.info(f'[Replay] Preparing {repo_name} in {repo_path}')
if not repo_path.exists():
logger.info(
f'[Replay] Repository {repo_name} not found in {replay_dir}, cloning...'
)
Repo.clone_from(repo_url, str(repo_path))
# repo_urls = [
# 'https://github.com/replayio-public/replayapi',
# 'https://github.com/replayio/devtools',
# ]
# for repo_url in repo_urls:
# repo_name = repo_url.split('/')[-1]
# repo_path = replay_dir / repo_name
# logger.info(f'[Replay] Preparing {repo_name} in {repo_path}')
# if not repo_path.exists():
# logger.info(
# f'[Replay] Repository {repo_name} not found in {replay_dir}, cloning...'
# )
# Repo.clone_from(repo_url, str(repo_path))

# Now mypy should see Repo as a proper class.
repo = Repo(str(repo_path))
# # Now mypy should see Repo as a proper class.
# repo = Repo(str(repo_path))

if repo.active_branch.name != 'main':
raise ValueError(f'Repository {repo_name} not on main branch')
# if repo.active_branch.name != 'main':
# raise ValueError(f'Repository {repo_name} not on main branch')

origin = repo.remote('origin')
origin.pull()
# origin = repo.remote('origin')
# origin.pull()

# Execute the dependencies installation script
install_script = replay_dir / 'replayapi' / 'scripts' / 'install-deps.sh'
subprocess.run([str(install_script)], check=True)
# # Execute the dependencies installation script
# install_script = replay_dir / 'replayapi' / 'scripts' / 'install-deps.sh'
# subprocess.run([str(install_script)], check=True)


async def process_issue(
Expand Down Expand Up @@ -286,9 +285,10 @@ async def process_issue(
timeout=300,
),
replay=ReplayConfig(
dir=os.environ.get(
'REPLAY_DIR', os.path.abspath(os.path.join(output_dir, 'replay'))
),
# dir=os.environ.get(
# 'REPLAY_DIR', os.path.abspath(os.path.join(output_dir, 'replay'))
# ),
dir=os.environ.get('REPLAY_DIR', None),
api_key=os.environ.get('REPLAY_API_KEY', None),
),
# do not mount workspace
Expand All @@ -305,10 +305,10 @@ async def process_issue(
runtime = create_runtime(config)
await runtime.connect()

# Force-update the Replay repos, if necessary:
if config.replay.dir is None:
raise ValueError('config.replay.dir is not set.')
init_replay(config.replay.dir)
# # Force-update the Replay repos, if necessary:
# if config.replay.dir is None:
# raise ValueError('config.replay.dir is not set.')
# init_replay(config.replay.dir)

async def on_event(evt):
logger.info(evt)
Expand Down
8 changes: 8 additions & 0 deletions openhands/runtime/builder/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,21 @@ def build(
target_image_repo, target_image_source_tag = target_image_hash_name.split(':')
target_image_tag = tags[1].split(':')[1] if len(tags) > 1 else None

# Fetch the latest commit hash for replayapi to bust the cache on the `git clone` layer.
repo_url = 'https://github.com/replayio-public/replayapi.git'
rev_parse_cmd = ['git', 'ls-remote', repo_url, 'main']
replayapi_sha = subprocess.check_output(rev_parse_cmd).decode().split()[0]

logger.info('[Replay] REPLAYAPI_SHA=' + replayapi_sha)

buildx_cmd = [
'docker',
'buildx',
'build',
'--progress=plain',
f'--build-arg=OPENHANDS_RUNTIME_VERSION={oh_version}',
f'--build-arg=OPENHANDS_RUNTIME_BUILD_TIME={datetime.datetime.now().isoformat()}',
f'--build-arg=REPLAYAPI_SHA={replayapi_sha}',
f'--tag={target_image_hash_name}',
'--load',
]
Expand Down
8 changes: 4 additions & 4 deletions openhands/runtime/impl/eventstream/eventstream_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,10 @@ def _init_container(self):
# * But any bugs coming from not having write access might be difficult to debug.
'mode': 'rw',
}
self.log(
'debug',
f'Replay volume: {self.config.replay.dir} -> /replay',
)
self.log(
'debug',
f'Replay volume: {self.config.replay.dir} -> /replay',
)

if self.config.sandbox.browsergym_eval_env is not None:
browsergym_arg = (
Expand Down
11 changes: 7 additions & 4 deletions openhands/runtime/utils/runtime_templates/Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ RUN if [ -z "${RELEASE_TAG}" ]; then \
# Install all dependencies
WORKDIR /openhands/code

# First RUN command
# Basics
RUN \
/openhands/micromamba/bin/micromamba config set changeps1 False && \
# Configure Poetry and create virtual environment
Expand All @@ -85,13 +85,16 @@ RUN \
/openhands/micromamba/bin/micromamba run -n openhands poetry run pip install playwright && \
/openhands/micromamba/bin/micromamba run -n openhands poetry run playwright install --with-deps chromium

# Second RUN command (involving replay)
# Clone replay and make sure the layer is not stale when HEAD changes.
ARG REPLAYAPI_SHA
RUN \
mkdir -p /replay && \
git -C /replay clone https://github.com/replayio-public/replayapi.git && \
/replay/replayapi/scripts/install-deps.sh
cd /replay/replayapi && \
git checkout ${REPLAYAPI_SHA} && \
./scripts/install-deps.sh

# Third RUN command
# More stuff.
RUN \
# Set environment variables
echo "OH_INTERPRETER_PATH=$(/openhands/micromamba/bin/micromamba run -n openhands poetry run python -c 'import sys; print(sys.executable)')" >> /etc/environment && \
Expand Down

0 comments on commit 2f470e5

Please sign in to comment.