Skip to content

Commit

Permalink
improve deploy function
Browse files Browse the repository at this point in the history
  • Loading branch information
rbonghi committed Jan 23, 2025
1 parent 2f37190 commit a093836
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 25 deletions.
50 changes: 27 additions & 23 deletions src/nanosaur/ros.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,33 +265,37 @@ def run_colcon_build(folder_path) -> bool:
return False


def deploy_docker_simulation(docker_user: str, simulation_ws_path: str, all: bool) -> bool:
def deploy_docker_simulation(docker_user: str, simulation_ws_path: str, image_name : str = None) -> bool:
# Get the path to the nanosaur_simulations package
nanosaur_simulations_path = os.path.join(simulation_ws_path, 'src', 'nanosaur_simulations')
# Build Gazebo sim docker
tag_image = f"{docker_user}/{NANOSAUR_DOCKER_PACKAGE_SIMULATION}:gazebo"
try:
print(TerminalFormatter.color_text(f"Building Gazebo simulation docker image {tag_image}", color='magenta', bold=True))
docker.build(
get_nanosaur_home(),
file=f"{nanosaur_simulations_path}/Dockerfile.gazebo",
tags=tag_image
)
except DockerException as e:
print(TerminalFormatter.color_text(f"Error building Gazebo Docker image: {e}", color='red'))
return False
if image_name == 'gazebo' or image_name is None:
tag_image = f"{docker_user}/{NANOSAUR_DOCKER_PACKAGE_SIMULATION}:gazebo"
try:
print(TerminalFormatter.color_text(f"Building Gazebo simulation docker image {tag_image}", color='magenta', bold=True))
docker.build(
get_nanosaur_home(),
file=f"{nanosaur_simulations_path}/Dockerfile.gazebo",
tags=tag_image
)
except DockerException as e:
print(TerminalFormatter.color_text(f"Error building Gazebo Docker image: {e}", color='red'))
return False

# Build the Docker image for nanosaur bridge
tag_image = f"{docker_user}/{NANOSAUR_DOCKER_PACKAGE_ROBOT}:simulation"
try:
print(TerminalFormatter.color_text(f"Building Nanosaur robot docker image {tag_image}", color='magenta', bold=True))
docker.build(
get_nanosaur_home(),
file=f"{nanosaur_simulations_path}/Dockerfile.nanosaur",
tags=tag_image
)
except DockerException as e:
print(TerminalFormatter.color_text(f"Error building Nanosaur Docker image: {e}", color='red'))
return False
if image_name == 'robot' or image_name is None:
tag_image = f"{docker_user}/{NANOSAUR_DOCKER_PACKAGE_ROBOT}:simulation"
try:
print(TerminalFormatter.color_text(f"Building Nanosaur robot docker image {tag_image}", color='magenta', bold=True))
docker.build(
get_nanosaur_home(),
file=f"{nanosaur_simulations_path}/Dockerfile.nanosaur",
tags=tag_image
)
except DockerException as e:
print(TerminalFormatter.color_text(f"Error building Nanosaur Docker image: {e}", color='red'))
return False

# Print success message
print(TerminalFormatter.color_text("Docker image built successfully", color='green'))
return True
Expand Down
5 changes: 3 additions & 2 deletions src/nanosaur/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ def add_workspace_subcommand(name, help_text, func):
add_workspace_subcommand('update', "Update the workspace", update)
add_workspace_subcommand('build', "Build the workspace", build)
add_workspace_subcommand('debug', "Debug the workspace", debug)
add_workspace_subcommand('deploy', "Deploy workspace to docker image", deploy)
parser_deploy = add_workspace_subcommand('deploy', "Deploy workspace to docker image", deploy)
parser_deploy.add_argument('image_name', type=str, nargs='?', help="Specify the image name")
return parser_workspace


Expand Down Expand Up @@ -257,7 +258,7 @@ def deploy(platform, params: Params, args):
nanosaur_docker_user = get_nanosaur_docker_user(params)
""" Deploy the workspace """
workspace_actions = {
'simulation': lambda: ros.deploy_docker_simulation(nanosaur_docker_user, get_workspace_path(params, 'ws_simulation_name'), args.all),
'simulation': lambda: ros.deploy_docker_simulation(nanosaur_docker_user, get_workspace_path(params, 'ws_simulation_name'), args.image_name),
'perception': lambda: ros.deploy_docker_perception(nanosaur_docker_user, get_workspace_path(params, 'ws_perception_name')),
}
if args.all:
Expand Down

0 comments on commit a093836

Please sign in to comment.