fix: fix proxy setup

This commit is contained in:
adlsdztony
2025-07-01 13:20:26 +00:00
parent 48ac57697a
commit 64f47d1a32
5 changed files with 37 additions and 21 deletions

View File

@@ -59,7 +59,7 @@ class SetupController:
{
"type": str, corresponding to the `_{:}_setup` methods of
this class
"parameters": dick like {str, Any} providing the keyword
"parameters": dict like {str, Any} providing the keyword
parameters
}
"""
@@ -368,6 +368,19 @@ class SetupController:
Args:
client_password (str): Password for sudo operations, defaults to "password"
"""
retry = 0
while retry < MAX_RETRIES:
try:
_ = requests.get(self.http_server + "/terminal")
break
except:
time.sleep(5)
retry += 1
logger.info(f"retry: {retry}/{MAX_RETRIES}")
if retry == MAX_RETRIES:
return False
# Get proxy from global proxy pool
proxy_pool = get_global_proxy_pool()
current_proxy = proxy_pool.get_next_proxy()
@@ -380,14 +393,21 @@ class SetupController:
proxy_url = proxy_pool._format_proxy_url(current_proxy)
logger.info(f"Setting up proxy: {current_proxy.host}:{current_proxy.port}")
# Configure system proxy environment variables
# Configure system proxy environment variables
proxy_commands = [
f"echo '{client_password}' | sudo -S bash -c \"echo 'export http_proxy={proxy_url}' >> /etc/environment\"",
f"echo '{client_password}' | sudo -S bash -c \"echo 'export https_proxy={proxy_url}' >> /etc/environment\"",
f"echo '{client_password}' | sudo -S bash -c \"echo 'export HTTP_PROXY={proxy_url}' >> /etc/environment\"",
f"echo '{client_password}' | sudo -S bash -c \"echo 'export HTTPS_PROXY={proxy_url}' >> /etc/environment\"",
f"echo '{client_password}' | sudo -S bash -c \"apt-get update\"", ## TODO: remove this line if ami is already updated
f"echo '{client_password}' | sudo -S bash -c \"apt-get install -y tinyproxy\"", ## TODO: remove this line if tinyproxy is already installed
f"echo '{client_password}' | sudo -S bash -c \"echo 'Port 18888' > /tmp/tinyproxy.conf\"",
f"echo '{client_password}' | sudo -S bash -c \"echo 'Allow 127.0.0.1' >> /tmp/tinyproxy.conf\"",
f"echo '{client_password}' | sudo -S bash -c \"echo 'Upstream http {current_proxy.username}:{current_proxy.password}@{current_proxy.host}:{current_proxy.port}' >> /tmp/tinyproxy.conf\"",
# CML commands to set environment variables for proxy
f"echo 'export http_proxy={proxy_url}' >> ~/.bashrc",
f"echo 'export https_proxy={proxy_url}' >> ~/.bashrc",
f"echo 'export HTTP_PROXY={proxy_url}' >> ~/.bashrc",
f"echo 'export HTTPS_PROXY={proxy_url}' >> ~/.bashrc",
]
# Execute all proxy configuration commands
for cmd in proxy_commands:
try:
@@ -397,6 +417,8 @@ class SetupController:
proxy_pool.mark_proxy_failed(current_proxy)
raise
self._launch_setup(["tinyproxy -c /tmp/tinyproxy.conf -d"], shell=True)
# Reload environment variables
reload_cmd = "source /etc/environment"
try:

View File

@@ -197,6 +197,9 @@ class DesktopEnv(gym.Env):
logger.info("Emulator started.")
if task_config is not None:
if task_config.get("proxy", False) and self.enable_proxy:
# If using proxy and proxy is enabled, set up the proxy configuration
self.setup_controller._proxy_setup()
self._set_task_info(task_config)
self.setup_controller.reset_cache_dir(self.cache_dir)
logger.info("Setting up environment...")
@@ -214,10 +217,6 @@ class DesktopEnv(gym.Env):
break
logger.info("Environment setup complete.")
if task_config.get("proxy", False) and self.enable_proxy:
# If using proxy and proxy is enabled, set up the proxy configuration
self.setup_controller._proxy_setup()
observation = self._get_obs()
return observation

View File

@@ -21,14 +21,8 @@ def create_vm_manager_and_provider(provider_name: str, region: str, use_proxy: b
return VirtualBoxVMManager(), VirtualBoxProvider(region)
elif provider_name in ["aws", "amazon web services"]:
from desktop_env.providers.aws.manager import AWSVMManager
if use_proxy:
# Use proxy-enabled AWS provider
from desktop_env.providers.aws.provider_with_proxy import AWSProviderWithProxy
return AWSVMManager(proxy_config_file="dataimpulse_proxy_config.json"), AWSProviderWithProxy(region, proxy_config_file="dataimpulse_proxy_config.json")
else:
# Use regular AWS provider
from desktop_env.providers.aws.provider import AWSProvider
return AWSVMManager(), AWSProvider(region)
from desktop_env.providers.aws.provider import AWSProvider
return AWSVMManager(), AWSProvider(region)
elif provider_name == "azure":
from desktop_env.providers.azure.manager import AzureVMManager
from desktop_env.providers.azure.provider import AzureProvider

View File

@@ -35,7 +35,7 @@ DEFAULT_REGION = "us-east-1"
# todo: Add doc for the configuration of image, security group and network interface
# todo: public the AMI images
IMAGE_ID_MAP = {
"us-east-1": "ami-025b3f907e5c1b805",
"us-east-1": "ami-0cae20d2680c939d4",
"ap-east-1": "ami-0c092a5b8be4116f5",
}

View File

@@ -9,6 +9,7 @@
"parameters": {
"command": [
"google-chrome",
"--proxy-server=http://127.0.0.1:18888",
"--remote-debugging-port=1337"
]
}
@@ -104,5 +105,5 @@
"ignore_case": true
}
},
"proxy": false
"proxy": true
}