Skip to content

Commit

Permalink
improve deploy docker
Browse files Browse the repository at this point in the history
  • Loading branch information
rbonghi committed Jan 23, 2025
1 parent 82e3b8a commit 3ee1453
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
17 changes: 15 additions & 2 deletions src/nanosaur/ros.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import termios
import tty
import signal
from python_on_whales import docker
from nanosaur.prompt_colors import TerminalFormatter
from nanosaur.utilities import Params, get_nanosaur_home

Expand Down Expand Up @@ -261,8 +262,20 @@ def run_colcon_build(folder_path) -> bool:
return False


def deploy_docker_perception(params: Params, perception_ws_path: str) -> bool:
image_name = "nanosaur-perception"
def deploy_docker_simulation(image_name: str, simulation_ws_path: str) -> bool:
# Get the path to the nanosaur_simulations package
nanosaur_simulations_path = os.path.join(simulation_ws_path, 'src', 'nanosaur_simulations')
# Build the Docker image using the Docker API
docker.build(
get_nanosaur_home(),
file=f"{nanosaur_simulations_path}/Dockerfile",
tags=image_name
)
print(TerminalFormatter.color_text("Docker image built successfully", color='green'))
return True


def deploy_docker_perception(image_name: str, perception_ws_path: str) -> bool:
nanosaur_perception_path = os.path.join(perception_ws_path, 'src', 'nanosaur_perception')

src_folders = [
Expand Down
6 changes: 5 additions & 1 deletion src/nanosaur/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
DEFAULT_WORKSPACE_ROBOT = 'robot_ws'
DEFAULT_WORKSPACE_DEVELOPER = 'ros_ws'

DEFAULT_DOCKER_PERCEPTION_IMAGE = 'nanosaur/perception'
DEFAULT_DOCKER_SIMULATION_IMAGE = 'nanosaur/simulation'
DEFAULT_DOCKER_ROBOT_IMAGE = 'nanosaur/nanosaur'

def workspaces_info(params: Params, verbose: bool):
"""Print information about the workspaces."""
Expand Down Expand Up @@ -256,7 +259,8 @@ def debug(platform, params: Params, args):
def deploy(platform, params: Params, args):
""" Deploy the workspace """
workspace_actions = {
'perception': lambda: ros.deploy_docker_perception(params, get_workspace_path(params, 'ws_perception_name'))
'simulation': lambda: ros.deploy_docker_simulation(DEFAULT_DOCKER_SIMULATION_IMAGE, get_workspace_path(params, 'ws_simulation_name')),
'perception': lambda: ros.deploy_docker_perception(DEFAULT_DOCKER_PERCEPTION_IMAGE, get_workspace_path(params, 'ws_perception_name')),
}
if args.all:
print(TerminalFormatter.color_text("Deploying all workspaces", bold=True))
Expand Down

0 comments on commit 3ee1453

Please sign in to comment.