fix: fix proxy setup
This commit is contained in:
@@ -59,7 +59,7 @@ class SetupController:
|
|||||||
{
|
{
|
||||||
"type": str, corresponding to the `_{:}_setup` methods of
|
"type": str, corresponding to the `_{:}_setup` methods of
|
||||||
this class
|
this class
|
||||||
"parameters": dick like {str, Any} providing the keyword
|
"parameters": dict like {str, Any} providing the keyword
|
||||||
parameters
|
parameters
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
@@ -368,6 +368,19 @@ class SetupController:
|
|||||||
Args:
|
Args:
|
||||||
client_password (str): Password for sudo operations, defaults to "password"
|
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
|
# Get proxy from global proxy pool
|
||||||
proxy_pool = get_global_proxy_pool()
|
proxy_pool = get_global_proxy_pool()
|
||||||
current_proxy = proxy_pool.get_next_proxy()
|
current_proxy = proxy_pool.get_next_proxy()
|
||||||
@@ -382,10 +395,17 @@ class SetupController:
|
|||||||
|
|
||||||
# Configure system proxy environment variables
|
# Configure system proxy environment variables
|
||||||
proxy_commands = [
|
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 \"apt-get update\"", ## TODO: remove this line if ami is already updated
|
||||||
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 install -y tinyproxy\"", ## TODO: remove this line if tinyproxy is already installed
|
||||||
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 'Port 18888' > /tmp/tinyproxy.conf\"",
|
||||||
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 '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
|
# Execute all proxy configuration commands
|
||||||
@@ -397,6 +417,8 @@ class SetupController:
|
|||||||
proxy_pool.mark_proxy_failed(current_proxy)
|
proxy_pool.mark_proxy_failed(current_proxy)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
self._launch_setup(["tinyproxy -c /tmp/tinyproxy.conf -d"], shell=True)
|
||||||
|
|
||||||
# Reload environment variables
|
# Reload environment variables
|
||||||
reload_cmd = "source /etc/environment"
|
reload_cmd = "source /etc/environment"
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -197,6 +197,9 @@ class DesktopEnv(gym.Env):
|
|||||||
logger.info("Emulator started.")
|
logger.info("Emulator started.")
|
||||||
|
|
||||||
if task_config is not None:
|
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._set_task_info(task_config)
|
||||||
self.setup_controller.reset_cache_dir(self.cache_dir)
|
self.setup_controller.reset_cache_dir(self.cache_dir)
|
||||||
logger.info("Setting up environment...")
|
logger.info("Setting up environment...")
|
||||||
@@ -215,10 +218,6 @@ class DesktopEnv(gym.Env):
|
|||||||
|
|
||||||
logger.info("Environment setup complete.")
|
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()
|
observation = self._get_obs()
|
||||||
return observation
|
return observation
|
||||||
|
|
||||||
|
|||||||
@@ -21,12 +21,6 @@ def create_vm_manager_and_provider(provider_name: str, region: str, use_proxy: b
|
|||||||
return VirtualBoxVMManager(), VirtualBoxProvider(region)
|
return VirtualBoxVMManager(), VirtualBoxProvider(region)
|
||||||
elif provider_name in ["aws", "amazon web services"]:
|
elif provider_name in ["aws", "amazon web services"]:
|
||||||
from desktop_env.providers.aws.manager import AWSVMManager
|
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
|
from desktop_env.providers.aws.provider import AWSProvider
|
||||||
return AWSVMManager(), AWSProvider(region)
|
return AWSVMManager(), AWSProvider(region)
|
||||||
elif provider_name == "azure":
|
elif provider_name == "azure":
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ DEFAULT_REGION = "us-east-1"
|
|||||||
# todo: Add doc for the configuration of image, security group and network interface
|
# todo: Add doc for the configuration of image, security group and network interface
|
||||||
# todo: public the AMI images
|
# todo: public the AMI images
|
||||||
IMAGE_ID_MAP = {
|
IMAGE_ID_MAP = {
|
||||||
"us-east-1": "ami-025b3f907e5c1b805",
|
"us-east-1": "ami-0cae20d2680c939d4",
|
||||||
"ap-east-1": "ami-0c092a5b8be4116f5",
|
"ap-east-1": "ami-0c092a5b8be4116f5",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
"parameters": {
|
"parameters": {
|
||||||
"command": [
|
"command": [
|
||||||
"google-chrome",
|
"google-chrome",
|
||||||
|
"--proxy-server=http://127.0.0.1:18888",
|
||||||
"--remote-debugging-port=1337"
|
"--remote-debugging-port=1337"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -104,5 +105,5 @@
|
|||||||
"ignore_case": true
|
"ignore_case": true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"proxy": false
|
"proxy": true
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user