Skip to content

Commit

Permalink
Improve docker control
Browse files Browse the repository at this point in the history
  • Loading branch information
rbonghi committed Jan 23, 2025
1 parent 779549c commit 21fe23d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
14 changes: 11 additions & 3 deletions src/nanosaur/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def docker_robot_run_command(platform, params: Params, command, name=None):
# Create a DockerClient object with the docker-compose file
nanosaur_compose = DockerClient(compose_files=[docker_compose_path])
try:
nanosaur_compose.compose.run(service='nanosaur_simulator', command=command, remove=True, tty=True, name=name)
nanosaur_compose.compose.run(service='nanosaur-gazebo', command=command, remove=True, tty=True, name=name)
except DockerException as e:
print(TerminalFormatter.color_text(f"Error running the command: {e}", color='red'))
return False
Expand Down Expand Up @@ -123,11 +123,18 @@ def docker_robot_start(platform, params: Params, args):
print(TerminalFormatter.color_text("Creating the environment file...", color='green'))
build_env_file(params)
print(TerminalFormatter.color_text(f"robot {robot.name} starting", color='green'))

compose_profiles = []
if args.profile:
print(TerminalFormatter.color_text(f"Starting with profile: {args.profile}", color='green'))
compose_profiles = [args.profile]
# Create a DockerClient object with the docker-compose file
nanosaur_compose = DockerClient(compose_files=[docker_compose_path])
nanosaur_compose = DockerClient(compose_files=[docker_compose_path], compose_profiles=compose_profiles)
# Start the container in detached mode
try:
nanosaur_compose.compose.up(detach=args.detach)
if not args.detach:
nanosaur_compose.compose.rm(volumes=True)
except DockerException as e:
print(TerminalFormatter.color_text(f"Error starting the robot: {e}", color='red'))
return False
Expand Down Expand Up @@ -164,7 +171,8 @@ def docker_simulator_start(platform, params: Params, args):
build_env_file(params)
print(TerminalFormatter.color_text(f"Simulator {simulation_tool} starting", color='green'))
try:
nanosaur_compose.compose.up(services=[f'nanosaur_{simulation_tool}'], recreate=False)
nanosaur_compose.compose.up(services=[f'nanosaur-{simulation_tool}'], recreate=False)
nanosaur_compose.compose.rm(services=[f'nanosaur-{simulation_tool}'], volumes=True)
except DockerException as e:
print(TerminalFormatter.color_text(f"Error starting the simulation tool: {e}", color='red'))
return False
Expand Down
5 changes: 4 additions & 1 deletion src/nanosaur/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ def install(platform, params: Params, args):


def nanosaur_wake_up(platform, params: Params, args):
args.detach = True
args.detach = False
# Start the container in detached mode
simulation_tool = params.get('simulation_tool','').lower().replace(' ', '_')
args.profile = simulation_tool
return docker_robot_start(platform, params, args)


Expand Down
2 changes: 1 addition & 1 deletion src/nanosaur/robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def parser_robot_menu(subparsers: argparse._SubParsersAction, params: Params) ->
# Add robot start subcommand
parser_robot_start = robot_subparsers.add_parser('start', help="Activate the robot")
parser_robot_start.add_argument(
'--build', action='store_true', help="Rebuild docker before starting")
'--profile', type=str, help="Specify the profile name to use")
parser_robot_start.add_argument(
'--detach', action='store_true', help="Run the robot in detached mode")
parser_robot_start.set_defaults(func=docker.docker_robot_start)
Expand Down

0 comments on commit 21fe23d

Please sign in to comment.