-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Tomoya.Fujita <[email protected]>
- Loading branch information
1 parent
3d0a48f
commit 9f8822c
Showing
2 changed files
with
204 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Build: | ||
# docker build --rm -f ./docker/Dockerfile --build-arg="ROS_DISTRO=rolling" --build-arg="COLCON_WS=/root/colcon_ws" -t <user_name>/ros2ai:rolling . | ||
# | ||
# Usage: | ||
# docker pull <user_name>/ros2ai:rolling | ||
|
||
# An ARG declared before a FROM is outside of a build stage, | ||
# so it can’t be used in any instruction after a FROM. | ||
# To use the default value of an ARG declared before the first FROM | ||
# use an ARG instruction without a value inside of a build stage: | ||
ARG ROS_DISTRO=rolling | ||
ARG COLCON_WS=/root/colcon_ws | ||
|
||
FROM ros:${ROS_DISTRO} | ||
|
||
LABEL maintainer="Tomoya Fujita <[email protected]>" | ||
LABEL version="1.0" | ||
LABEL description="ros2ai ${ROS_DISTRO} docker image" | ||
|
||
ARG ROS_DISTRO | ||
ARG COLCON_WS | ||
|
||
SHELL ["/bin/bash","-c"] | ||
|
||
RUN mkdir -p ${COLCON_WS}/src | ||
COPY . ${COLCON_WS}/src/ros2ai/ | ||
|
||
# All apt-get commands start with an update, then install | ||
# and finally, a cache cleanup to keep the image size small. | ||
|
||
# Install packages | ||
RUN apt-get update \ | ||
&& apt-get upgrade -y \ | ||
&& apt-get install -y \ | ||
# Basic utilities just in case | ||
pip curl\ | ||
--no-install-recommends \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
RUN pip install openai | ||
|
||
# Build and source colcon workspace | ||
RUN cd $COLCON_WS \ | ||
&& source /opt/ros/$ROS_DISTRO/setup.bash \ | ||
&& colcon build --symlink-install --packages-select ros2ai | ||
|
||
# Add source environment in .bashrc | ||
RUN echo -n -e "\n" >> /root/.bashrc | ||
RUN echo "### ros2ai workspace setting" >> /root/.bashrc | ||
RUN echo "cd $COLCON_WS && source ./install/setup.bash" >> /root/.bashrc | ||
|
||
# Overwrite as environmental varialble so that entrypoint can rely on those | ||
# OPENAI_API_KEY should not be included here, that is required for the runtime | ||
ENV COLCON_WS=${COLCON_WS} | ||
ENV ROS_DISTRO=${ROS_DISTRO} | ||
#ENTRYPOINT ["/ros_entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
#!/bin/bash | ||
|
||
##################################################################### | ||
# This script builds, verifies and releases ros2ai docker images. | ||
##################################################################### | ||
|
||
################ | ||
# User Setting # | ||
################ | ||
|
||
DOCKERHUB_USERNAME="${DOCKERHUB_USERNAME:-tomoyafujita}" | ||
COLCON_WS="${COLCON_WS:-/root/colcon_ws}" | ||
|
||
ros_distros=( | ||
"humble" | ||
"iron" | ||
"rolling" | ||
) | ||
|
||
###################### | ||
# Options (defaults) # | ||
###################### | ||
|
||
build_image=false | ||
verify_image=false | ||
upload_image=false | ||
|
||
######################## | ||
# Function Definitions # | ||
######################## | ||
|
||
function print_usage() { | ||
echo "Usage: $0 [-b] [-v] [-u]" | ||
echo "Options(default):" | ||
echo " -b : build docker container images (default: false)" | ||
echo " -v : verify images to call ros2ai commands (default: false)" | ||
echo " -u : uploade images to DockerHub (default: false)" | ||
exit 1 | ||
} | ||
|
||
function exit_trap() { | ||
if [ $? != 0 ]; then | ||
echo "Command [$BASH_COMMAND] is failed" | ||
exit 1 | ||
fi | ||
} | ||
|
||
function check_dockerhub_setting () { | ||
trap exit_trap ERR | ||
echo "[${FUNCNAME[0]}]: checking dockerhub setting and configuration." | ||
if [ -z "$DOCKERHUB_USERNAME" ]; then | ||
echo "DOCKERHUB_USERNAME is not set." | ||
exit 1 | ||
fi | ||
# check if docker login succeeds | ||
docker login | ||
} | ||
|
||
function command_exist() { | ||
trap exit_trap ERR | ||
echo "[${FUNCNAME[0]}]: checking $1 command exists." | ||
if command -v "$1" >/dev/null 2>&1; then | ||
echo "$1 exists." | ||
return 0 | ||
else | ||
echo "Error: $1 not found." | ||
return 1 | ||
fi | ||
} | ||
|
||
function build_images() { | ||
trap exit_trap ERR | ||
echo "[${FUNCNAME[0]}]: building ros2ai docker container images." | ||
for distro in "${ros_distros[@]}"; do | ||
echo "----- $distro image building" | ||
docker build --rm -f ./docker/Dockerfile --build-arg="ROS_DISTRO=$distro" --build-arg="COLCON_WS=$COLCON_WS" -t $DOCKERHUB_USERNAME/ros2ai:$distro . | ||
done | ||
echo "----- all images successfully generated!!! -----" | ||
} | ||
|
||
function verify_images() { | ||
trap exit_trap ERR | ||
echo "[${FUNCNAME[0]}]: verifying ros2ai docker container images." | ||
for distro in "${ros_distros[@]}"; do | ||
echo "----- $distro image verifying" | ||
docker run -it --rm -e OPENAI_API_KEY=$OPENAI_API_KEY $DOCKERHUB_USERNAME/ros2ai:$distro \ | ||
bash -c "/ros_entrypoint.sh && source /root/.bashrc && cd $COLCON_WS && source ./install/setup.bash && $COLCON_WS/src/ros2ai/scripts/verification.sh" | ||
done | ||
echo "----- all images successfully verified!!! -----" | ||
} | ||
|
||
function upload_images() { | ||
trap exit_trap ERR | ||
echo "[${FUNCNAME[0]}]: uploading ros2ai docker container images." | ||
for distro in "${ros_distros[@]}"; do | ||
echo "----- $distro image uploading" | ||
# TODO@fujitatomoya: support multi-arch docker images | ||
docker push $DOCKERHUB_USERNAME/ros2ai:$distro | ||
done | ||
echo "----- all images successfully verified!!! -----" | ||
} | ||
|
||
######## | ||
# Main # | ||
######## | ||
|
||
# set the trap on error | ||
trap exit_trap ERR | ||
|
||
# parse command line options | ||
while getopts ":bvu" opt; do | ||
case $opt in | ||
b) | ||
build_image=true | ||
;; | ||
v) | ||
verify_image=true | ||
;; | ||
u) | ||
upload_image=true | ||
;; | ||
\?) | ||
echo "Invalid option: -$OPTARG" | ||
print_usage | ||
;; | ||
esac | ||
done | ||
shift $((OPTIND-1)) | ||
|
||
# check settings | ||
check_dockerhub_setting | ||
command_exist docker | ||
|
||
# building images | ||
if [ "$build_image" = true ]; then | ||
build_images | ||
fi | ||
|
||
# verifying images | ||
if [ "$verify_image" = true ]; then | ||
verify_images | ||
fi | ||
|
||
# upload images | ||
if [ "$upload_image" = true ]; then | ||
upload_images | ||
fi | ||
|
||
exit 0 |