Skip to content

Commit 16a4d7a

Browse files
committed
simplify dependencies; update AMI; ssh non_interactive; replace nvidia-docker with docker; improve documentation
1 parent 76d6110 commit 16a4d7a

File tree

3 files changed

+49
-31
lines changed

3 files changed

+49
-31
lines changed

Dockerfile

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# Dockerfile for OmniParser with GPU and OpenGL support.
22
#
3-
# Author: Richard Abrich (@OpenAdaptAI)
4-
#
53
# Base: nvidia/cuda:12.3.1-devel-ubuntu22.04
64
# Features:
75
# - Python 3.12 with Miniconda environment.
@@ -18,25 +16,17 @@
1816
# ```bash
1917
# sudo docker run -d -p 7861:7861 --gpus all --name omniparser-container omniparser
2018
# ```
19+
#
20+
# Author: Richard Abrich ([email protected])
2121

2222
FROM nvidia/cuda:12.3.1-devel-ubuntu22.04
2323

2424
# Install system dependencies with explicit OpenGL libraries
2525
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
26-
git \
2726
git-lfs \
2827
wget \
2928
libgl1 \
3029
libglib2.0-0 \
31-
libsm6 \
32-
libxext6 \
33-
libxrender1 \
34-
libglu1-mesa \
35-
libglib2.0-0 \
36-
libsm6 \
37-
libxrender1 \
38-
libxext6 \
39-
python3-opencv \
4030
&& apt-get clean \
4131
&& rm -rf /var/lib/apt/lists/* \
4232
&& git lfs install

deploy.py

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@
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(
422431
def 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:

docker-build-ec2.yml.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
sudo docker rm {{ project_name }}-container || true
3434

3535
# Build the Docker image
36-
sudo nvidia-docker build -t {{ project_name }} .
36+
sudo docker build -t {{ project_name }} .
3737

3838
# Run the Docker container on the specified port
3939
sudo docker run -d -p 7861:7861 --gpus all --name {{ project_name }}-container {{ project_name }}

0 commit comments

Comments
 (0)