2424
2525 python deploy.py start
2626
27+ You may see the following error:
28+
29+ botocore.exceptions.ClientError: An error occurred (OptInRequired) when
30+ calling the RunInstances operation: In order to use this AWS
31+ Marketplace product you need to accept terms and subscribe. To do so
32+ please visit https://aws.amazon.com/marketplace/pp?sku=64g24n0wem7a8nuhfum3097vb
33+
34+ Open the specified URL in the browser and accept the terms, then try again.
35+
2736 4. Wait for the build to succeed in Github actions (see console output for URL)
2837
2938 5. Open the gradio interface (see console output for URL) and test it out.
@@ -125,8 +134,8 @@ class Config(BaseSettings):
125134 GITHUB_TOKEN : str
126135 PROJECT_NAME : str
127136
128- AWS_EC2_AMI : str = "ami-0f9c346cdcac09fb5" # Deep Learning AMI GPU PyTorch 2.0.1 (Ubuntu 20.04) 20230827
129- AWS_EC2_DISK_SIZE : int = 100 # GB
137+ AWS_EC2_AMI : str = "ami-06835d15c4de57810"
138+ AWS_EC2_DISK_SIZE : int = 128 # GB
130139 #AWS_EC2_INSTANCE_TYPE: str = "p3.2xlarge" # (V100 16GB $3.06/hr x86_64)
131140 AWS_EC2_INSTANCE_TYPE : str = "g4dn.xlarge" # (T4 16GB $0.526/hr x86_64)
132141 AWS_EC2_USER : str = "ubuntu"
@@ -422,9 +431,9 @@ def deploy_ec2_instance(
422431def configure_ec2_instance (
423432 instance_id : str | None = None ,
424433 instance_ip : str | None = None ,
425- max_ssh_retries : int = 10 ,
426- ssh_retry_delay : int = 10 ,
427- max_cmd_retries : int = 10 ,
434+ max_ssh_retries : int = 20 ,
435+ ssh_retry_delay : int = 20 ,
436+ max_cmd_retries : int = 20 ,
428437 cmd_retry_delay : int = 30 ,
429438) -> tuple [str | None , str | None ]:
430439 """
@@ -433,9 +442,9 @@ def configure_ec2_instance(
433442 Args:
434443 instance_id (str | None): The ID of the instance to configure. If None, a new instance will be deployed. Defaults to None.
435444 instance_ip (str | None): The IP address of the instance. Must be provided if instance_id is manually passed. Defaults to None.
436- max_ssh_retries (int): Maximum number of SSH connection retries. Defaults to 10 .
437- ssh_retry_delay (int): Delay between SSH connection retries in seconds. Defaults to 10 .
438- max_cmd_retries (int): Maximum number of command execution retries. Defaults to 10 .
445+ max_ssh_retries (int): Maximum number of SSH connection retries. Defaults to 20 .
446+ ssh_retry_delay (int): Delay between SSH connection retries in seconds. Defaults to 20 .
447+ max_cmd_retries (int): Maximum number of command execution retries. Defaults to 20 .
439448 cmd_retry_delay (int): Delay between command execution retries in seconds. Defaults to 30.
440449
441450 Returns:
@@ -637,6 +646,9 @@ def start() -> None:
637646 config .GITHUB_OWNER , config .GITHUB_REPO , config .GITHUB_TOKEN ,
638647 )
639648
649+ # Use the `ssh` method to connect and execute instance setup commands
650+ Deploy .ssh (non_interactive = True )
651+
640652 # Add, commit, and push the workflow file changes, setting the upstream branch
641653 try :
642654 # Stage the workflow file
@@ -752,12 +764,13 @@ def status() -> None:
752764 logger .info (f"Instance ID: { instance .id } , State: { instance .state ['Name' ]} , HTTP URL: Not available (no public IP)" )
753765
754766 @staticmethod
755- def ssh (project_name : str = config .PROJECT_NAME ) -> None :
767+ def ssh (project_name : str = config .PROJECT_NAME , non_interactive : bool = False ) -> None :
756768 """
757- Establishes an SSH connection to the EC2 instance associated with the specified project name using subprocess .
769+ Establishes an SSH connection to the EC2 instance associated with the specified project name.
758770
759771 Args:
760772 project_name (str): The project name used to tag the instance. Defaults to config.PROJECT_NAME.
773+ non_interactive (bool): If True, ensures a full interactive login simulation. Defaults to False.
761774
762775 Returns:
763776 None
@@ -773,14 +786,29 @@ def ssh(project_name: str = config.PROJECT_NAME) -> None:
773786 for instance in instances :
774787 logger .info (f"Attempting to SSH into instance: ID - { instance .id } , IP - { instance .public_ip_address } " )
775788
776- # Build the SSH command
777- ssh_command = [
778- "ssh" ,
779- "-i" , config .AWS_EC2_KEY_PATH ,
780- f"{ config .AWS_EC2_USER } @{ instance .public_ip_address } "
781- ]
782-
783- # Start an interactive shell session
789+ if non_interactive :
790+ # Simulate full login by forcing all initialization scripts
791+ ssh_command = [
792+ "ssh" ,
793+ "-o" , "StrictHostKeyChecking=no" , # Automatically accept new host keys
794+ "-o" , "UserKnownHostsFile=/dev/null" , # Prevent writing to known_hosts
795+ "-i" , config .AWS_EC2_KEY_PATH ,
796+ f"{ config .AWS_EC2_USER } @{ instance .public_ip_address } " ,
797+ "-t" , # Allocate a pseudo-terminal
798+ "-tt" , # Force pseudo-terminal allocation
799+ "bash --login -c 'exit'" # Force a full login shell and exit immediately
800+ ]
801+ else :
802+ # Standard interactive SSH session
803+ ssh_command = [
804+ "ssh" ,
805+ "-o" , "StrictHostKeyChecking=no" ,
806+ "-o" , "UserKnownHostsFile=/dev/null" ,
807+ "-i" , config .AWS_EC2_KEY_PATH ,
808+ f"{ config .AWS_EC2_USER } @{ instance .public_ip_address } "
809+ ]
810+
811+ # Execute the SSH command
784812 try :
785813 subprocess .run (ssh_command , check = True )
786814 except subprocess .CalledProcessError as e :
0 commit comments