| |
|
|
| |
| |
| |
| |
|
|
| import argparse |
| import shutil |
| from pathlib import Path |
|
|
| from utils import ContainerInterface, x11_utils |
|
|
|
|
| def parse_cli_args() -> argparse.Namespace: |
| """Parse command line arguments. |
| |
| This function creates a parser object and adds subparsers for each command. The function then parses the |
| command line arguments and returns the parsed arguments. |
| |
| Returns: |
| The parsed command line arguments. |
| """ |
| parser = argparse.ArgumentParser(description="Utility for using Docker with Isaac Lab.") |
|
|
| |
| parent_parser = argparse.ArgumentParser(add_help=False) |
| parent_parser.add_argument( |
| "profile", nargs="?", default="base", help="Optional container profile specification. Example: 'base' or 'ros'." |
| ) |
| parent_parser.add_argument( |
| "--files", |
| nargs="*", |
| default=None, |
| help=( |
| "Allows additional '.yaml' files to be passed to the docker compose command. These files will be merged" |
| " with 'docker-compose.yaml' in their provided order." |
| ), |
| ) |
| parent_parser.add_argument( |
| "--env-files", |
| nargs="*", |
| default=None, |
| help=( |
| "Allows additional '.env' files to be passed to the docker compose command. These files will be merged with" |
| " '.env.base' in their provided order." |
| ), |
| ) |
| parent_parser.add_argument( |
| "--suffix", |
| nargs="?", |
| default=None, |
| help=( |
| "Optional docker image and container name suffix. Defaults to None, in which case, the docker name" |
| " suffix is set to the empty string. A hyphen is inserted in between the profile and the suffix if" |
| ' the suffix is a nonempty string. For example, if "base" is passed to profile, and "custom" is' |
| " passed to suffix, then the produced docker image and container will be named ``isaac-lab-base-custom``." |
| ), |
| ) |
| parent_parser.add_argument( |
| "--info", |
| action="store_true", |
| help="Print the container interface information. This is useful for debugging purposes.", |
| ) |
|
|
| |
| subparsers = parser.add_subparsers(dest="command", required=True) |
| subparsers.add_parser( |
| "build", |
| help="Build the docker image without creating the container.", |
| parents=[parent_parser], |
| ) |
| subparsers.add_parser( |
| "start", |
| help="Build the docker image and create the container in detached mode.", |
| parents=[parent_parser], |
| ) |
| subparsers.add_parser( |
| "enter", help="Begin a new bash process within an existing Isaac Lab container.", parents=[parent_parser] |
| ) |
| config = subparsers.add_parser( |
| "config", |
| help=( |
| "Generate a docker-compose.yaml from the passed yamls, .envs, and either print to the terminal or create a" |
| " yaml at output_yaml" |
| ), |
| parents=[parent_parser], |
| ) |
| config.add_argument( |
| "--output-yaml", nargs="?", default=None, help="Yaml file to write config output to. Defaults to None." |
| ) |
| subparsers.add_parser( |
| "copy", help="Copy build and logs artifacts from the container to the host machine.", parents=[parent_parser] |
| ) |
| subparsers.add_parser("stop", help="Stop the docker container and remove it.", parents=[parent_parser]) |
|
|
| |
| args = parser.parse_args() |
|
|
| return args |
|
|
|
|
| def main(args: argparse.Namespace): |
| """Main function for the Docker utility.""" |
| |
| if not shutil.which("docker"): |
| raise RuntimeError( |
| "Docker is not installed! Please check the 'Docker Guide' for instruction: " |
| "https://isaac-sim.github.io/IsaacLab/source/deployment/docker.html" |
| ) |
|
|
| |
| ci = ContainerInterface( |
| context_dir=Path(__file__).resolve().parent, |
| profile=args.profile, |
| yamls=args.files, |
| envs=args.env_files, |
| suffix=args.suffix, |
| ) |
| if args.info: |
| print("[INFO] Printing container interface information...\n") |
| ci.print_info() |
| return |
|
|
| print(f"[INFO] Using container profile: {ci.profile}") |
| if args.command == "build": |
| |
| x11_outputs = x11_utils.x11_check(ci.statefile) |
| |
| if x11_outputs is not None: |
| (x11_yaml, x11_envar) = x11_outputs |
| ci.add_yamls += x11_yaml |
| ci.environ.update(x11_envar) |
| |
| ci.build() |
| elif args.command == "start": |
| |
| x11_outputs = x11_utils.x11_check(ci.statefile) |
| |
| if x11_outputs is not None: |
| (x11_yaml, x11_envar) = x11_outputs |
| ci.add_yamls += x11_yaml |
| ci.environ.update(x11_envar) |
| |
| ci.start() |
| elif args.command == "enter": |
| |
| x11_utils.x11_refresh(ci.statefile) |
| |
| ci.enter() |
| elif args.command == "config": |
| ci.config(args.output_yaml) |
| elif args.command == "copy": |
| ci.copy() |
| elif args.command == "stop": |
| |
| ci.stop() |
| |
| x11_utils.x11_cleanup(ci.statefile) |
| else: |
| raise RuntimeError(f"Invalid command provided: {args.command}. Please check the help message.") |
|
|
|
|
| if __name__ == "__main__": |
| args_cli = parse_cli_args() |
| main(args_cli) |
|
|