Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add project name option for docker compose
Browse files Browse the repository at this point in the history
ZiwenZhuang committed Nov 12, 2024

Unverified

The committer email address is not verified.
1 parent 84b2d2d commit 82de109
Showing 6 changed files with 43 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -78,6 +78,9 @@ Guidelines for modifications:
* Yujian Zhang
* Zhengyu Zhang
* Ziqi Fan
* Qian Wan
* Wei Yang
* Ziwen Zhuang

## Acknowledgements

3 changes: 3 additions & 0 deletions docker/.env.base
Original file line number Diff line number Diff line change
@@ -14,3 +14,6 @@ DOCKER_ISAACSIM_ROOT_PATH=/isaac-sim
DOCKER_ISAACLAB_PATH=/workspace/isaaclab
# Docker user directory - by default this is the root user's home directory
DOCKER_USER_HOME=/root
# Learning framework to use (e.g. rl_games, rsl_rl, sb3, skrl, robomimic, none)
# no specification installs all
LEARNING_FRAMEWORK=""
10 changes: 9 additions & 1 deletion docker/Dockerfile.base
Original file line number Diff line number Diff line change
@@ -26,9 +26,17 @@ ENV ISAACSIM_ROOT_PATH=${ISAACSIM_ROOT_PATH_ARG}
# Path to the Isaac Lab directory
ARG ISAACLAB_PATH_ARG
ENV ISAACLAB_PATH=${ISAACLAB_PATH_ARG}
# Learning framework to install
ARG ISAACLAB_LEARNING_FRAMEWORK_ARG
ENV ISAACLAB_LEARNING_FRAMEWORK=${ISAACLAB_LEARNING_FRAMEWORK_ARG}
# Home dir of docker user, typically '/root'
ARG DOCKER_USER_HOME_ARG
ENV DOCKER_USER_HOME=${DOCKER_USER_HOME_ARG}
# Create a user based on the UID and GID passed as build args
ARG USER_ID_ARG
ENV USER_ID=${USER_ID_ARG}
ARG GROUP_ID_ARG
ENV GROUP_ID=${GROUP_ID_ARG}

# Set environment variables
ENV LANG=C.UTF-8
@@ -82,7 +90,7 @@ RUN touch /bin/nvidia-smi && \
# installing Isaac Lab dependencies
# use pip caching to avoid reinstalling large packages
RUN --mount=type=cache,target=${DOCKER_USER_HOME}/.cache/pip \
${ISAACLAB_PATH}/isaaclab.sh --install
${ISAACLAB_PATH}/isaaclab.sh --install ${ISAACLAB_LEARNING_FRAMEWORK}

# aliasing isaaclab.sh and python for convenience
RUN echo "export ISAACLAB_PATH=${ISAACLAB_PATH}" >> ${HOME}/.bashrc && \
12 changes: 11 additions & 1 deletion docker/container.py
Original file line number Diff line number Diff line change
@@ -25,6 +25,12 @@ def parse_cli_args() -> argparse.Namespace:

# We have to create separate parent parsers for common options to our subparsers
parent_parser = argparse.ArgumentParser(add_help=False)
parent_parser.add_argument(
"--project",
nargs="?",
default="isaac-lab",
help="Optional project name to be used for the container.",
)
parent_parser.add_argument(
"profile", nargs="?", default="base", help="Optional container profile specification. Example: 'base' or 'ros'."
)
@@ -90,7 +96,11 @@ def main(args: argparse.Namespace):

# creating container interface
ci = ContainerInterface(
context_dir=Path(__file__).resolve().parent, profile=args.profile, yamls=args.files, envs=args.env_files
context_dir=Path(__file__).resolve().parent,
profile=args.profile,
project_name=args.project,
yamls=args.files,
envs=args.env_files,
)

print(f"[INFO] Using container profile: {ci.profile}")
13 changes: 9 additions & 4 deletions docker/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -61,6 +61,8 @@ x-default-isaac-lab-volumes: &default-isaac-lab-volumes
x-default-isaac-lab-environment: &default-isaac-lab-environment
- ISAACSIM_PATH=${DOCKER_ISAACLAB_PATH}/_isaac_sim
- OMNI_KIT_ALLOW_ROOT=1
- UID=${USER_ID}
- GID=${GROUP_ID}

x-default-isaac-lab-deploy: &default-isaac-lab-deploy
resources:
@@ -84,8 +86,11 @@ services:
- ISAACSIM_ROOT_PATH_ARG=${DOCKER_ISAACSIM_ROOT_PATH}
- ISAACLAB_PATH_ARG=${DOCKER_ISAACLAB_PATH}
- DOCKER_USER_HOME_ARG=${DOCKER_USER_HOME}
image: isaac-lab-base
container_name: isaac-lab-base
- ISAACLAB_LEARNING_FRAMEWORK_ARG=${ISAACLAB_LEARNING_FRAMEWORK}
- USER_ID_ARG=${USER_ID}
- GROUP_ID_ARG=${GROUP_ID}
image: ${COMPOSE_PROJECT_NAME}-base
container_name: ${COMPOSE_PROJECT_NAME}-base
environment: *default-isaac-lab-environment
volumes: *default-isaac-lab-volumes
network_mode: host
@@ -110,8 +115,8 @@ services:
# avoid a warning message when building only the base profile
# with the .env.base file
- ROS2_APT_PACKAGE=${ROS2_APT_PACKAGE:-NONE}
image: isaac-lab-ros2
container_name: isaac-lab-ros2
image: ${COMPOSE_PROJECT_NAME}-ros2
container_name: ${COMPOSE_PROJECT_NAME}-ros2
environment: *default-isaac-lab-environment
volumes: *default-isaac-lab-volumes
network_mode: host
10 changes: 8 additions & 2 deletions docker/utils/container_interface.py
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@ def __init__(
self,
context_dir: Path,
profile: str = "base",
project_name: str = "isaac-lab",
yamls: list[str] | None = None,
envs: list[str] | None = None,
statefile: StateFile | None = None,
@@ -54,12 +55,17 @@ def __init__(
# Silently correct from isaaclab to base, because isaaclab is a commonly passed arg
# but not a real profile
self.profile = "base"
self.project_name = project_name

self.container_name = f"isaac-lab-{self.profile}"
self.image_name = f"isaac-lab-{self.profile}:latest"
self.container_name = f"{self.project_name}-{self.profile}"
self.image_name = f"{self.project_name}-{self.profile}:latest"

# keep the environment variables from the current environment
self.environ = os.environ
self.environ["COMPOSE_PROJECT_NAME"] = f"{self.project_name}"
# set user id and group id for the container
self.environ["USER_ID"] = str(os.getuid())
self.environ["GROUP_ID"] = str(os.getgid())

# resolve the image extension through the passed yamls and envs
self._resolve_image_extension(yamls, envs)

0 comments on commit 82de109

Please sign in to comment.