@@ -647,7 +647,7 @@ def start() -> None:
647647 )
648648
649649 # Use the `ssh` method to connect and execute instance setup commands
650- Deploy .ssh ()
650+ Deploy .ssh (non_interactive = True )
651651
652652 # Add, commit, and push the workflow file changes, setting the upstream branch
653653 try :
@@ -764,12 +764,13 @@ def status() -> None:
764764 logger .info (f"Instance ID: { instance .id } , State: { instance .state ['Name' ]} , HTTP URL: Not available (no public IP)" )
765765
766766 @staticmethod
767- def ssh (project_name : str = config .PROJECT_NAME ) -> None :
767+ def ssh (project_name : str = config .PROJECT_NAME , non_interactive : bool = False ) -> None :
768768 """
769- 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.
770770
771771 Args:
772772 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.
773774
774775 Returns:
775776 None
@@ -785,16 +786,29 @@ def ssh(project_name: str = config.PROJECT_NAME) -> None:
785786 for instance in instances :
786787 logger .info (f"Attempting to SSH into instance: ID - { instance .id } , IP - { instance .public_ip_address } " )
787788
788- # Build the SSH command with StrictHostKeyChecking disabled
789- ssh_command = [
790- "ssh" ,
791- "-o" , "StrictHostKeyChecking=no" , # Automatically accept new host keys
792- "-o" , "UserKnownHostsFile=/dev/null" , # Prevent writing to known_hosts
793- "-i" , config .AWS_EC2_KEY_PATH ,
794- f"{ config .AWS_EC2_USER } @{ instance .public_ip_address } "
795- ]
796-
797- # 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
798812 try :
799813 subprocess .run (ssh_command , check = True )
800814 except subprocess .CalledProcessError as e :
0 commit comments