mirror of
https://github.com/OpenHands/OpenHands.git
synced 2026-03-22 13:47:19 +08:00
Fix for docker regression (#11759)
This commit is contained in:
@@ -63,7 +63,9 @@ from openhands.app_server.sandbox.sandbox_spec_service import SandboxSpecService
|
||||
from openhands.app_server.services.injector import InjectorState
|
||||
from openhands.app_server.services.jwt_service import JwtService
|
||||
from openhands.app_server.user.user_context import UserContext
|
||||
from openhands.app_server.utils.docker_utils import replace_localhost_hostname
|
||||
from openhands.app_server.utils.docker_utils import (
|
||||
replace_localhost_hostname_for_docker,
|
||||
)
|
||||
from openhands.experiments.experiment_manager import ExperimentManagerImpl
|
||||
from openhands.integrations.provider import ProviderType
|
||||
from openhands.sdk import LocalWorkspace
|
||||
@@ -473,7 +475,7 @@ class LiveStatusAppConversationService(GitAppConversationService):
|
||||
for exposed_url in exposed_urls
|
||||
if exposed_url.name == AGENT_SERVER
|
||||
)
|
||||
agent_server_url = replace_localhost_hostname(agent_server_url)
|
||||
agent_server_url = replace_localhost_hostname_for_docker(agent_server_url)
|
||||
return agent_server_url
|
||||
|
||||
def _inherit_configuration_from_parent(
|
||||
|
||||
@@ -32,8 +32,9 @@ from openhands.app_server.sandbox.sandbox_service import (
|
||||
)
|
||||
from openhands.app_server.sandbox.sandbox_spec_service import SandboxSpecService
|
||||
from openhands.app_server.services.injector import InjectorState
|
||||
from openhands.app_server.utils.docker_utils import replace_localhost_hostname
|
||||
from openhands.utils.environment import is_running_in_docker
|
||||
from openhands.app_server.utils.docker_utils import (
|
||||
replace_localhost_hostname_for_docker,
|
||||
)
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
SESSION_API_KEY_VARIABLE = 'OH_SESSION_API_KEYS_0'
|
||||
@@ -188,8 +189,7 @@ class DockerSandboxService(SandboxService):
|
||||
)
|
||||
try:
|
||||
# When running in Docker, replace localhost hostname with host.docker.internal for internal requests
|
||||
if is_running_in_docker():
|
||||
app_server_url = replace_localhost_hostname(app_server_url)
|
||||
app_server_url = replace_localhost_hostname_for_docker(app_server_url)
|
||||
|
||||
response = await self.httpx_client.get(
|
||||
f'{app_server_url}{self.health_check_path}'
|
||||
|
||||
@@ -1,21 +1,29 @@
|
||||
from urllib.parse import urlparse, urlunparse
|
||||
|
||||
from openhands.utils.environment import is_running_in_docker
|
||||
|
||||
def replace_localhost_hostname(
|
||||
|
||||
def replace_localhost_hostname_for_docker(
|
||||
url: str, replacement: str = 'host.docker.internal'
|
||||
) -> str:
|
||||
"""Replace localhost hostname in URL with the specified replacement.
|
||||
"""Replace localhost hostname in URL with the specified replacement when running in Docker.
|
||||
|
||||
This function only performs the replacement when the code is running inside a Docker
|
||||
container. When not running in Docker, it returns the original URL unchanged.
|
||||
|
||||
Only replaces the hostname if it's exactly 'localhost', preserving all other
|
||||
parts of the URL including port, path, query parameters, etc.
|
||||
|
||||
Args:
|
||||
url: The URL to process
|
||||
replacement: The hostname to replace localhost with
|
||||
replacement: The hostname to replace localhost with (default: 'host.docker.internal')
|
||||
|
||||
Returns:
|
||||
URL with localhost hostname replaced, or original URL if hostname is not localhost
|
||||
URL with localhost hostname replaced if running in Docker and hostname is localhost,
|
||||
otherwise returns the original URL unchanged
|
||||
"""
|
||||
if not is_running_in_docker():
|
||||
return url
|
||||
parsed = urlparse(url)
|
||||
if parsed.hostname == 'localhost':
|
||||
# Replace only the hostname part, preserving port and everything else
|
||||
|
||||
Reference in New Issue
Block a user