diff --git a/.env b/.env index aab2e15..252eaef 100644 --- a/.env +++ b/.env @@ -8,9 +8,9 @@ HOST_HOME="${HOST_HOME:-/home/coresense/}" HOST_WORKSPACE_FOLDER="${HOST_WORKSPACE_FOLDER:-${HOST_HOME}/workspaces/k_ws/}" CONTAINER_USER_HOME="/home/ros/" -CONTAINER_DEV_WORKSPACE="/workspaces/mesh_ws/" -DYNAMIC_MESH_GEN_SRC_HOST_DIR="${HOST_WORKSPACE_FOLDER}/src/dynamic_mesh/" -DYNAMIC_MESH_GEN_SRC_CONTAINER_DIR="${CONTAINER_DEV_WORKSPACE}/src/dynamic_mesh/" +DYNAMIC_MESH_TARGET_WS="/workspaces/mesh_ws/" +DYNAMIC_MESH_SRC_SUBDIR="src/dynamic_mesh/" +DYNAMIC_MESH_SRC_CONTAINER_DIR="${DYNAMIC_MESH_TARGET_WS}/${DYNAMIC_MESH_SRC_SUBDIR}" DISPLAY=${DISPLAY:-"coresense-nuc:1.0"} diff --git a/build.docker-compose.yaml b/build.docker-compose.yaml new file mode 100644 index 0000000..69e43ea --- /dev/null +++ b/build.docker-compose.yaml @@ -0,0 +1,7 @@ + +services: + + dynamic_mesh_gen: + extends: + file: ./container/docker_compose/build.dynamic_mesh.docker-compose.yaml + service: dynamic_mesh_gen diff --git a/container/docker_compose/build.Dockerfile b/container/docker_compose/build.Dockerfile new file mode 100644 index 0000000..fc07821 --- /dev/null +++ b/container/docker_compose/build.Dockerfile @@ -0,0 +1,35 @@ +########################################### +# docker build +# -t user/repo:tag # assign user, repo and tag. if tag is omitted, will default to 'latest' +# --rm # (optional) clean up intermediate images +# --build-context name=location +# --build-arg name=value +# -f Dockerfilename . # build from file with context (. is current pwd) +# +# docker build -t erf2025.demo/dynamic_mesh_gen --build-arg DYNAMIC_MESH_TARGET_WS=/workspaces/dynamic_mesh_ws --build-arg DYNAMIC_MESH_SRC_SUBDIR=src/dynamic_mesh -f build.Dockerfile . +# +########################################### +# docker push user/repo:tag +########################################### + +# hadolint global ignore=DL3004 + +FROM scancontrol:latest + +ARG DYNAMIC_MESH_TARGET_WS="/CHANGEME_ws" +ARG DYNAMIC_MESH_SRC_SUBDIR="src/dynamic_mesh" + +USER ros + +RUN sudo mkdir -p "${DYNAMIC_MESH_TARGET_WS}/${DYNAMIC_MESH_SRC_SUBDIR}" && sudo chown -R ros:ros "${DYNAMIC_MESH_TARGET_WS}" + +WORKDIR ${DYNAMIC_MESH_TARGET_WS}/${DYNAMIC_MESH_SRC_SUBDIR} + +COPY ${DYNAMIC_MESH_SRC_SUBDIR} ${DYNAMIC_MESH_TARGET_WS}/${DYNAMIC_MESH_SRC_SUBDIR} + +WORKDIR ${DYNAMIC_MESH_TARGET_WS} + +# Remember to source ROS here if the script requires ROS variables! +RUN [ "/bin/bash", "-c", "source /opt/ros/humble/setup.sh && ${DYNAMIC_MESH_TARGET_WS}/${DYNAMIC_MESH_SRC_SUBDIR}/container/docker_compose/scripts/build_app.sh -t ${DYNAMIC_MESH_TARGET_WS}" ] + +ENTRYPOINT [ "/bin/bash", "-c", "tail -f /dev/null" ] diff --git a/container/docker_compose/build.dynamic_mesh.docker-compose.yaml b/container/docker_compose/build.dynamic_mesh.docker-compose.yaml new file mode 100644 index 0000000..225b0c3 --- /dev/null +++ b/container/docker_compose/build.dynamic_mesh.docker-compose.yaml @@ -0,0 +1,37 @@ + +services: + dynamic_mesh_gen: + + build: + context: ${HOST_WORKSPACE_FOLDER:-/CHANGEMEws} + args: + DYNAMIC_MESH_TARGET_WS: ${DYNAMIC_MESH_TARGET_WS:-/CHANGEMEcached_target_ws} + DYNAMIC_MESH_SRC_SUBDIR: ${DYNAMIC_MESH_SRC_SUBDIR:-src/CHANGEMEcached} + dockerfile: ${HOST_WORKSPACE_FOLDER}/${DYNAMIC_MESH_SRC_SUBDIR}/container/docker_compose/build.Dockerfile + + image: erf2025.demo/dynamic_mesh_c + container_name: dynamic_mesh_gen_c + + environment: + DEV_WORKSPACE: ${DYNAMIC_MESH_TARGET_WS:-/CHANGEMEcached_target_ws} + + env_file: + - path: variables.env + required: true # default + + network_mode: host + + # entrypoint: tail -f /dev/null + entrypoint: ${DYNAMIC_MESH_SRC_CONTAINER_DIR}/container/docker_compose/scripts/run_app.sh -t ${DYNAMIC_MESH_TARGET_WS} + + working_dir: ${DYNAMIC_MESH_TARGET_WS:-/CHANGEMEwrkdir} + + user: ${PUID:-1000}:${PGID:-1000} + + ipc: host + + mem_limit: 12gb # TODO confirm this + + privileged: true + + tty: true diff --git a/container/docker_compose/scripts/build_app.sh b/container/docker_compose/scripts/build_app.sh index 0d516a7..ce8402e 100755 --- a/container/docker_compose/scripts/build_app.sh +++ b/container/docker_compose/scripts/build_app.sh @@ -1,11 +1,35 @@ -#! /bin/bash +#!/bin/bash -cd "${DEV_WORKSPACE}" || exit +SOURCE_WS="$DEV_WORKSPACE" -# Auto-build everything in the background: -# export ROSDEP_SKIP_KEYS=snp_msgs -# "${DEV_WORKSPACE}"/src/dynamic_mesh/setup.sh -t "${DEV_WORKSPACE}" +USAGE=" +build.sh usage + +-t \ +SOURCE_WS: the location of the workspace you wish to cache inside an image + +" + +while getopts t:h flag; do + case "${flag}" in + t) SOURCE_WS=${OPTARG} ;; + h) + echo -e "${USAGE}" + exit 0 + ;; + *) + echo 'Unknown parameter' >&2 + echo 'use -h for usage information' + exit 1 + ;; + esac +done +echo "Target workspace: ${SOURCE_WS}" + +cd "${SOURCE_WS}" || exit + +# Auto-build everything in the background: source /opt/ros/humble/setup.bash # install dependencies diff --git a/container/docker_compose/scripts/run_app.sh b/container/docker_compose/scripts/run_app.sh index 712641c..934114c 100755 --- a/container/docker_compose/scripts/run_app.sh +++ b/container/docker_compose/scripts/run_app.sh @@ -1,9 +1,36 @@ #! /bin/bash -cd "${DEV_WORKSPACE}" || exit +SOURCE_WS="$DEV_WORKSPACE" + +USAGE=" +build.sh usage + +-t \ +SOURCE_WS: the location of the workspace you wish to cache inside an image + +" + +while getopts t:h flag; do + case "${flag}" in + t) SOURCE_WS=${OPTARG} ;; + h) + echo -e "${USAGE}" + exit 0 + ;; + *) + echo 'Unknown parameter' >&2 + echo 'use -h for usage information' + exit 1 + ;; + esac +done + +echo "Target workspace: ${SOURCE_WS}" + +cd "${SOURCE_WS}" || exit source ~/.bashrc -source install/setup.bash +source "${SOURCE_WS}/install/setup.bash" # launch processes here