Skip to content

Commit 173b5f3

Browse files
authored
Cleans up the docker container interface and utilities (isaac-sim#823)
# Description Mainly documentation fixes and ensuring the code quality remains consistent. Also adds the `container.sh` script which calls the python script for compatibility reasons. We can remove it in later releases. ## Type of change - Bug fix (non-breaking change which fixes an issue) - This change requires a documentation update ## Checklist - [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with `./isaaclab.sh --format` - [x] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] I have updated the changelog and the corresponding version in the extension's `config/extension.toml` file - [x] I have added my name to the `CONTRIBUTORS.md` or my name already exists there
1 parent 7379dce commit 173b5f3

10 files changed

+536
-386
lines changed

docker/.env.ros2

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
###
44
# Set the version of the ROS2 apt package to install (ros-base, desktop, desktop-full)
55
ROS2_APT_PACKAGE=ros-base
6-
# Se t ROS2 middleware implementation to use (e.g. rmw_fastrtps_cpp, rmw_cyclonedds_cpp)
6+
# Set ROS2 middleware implementation to use (e.g. rmw_fastrtps_cpp, rmw_cyclonedds_cpp)
77
RMW_IMPLEMENTATION=rmw_fastrtps_cpp
88
# Path to fastdds.xml file to use (only needed when using fastdds)
99
FASTRTPS_DEFAULT_PROFILES_FILE=${DOCKER_USER_HOME}/.ros/fastdds.xml

docker/container.py

+41-14
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,46 @@
99
import shutil
1010
from pathlib import Path
1111

12-
from utils import x11_utils
13-
from utils.isaaclab_container_interface import IsaacLabContainerInterface
12+
from utils import ContainerInterface, x11_utils
1413

1514

16-
def main():
15+
def parse_cli_args() -> argparse.Namespace:
16+
"""Parse command line arguments.
17+
18+
This function creates a parser object and adds subparsers for each command. The function then parses the
19+
command line arguments and returns the parsed arguments.
20+
21+
Returns:
22+
The parsed command line arguments.
23+
"""
1724
parser = argparse.ArgumentParser(description="Utility for using Docker with Isaac Lab.")
18-
subparsers = parser.add_subparsers(dest="command", required=True)
1925

2026
# We have to create separate parent parsers for common options to our subparsers
2127
parent_parser = argparse.ArgumentParser(add_help=False)
22-
parent_parser.add_argument("profile", nargs="?", default="base", help="Optional container profile specification.")
28+
parent_parser.add_argument(
29+
"profile", nargs="?", default="base", help="Optional container profile specification. Example: 'base' or 'ros'."
30+
)
2331
parent_parser.add_argument(
2432
"--files",
2533
nargs="*",
2634
default=None,
2735
help=(
28-
"Allows additional .yaml files to be passed to the docker compose command. Files will be merged with"
29-
" docker-compose.yaml in the order in which they are provided."
36+
"Allows additional '.yaml' files to be passed to the docker compose command. These files will be merged"
37+
" with 'docker-compose.yaml' in their provided order."
3038
),
3139
)
3240
parent_parser.add_argument(
3341
"--env-files",
3442
nargs="*",
3543
default=None,
3644
help=(
37-
"Allows additional .env files to be passed to the docker compose command. Files will be merged with"
38-
" .env.base in the order in which they are provided."
45+
"Allows additional '.env' files to be passed to the docker compose command. These files will be merged with"
46+
" '.env.base' in their provided order."
3947
),
4048
)
4149

4250
# Actual command definition begins here
51+
subparsers = parser.add_subparsers(dest="command", required=True)
4352
subparsers.add_parser(
4453
"start",
4554
help="Build the docker image and create the container in detached mode.",
@@ -64,37 +73,55 @@ def main():
6473
)
6574
subparsers.add_parser("stop", help="Stop the docker container and remove it.", parents=[parent_parser])
6675

76+
# parse the arguments to determine the command
6777
args = parser.parse_args()
6878

79+
return args
80+
81+
82+
def main(args: argparse.Namespace):
83+
"""Main function for the Docker utility."""
84+
# check if docker is installed
6985
if not shutil.which("docker"):
70-
raise RuntimeError("Docker is not installed! Please check the 'Docker Guide' for instruction.")
86+
raise RuntimeError(
87+
"Docker is not installed! Please check the 'Docker Guide' for instruction: "
88+
"https://isaac-sim.github.io/IsaacLab/source/deployment/docker.html"
89+
)
7190

72-
# Creating container interface
73-
ci = IsaacLabContainerInterface(
91+
# creating container interface
92+
ci = ContainerInterface(
7493
context_dir=Path(__file__).resolve().parent, profile=args.profile, yamls=args.files, envs=args.env_files
7594
)
7695

7796
print(f"[INFO] Using container profile: {ci.profile}")
7897
if args.command == "start":
98+
# check if x11 forwarding is enabled
7999
x11_outputs = x11_utils.x11_check(ci.statefile)
100+
# if x11 forwarding is enabled, add the x11 yaml and environment variables
80101
if x11_outputs is not None:
81102
(x11_yaml, x11_envar) = x11_outputs
82103
ci.add_yamls += x11_yaml
83104
ci.environ.update(x11_envar)
105+
# start the container
84106
ci.start()
85107
elif args.command == "enter":
108+
# refresh the x11 forwarding
86109
x11_utils.x11_refresh(ci.statefile)
110+
# enter the container
87111
ci.enter()
88112
elif args.command == "config":
89113
ci.config(args.output_yaml)
90114
elif args.command == "copy":
91115
ci.copy()
92116
elif args.command == "stop":
117+
# stop the container
93118
ci.stop()
119+
# cleanup the x11 forwarding
94120
x11_utils.x11_cleanup(ci.statefile)
95121
else:
96-
raise RuntimeError(f"Invalid command provided: {args.command}")
122+
raise RuntimeError(f"Invalid command provided: {args.command}. Please check the help message.")
97123

98124

99125
if __name__ == "__main__":
100-
main()
126+
args_cli = parse_cli_args()
127+
main(args_cli)

docker/container.sh

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright (c) 2022-2024, The Isaac Lab Project Developers.
4+
# All rights reserved.
5+
#
6+
# SPDX-License-Identifier: BSD-3-Clause
7+
8+
# print warning of deprecated script in yellow
9+
echo -e "\e[33m------------------------------------------------------------"
10+
echo -e "WARNING: This script is deprecated and will be removed in the future. Please use 'docker/container.py' instead."
11+
echo -e "------------------------------------------------------------\e[0m\n"
12+
13+
# obtain current directory
14+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
15+
16+
# call the python script
17+
python3 "${SCRIPT_DIR}/container.py" "${@:1}"

docker/utils/__init__.py

+4
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@
22
# All rights reserved.
33
#
44
# SPDX-License-Identifier: BSD-3-Clause
5+
6+
from .container_interface import ContainerInterface
7+
8+
__all__ = ["ContainerInterface"]

0 commit comments

Comments
 (0)