Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(docker): fix CUDA compile on devel image and improve run.sh #4849

Merged
merged 11 commits into from
Jun 14, 2024
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
oguzkaganozt marked this conversation as resolved.
Show resolved Hide resolved
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 \
oguzkaganozt marked this conversation as resolved.
Show resolved Hide resolved
&& 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" \
oguzkaganozt marked this conversation as resolved.
Show resolved Hide resolved
--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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oguzkaganozt may I please check with you what is the purpose of this step?
In the Dockerfile we are still copying the src that is under autoware not the src that is under autoware/docker.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your review. I think it is a mistake and I fix it by #4894.

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 @@
# 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 @@
# 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 @@
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,17 +159,27 @@
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}"

# Launch the container
set -x
docker run -it --rm --net=host ${GPU_FLAG} ${USER_ID} ${MOUNT_X} \
-e XAUTHORITY=${XAUTHORITY} -e XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR -e NVIDIA_DRIVER_CAPABILITIES=all -v /etc/localtime:/etc/localtime:ro \

Check warning on line 182 in docker/run.sh

View workflow job for this annotation

GitHub Actions / spell-check-differential

Unknown word (localtime)

Check warning on line 182 in docker/run.sh

View workflow job for this annotation

GitHub Actions / spell-check-differential

Unknown word (localtime)
${WORKSPACE} ${MAP} ${IMAGE} \
${LAUNCH_CMD}
}
Expand Down
Loading