Skip to content

Commit

Permalink
feat(docker): fix CUDA compile on devel image and improve run.sh (aut…
Browse files Browse the repository at this point in the history
…owarefoundation#4849)

* modular containers PR phase1

Signed-off-by: Oguz <[email protected]>

* style(pre-commit): autofix

* add download artifacts to devel and runtime image

Signed-off-by: Oguz <[email protected]>

* Update docker/build.sh

Co-authored-by: Yutaka Kondo <[email protected]>

* style(pre-commit): autofix

* build from temp source directory and remove dangling images

Signed-off-by: Oguz Ozturk <[email protected]>

* Revert "build from temp source directory and remove dangling images"

This reverts commit c66a1dd.

* build containers from temp source and remove dangling images

Signed-off-by: Oguz Ozturk <[email protected]>

* style(pre-commit): autofix

* add vcs pull to update

Signed-off-by: Oguz Ozturk <[email protected]>

* style(pre-commit): autofix

---------

Signed-off-by: Oguz <[email protected]>
Signed-off-by: Oguz Ozturk <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Yutaka Kondo <[email protected]>
  • Loading branch information
3 people authored Jun 14, 2024
1 parent f84afce commit 4e7f539
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 36 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ capture/

# Node.js
node_modules/

# Docker build
docker/src
4 changes: 2 additions & 2 deletions ansible/playbooks/openadkit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
when: module == 'base'
- role: autoware.dev_env.kisak_mesa
when: module == 'base'
- role: autoware.dev_env.pacmod
when: module == 'base'
- role: autoware.dev_env.build_tools
when: module == 'all' and install_devel=='y'

Expand All @@ -34,8 +36,6 @@
when: (module == 'perception-localization' or module == 'all') and prompt_install_nvidia=='y'
- role: autoware.dev_env.tensorrt
when: (module == 'perception-localization' or module == 'all') and prompt_install_nvidia=='y'
- role: autoware.dev_env.pacmod
when: module == 'planning-control' or module == 'perception-localization' or module == 'all'

# Development environment
- role: autoware.dev_env.dev_tools
Expand Down
4 changes: 1 addition & 3 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ ENV CCACHE_DIR="/root/.ccache"
RUN --mount=type=ssh \
./setup-dev-env.sh -y --module all ${SETUP_ARGS} --no-cuda-drivers openadkit \
&& pip uninstall -y ansible ansible-core \
&& apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* "$HOME"/.cache \
&& find / -name 'libcu*.a' -delete \
&& find / -name 'libnv*.a' -delete
&& apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* "$HOME"/.cache

# Install rosdep dependencies
COPY --from=src-imported /rosdep-all-depend-packages.txt /tmp/rosdep-all-depend-packages.txt
Expand Down
27 changes: 27 additions & 0 deletions docker/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,19 @@ load_env() {
fi
}

# Clone repositories
clone_repositories() {
cd "$WORKSPACE_ROOT"
if [ ! -d "docker/src" ]; then
mkdir -p docker/src
vcs import docker/src <autoware.repos
else
echo "Source directory already exists. Updating repositories..."
vcs import docker/src <autoware.repos
vcs pull docker/src
fi
}

# Build images
build_images() {
# https://github.com/docker/buildx/issues/484
Expand All @@ -119,18 +132,32 @@ build_images() {
--set "*.args.BASE_IMAGE=$base_image" \
--set "*.args.SETUP_ARGS=$setup_args" \
--set "*.args.LIB_DIR=$lib_dir" \
--set "base.tags=ghcr.io/autowarefoundation/autoware:latest-base" \
--set "devel.tags=ghcr.io/autowarefoundation/autoware:latest-devel$image_name_suffix" \
--set "prebuilt.tags=ghcr.io/autowarefoundation/autoware:latest-prebuilt$image_name_suffix" \
--set "runtime.tags=ghcr.io/autowarefoundation/autoware:latest-runtime$image_name_suffix" \
"${targets[@]}"
set +x
}

# Remove temporary source directory
remove_tmp_src() {
rm -rf "$WORKSPACE_ROOT/docker/src"
}

# Remove dangling images
remove_dangling_images() {
docker image prune -f
}

# Main script execution
parse_arguments "$@"
set_cuda_options
set_build_options
set_platform
set_arch_lib_dir
load_env
clone_repositories
build_images
remove_tmp_src
remove_dangling_images
9 changes: 8 additions & 1 deletion docker/docker-bake.hcl
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
group "default" {
targets = ["prebuilt", "devel", "runtime"]
targets = ["base", "prebuilt", "devel", "runtime"]
}

// For docker/metadata-action
target "docker-metadata-action-base" {}
target "docker-metadata-action-prebuilt" {}
target "docker-metadata-action-devel" {}
target "docker-metadata-action-runtime" {}

target "base" {
inherits = ["docker-metadata-action-base"]
dockerfile = "docker/Dockerfile"
target = "base"
}

target "prebuilt" {
inherits = ["docker-metadata-action-prebuilt"]
dockerfile = "docker/Dockerfile"
Expand Down
81 changes: 51 additions & 30 deletions docker/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set -e
# Define terminal colors
RED='\033[0;31m'
GREEN='\033[0;32m'
# BLUE='\033[0;34m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color

SCRIPT_DIR=$(readlink -f "$(dirname "$0")")
Expand All @@ -29,17 +29,17 @@ DEFAULT_LAUNCH_CMD="ros2 launch autoware_launch autoware.launch.xml map_path:=/a
# Function to print help message
print_help() {
echo -e "\n------------------------------------------------------------"
echo -e "${RED}Note:${NC} The --map-path option is mandatory if not custom launch command given. Please provide exact path to the map files."
echo -e "${RED}Note:${NC} The --map-path option is mandatory for the runtime. For development environment with shell access, use --devel option."
echo -e " Default launch command: ${GREEN}${DEFAULT_LAUNCH_CMD}${NC}"
echo -e "------------------------------------------------------------"
echo -e "${RED}Usage:${NC} run.sh [OPTIONS] [LAUNCH_CMD](optional)"
echo -e "Options:"
echo -e " ${GREEN}--help/-h${NC} Display this help message"
echo -e " ${GREEN}--map-path${NC} Specify to mount map files into /autoware_map (mandatory if no custom launch command is provided)"
echo -e " ${GREEN}--map-path${NC} Specify to mount map files into /autoware_map (mandatory for runtime)"
echo -e " ${GREEN}--devel${NC} Launch the latest Autoware development environment with shell access"
echo -e " ${GREEN}--workspace${NC} (--devel only)Specify the directory to mount into /workspace, by default it uses current directory (pwd)"
echo -e " ${GREEN}--no-nvidia${NC} Disable NVIDIA GPU support"
echo -e " ${GREEN}--devel${NC} Use the latest development version of Autoware"
echo -e " ${GREEN}--headless${NC} Run Autoware in headless mode (default: false)"
echo -e " ${GREEN}--workspace${NC} Specify to mount the workspace into /workspace"
echo ""
}

Expand Down Expand Up @@ -87,37 +87,48 @@ parse_arguments() {
done
}

# Set image and workspace variables
# Set the docker image and workspace variables
set_variables() {
# Check if map path is provided for default launch command
if [ "$MAP_PATH" == "" ] && [ "$LAUNCH_CMD" == "" ]; then
print_help
exit 1
fi
if [ "$option_devel" = "true" ]; then
# Set image based on option
IMAGE="ghcr.io/autowarefoundation/autoware:latest-devel"

# Mount map path if provided
MAP="-v ${MAP_PATH}:/autoware_map:ro"
# Set workspace path, if not provided use the current directory
if [ "$WORKSPACE_PATH" = "" ]; then
WORKSPACE_PATH=$(pwd)
fi
WORKSPACE="-v ${WORKSPACE_PATH}:/workspace"

# Set workspace path if provided and login with local user
if [ "$WORKSPACE_PATH" != "" ]; then
# Set user ID and group ID to match the local user
USER_ID="-e LOCAL_UID=$(id -u) -e LOCAL_GID=$(id -g) -e LOCAL_USER=$(id -un) -e LOCAL_GROUP=$(id -gn)"
WORKSPACE="-v ${WORKSPACE_PATH}:/workspace"
fi

# Set default launch command if not provided
if [ "$LAUNCH_CMD" == "" ]; then
if [ "$WORKSPACE_PATH" != "" ]; then
LAUNCH_CMD="/bin/bash"
else
LAUNCH_CMD=${DEFAULT_LAUNCH_CMD}
# Set map path
if [ "$MAP_PATH" != "" ]; then
MAP="-v ${MAP_PATH}:/autoware_map:ro"
fi
fi

# Set image based on option
if [ "$option_devel" == "true" ]; then
IMAGE="ghcr.io/autowarefoundation/autoware:latest-devel"
# Set launch command
if [ "$LAUNCH_CMD" = "" ]; then
LAUNCH_CMD="/bin/bash"
fi
else
# Set image based on option
IMAGE="ghcr.io/autowarefoundation/autoware:latest-runtime"

# Set map path
if [ "$MAP_PATH" = "" ]; then
echo -e "\n------------------------------------------------------------"
echo -e "${RED}Note:${NC} The --map-path option is mandatory for the runtime. For development environment with shell access, use --devel option."
echo -e "------------------------------------------------------------"
exit 1
else
MAP="-v ${MAP_PATH}:/autoware_map:ro"
fi

# Set default launch command if not provided
if [ "$LAUNCH_CMD" = "" ]; then
LAUNCH_CMD=${DEFAULT_LAUNCH_CMD}
fi
fi
}

Expand Down Expand Up @@ -148,10 +159,20 @@ main() {
set_gpu_flag
set_x_display

echo -e "${GREEN}\n-----------------------LAUNCHING CONTAINER-----------------------"
if [ "$option_devel" = "true" ]; then
echo -e "${GREEN}-----------------------------------------------------------------${NC}"
echo -e "${BLUE}Launching Autoware development environment${NC}"
else
echo -e "${GREEN}-----------------------------------------------------------------${NC}"
echo -e "${GREEN}Launching Autoware${NC}"
fi
echo -e "${GREEN}IMAGE:${NC} ${IMAGE}"
echo -e "${GREEN}MAP PATH(mounted):${NC} ${MAP_PATH}:/autoware_map"
echo -e "${GREEN}WORKSPACE(mounted):${NC} ${WORKSPACE_PATH}:/workspace"
if [ "$option_devel" = "true" ]; then
echo -e "${GREEN}WORKSPACE PATH(mounted):${NC} ${WORKSPACE_PATH}:/workspace"
fi
if [ "$MAP_PATH" != "" ]; then
echo -e "${GREEN}MAP PATH(mounted):${NC} ${MAP_PATH}:/autoware_map"
fi
echo -e "${GREEN}LAUNCH CMD:${NC} ${LAUNCH_CMD}"
echo -e "${GREEN}-----------------------------------------------------------------${NC}"

Expand Down

0 comments on commit 4e7f539

Please sign in to comment.