From 52e0b40663857c71135889fd9c76c5c9086abbfc Mon Sep 17 00:00:00 2001 From: John Ericksen Date: Sun, 11 Jul 2021 20:18:18 -0600 Subject: [PATCH] Copied solution docker file from srcp2 along with build_comp_image.bash entry point with required solution files and made necessary changes to build our submission. --- docker/solution/build_comp_image.bash | 154 ++++++++++++++++++ .../solution/container/config_solution.yaml | 0 .../container/solution-entrypoint.bash | 22 +++ docker/solution/solution.dockerfile | 79 +++++++++ 4 files changed, 255 insertions(+) create mode 100755 docker/solution/build_comp_image.bash create mode 100644 docker/solution/container/config_solution.yaml create mode 100644 docker/solution/container/solution-entrypoint.bash create mode 100644 docker/solution/solution.dockerfile diff --git a/docker/solution/build_comp_image.bash b/docker/solution/build_comp_image.bash new file mode 100755 index 0000000..f7e4c9c --- /dev/null +++ b/docker/solution/build_comp_image.bash @@ -0,0 +1,154 @@ +#! /usr/bin/env bash +# +# Space Robotics Competition 2: NASA JSC +# Copyright (c), 2019-2021 NASA-JSC. All Rights Reserved +# Unauthorized distribution strictly prohibited +# +# +pushd `pwd` > /dev/null 2>&1 +cd $(cd -P -- "$(dirname -- "$0")" && pwd -P) +source "../../srcp2-competitors/docker/scripts/srcp2_setup.bash" + +# ---------------------------------------------------------------------------------------------------------------------- +# CONSTANTS AND NAMES +# +BUILD_CONTEXT=$( cd "../../"; pwd) # the repo root +DOCKER_BUILD_ARGS="" +# +BUILD_LOG="/tmp/docker-build-log.txt" +OUTPUT_LOG=" > $BUILD_LOG 2>&1" +VERBOSE=0 +# Solution +DOCKER_SUBMIT_REPO="scheducation/srcp2_comp_solutions" +DOCKER_SUBMIT_TAG="swarmathon" + +# Base Line +DOCKER_BASE_REPO="scheducation/srcp2_comp" +DOCKER_BASE_TAG="final_competitor" +# + + +# ---------------------------------------------------------------------------------------------------------------------- +# UTILITY FUNCTIONS +# + +function help(){ + echo -e " + ${B}Synopsis:${rs} + + Build the the solution docker images this project relies upon. + By default, this will build everything, you can specify + which image sets you build + + ${B}Options:${rs} + + ${B}-h | --help${rs} + print this message and quit + + ${B}-n | --new${rs} + build any clean (--no-cache). This forces total rebuild and + will be slow! + + ${B}-t | --team${rs} + the Team Name Tag in the submision docker hub repo if not + provided the defaults to team_omega a developer test image + + ${B}-v | --verbose${rs} + build verbose, show all docker outputs to stdout +" +} + +function test_build_ok() { + if [ $1 -ne 0 ]; then + echo -e "$echo_error could not build image for ${r}$2${rs}" + echo + if [ $VERBOSE -eq 0 ]; then + cat $3 + fi + return $1 + else + echo -e "$echo_ok completed build ${b}$2${rs}" + return 0 + fi +} + +# ---------------------------------------------------------------------------------------------------------------------- +# +function build_solution_images() { + + tag="${DOCKER_SUBMIT_REPO}:${DOCKER_SUBMIT_TAG}" + echo -e "$echo_info building ${b}$tag${rs}" + docker build ${DOCKER_BUILD_ARGS} \ + --file solution.dockerfile \ + --tag $tag \ + --build-arg base_image=${DOCKER_BASE_REPO}:${DOCKER_BASE_TAG} \ + \ + $BUILD_CONTEXT + + if ! test_build_ok $? $tag $BUILD_LOG; then return 1; fi + echo + + return 0 +} + + +# ---------------------------------------------------------------------------------------------------------------------- +# MAIN PROGRAM + +echo_header + +# long opts to short opts +for arg in "$@"; do + shift + case "$arg" in + "--help") set -- "$@" "-h" ;; + "--team") set -- "$@" "-t" ;; + "--new") set -- "$@" "-n" ;; + "--verbose") set -- "$@" "-v" ;; + *) set -- "$@" "$arg" + esac +done + +OPTIND=1 +while getopts hnvt: arg; do + case $arg in + + h) + help + quit_with_popd 0 + ;; + n) + DOCKER_BUILD_ARGS="--no-cache" + echo -e "$echo_info Forcing from-scratch rebuild. This will be slow!" + ;; + v) + VERBOSE=1 + echo -e "$echo_info Building in verbose mode" + ;; + + t) + if [ -z ${OPTARG} ]; then + DOCKER_SUBMIT_TAG=$DOCKER_SUBMIT_TAG + else + DOCKER_SUBMIT_TAG=$OPTARG + fi + ;; + *) + echo -e "$echo_error Input option \"$arg\" not supported at this time. see '-h' for help" + quit_with_popd 1 + ;; + esac +done + +echo -e "$echo_info Build Parameters:" +echo -e "$echo_info \tDocker build context = $(cd $BUILD_CONTEXT; pwd)" +echo -e "$echo_info \tBuild Log = $BUILD_LOG" +echo + +if ! build_solution_images; then + quit_with_popd $?; +fi +echo -e "$echo_info Solution Image Detail : ${b}${DOCKER_SUBMIT_REPO}:${DOCKER_SUBMIT_TAG}${rs}" +echo -e "\n$echo_ok Solution Image Built." + +quit_with_popd 0 \ No newline at end of file diff --git a/docker/solution/container/config_solution.yaml b/docker/solution/container/config_solution.yaml new file mode 100644 index 0000000..e69de29 diff --git a/docker/solution/container/solution-entrypoint.bash b/docker/solution/container/solution-entrypoint.bash new file mode 100644 index 0000000..b5d0a43 --- /dev/null +++ b/docker/solution/container/solution-entrypoint.bash @@ -0,0 +1,22 @@ +#! /usr/bin/env bash +# +# Space Robotics Competition 2: NASA JSC +# Copyright (c), 2019-2021 NASA-JSC. All Rights Reserved +# + +# system setups +source "/opt/ros/$ROS_DISTRO/setup.bash" +source "/usr/share/gazebo/setup.sh" + +# set up srcp2 extras +source ~/scripts/srcp2_setup.bash + +# Source ROS Worspaces +source $HOME/ros_workspace/install/setup.bash +source $HOME/cmp_workspace/install/setup.bash + +roslaunch scoot scoot.launch "mode:=man" "name:=small_scout_1" +# run example solution +rosrun scoot repl.py + +exit $? diff --git a/docker/solution/solution.dockerfile b/docker/solution/solution.dockerfile new file mode 100644 index 0000000..16feb4e --- /dev/null +++ b/docker/solution/solution.dockerfile @@ -0,0 +1,79 @@ +# +# Space Robotics Challenge 2: NASA JSC +# Final Round +# +# Copyright (c), 2019-2022 NASA-JSC. All Rights Reserved +# Unauthorized Distribution Strictly Prohibited +# +ARG base_image="final_competitor" +FROM ${base_image} +# ******************************************* +# ** COMPETITOR CUSTOMIZATION THIS LIST ** +# ** DELIMITED ITEMS WITH SPACE CHARACTER! ** + +# OS Level Apps (all will be installed root permissions) +# These boxes and figlet, flask are optional are just here as examples +ARG os_apps="apt-utils \ + build-essential \ + ros-noetic-tf \ + ros-noetic-angles \ + ros-noetic-gazebo-msgs \ + ros-noetic-robot-localization \ + ros-noetic-stereo-image-proc \ + ros-noetic-gazebo-ros \ + ros-noetic-geometry2 \ + python3-catkin-tools \ + python3-osrf-pycommon \ + python3 \ + python3-pip" + +# Python Plugins +ARG py_apps="ipython future imutils scipy" +# ** COMPETITOR CUSTOMIZATION THIS LIST DONE ** +# ********************************************* + +ARG enduser_name="srcp2" + +USER root +# The apts +RUN apt-get update && apt-get install -y; \ + for app in $req_os_apps; do \ + apt-get install $app -y; \ + done; +# The python +RUN for py in $req_py_apps; do \ + pip3 install $py; \ + done; + +# Make Home Folder Tree Proper Permissions ** THESE ARE REQUIRED ** +# copy in the "binary" & src versions of all the ROS packages +# User Level +USER ${enduser_name} +RUN mkdir -p -v /home/$enduser_name/cmp_workspace +COPY --chown=${enduser_name}:${enduser_name} ./srcp2-competitors/cmp_workspace/install ${HOME}/cmp_workspace/install/ +COPY --chown=${enduser_name}:${enduser_name} . ${HOME}/cmp_workspace/src + +# ****************************************** +# ** COMPETITOR CUSTOMIZATION HERE! ** +# The Competitor Can Add More Docker Customization Commands Here +# Refer to Docker Documentation for this. +# RUN zzz +# COPY zzz +# +# ****************************************** + +# Root Level Permissions +USER root +RUN chown -R "${enduser_name}:${enduser_name}" "/home/${enduser_name}";\ + ls -la "/home/${enduser_name}" + +# User Level Permissions +USER ${enduser_name} + +# Entrypoint and Config Copies ** THESE ARE REQUIRED ** +COPY docker/solution/container/solution-entrypoint.bash ${HOME}/scripts +COPY docker/solution/container/config_solution.yaml ${HOME}/config + +# starting conditions (note: CMD not ENTRYPOINT for --interactive override) +ENV SOLUTION_ENTRYPOINT="${HOME}/scripts/solution-entrypoint.bash" +CMD ${SOLUTION_ENTRYPOINT} \ No newline at end of file