From ca4713d56bd12a155cd9bc7111cd3050ae87695f Mon Sep 17 00:00:00 2001 From: David Kebler Date: Thu, 17 Oct 2024 16:17:59 -0700 Subject: [PATCH] refactored custom core processing, now uses a core directory in the /src entrpoint now uses exec to call the entrypoint command thus not spawing a subshell updated uci shell code and added /root/shell so to avoid constant warning about it missing. add /opt/bin to path in dockerfile --- .gitignore | 1 + Dockerfile.d/Dockerfile.tpl | 3 +++ Dockerfile.d/core.tpl | 7 +++++++ build | 17 ++++++++++++----- core/core.sh | 1 - core/rootfs/opt/bin/entrypoint | 6 ++---- core/rootfs/opt/env/run.env | 1 - core/rootfs/opt/lib/uci-shell | 2 ++ lib/build.lib | 8 ++++---- lib/cmds/try.sh | 2 +- test/src/core/run | 14 ++++++++++++++ test/src/rootfs/opt/env/run.env | 3 ++- 12 files changed, 48 insertions(+), 17 deletions(-) delete mode 100644 core/rootfs/opt/env/run.env create mode 100644 test/src/core/run diff --git a/.gitignore b/.gitignore index fbb4563..118ad9e 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ _opt/ .src TODO.md mnt/ +core/custom logs/ Dockerfile .env diff --git a/Dockerfile.d/Dockerfile.tpl b/Dockerfile.d/Dockerfile.tpl index 220db2b..41fa65d 100644 --- a/Dockerfile.d/Dockerfile.tpl +++ b/Dockerfile.d/Dockerfile.tpl @@ -16,6 +16,9 @@ ARG VERBOSE ARG REBUILD WORKDIR /build +# put /opt/bin in path permently +ENV PATH="/opt/bin:${PATH}" + # CORE RUN --mount=type=bind,source=./core,target=/build \ < /dev/null ) ]]; then rsync -aAru ${BUILD_SRC:-src}/ $BDIR/.src - rsync -aAru $BDIR/.src/$_env_dir/ $BDIR/core/$_env_dir > /dev/null 2>&1 else echo no rsync copying with cp /bin/cp -a ${BUILD_SRC:-src}/. $BDIR/.src > /dev/null 2>&1 - /bin/cp -a $BDIR/.src/rootfs/opt/env/. $BDIR/core/rootfs/opt/env > /dev/null 2>&1 fi ls -la $BDIR/.src/rootfs fi + + # create Dockerfile from template if ! source $BDIR/Dockerfile.d/create; then echo unable to create Dockerfile from template, aborting build @@ -291,7 +289,13 @@ fi EOF fi -[[ -f $BDIR/.src/custom-core.sh ]] && /bin/cp $BDIR/.src/custom-core.sh $BDIR/core/ +if [[ -d $BDIR/.src/core ]]; then + [[ -d "$BDIR/core/custom" ]] && rm -rf "$BDIR/core/custom" + echo adding the custom core directory to /custom in the core directory + /bin/cp -a "$BDIR/.src/core/." "$BDIR/core/custom" + rm -rf "$BDIR/.src/core/" + ls -la $BDIR/core/custom +fi pushd "$BDIR" > /dev/null || return 3 @@ -321,6 +325,9 @@ if [[ $TARGET == "private" ]]; then image_push -r $REPO $IMAGE_NAME fi +# cleanup +[[ -d "$BDIR/core/custom" ]] && rm -rf "$BDIR/core/custom" + } # if script was executed then call the function diff --git a/core/core.sh b/core/core.sh index 8242fa0..195722a 100644 --- a/core/core.sh +++ b/core/core.sh @@ -11,7 +11,6 @@ if [[ -f ./build.env ]]; then fi source $LIB_DIR/verbose.lib -[[ -f ./custom-core.sh ]] && echo "sourcing custom core script" && source "./custom-core.sh" echo appending pkg commands to core_run.env echo appending sourcing of $ENV_DIR/run.env if it exists cat <> /opt/core_run.env diff --git a/core/rootfs/opt/bin/entrypoint b/core/rootfs/opt/bin/entrypoint index 3ba57a3..5662718 100755 --- a/core/rootfs/opt/bin/entrypoint +++ b/core/rootfs/opt/bin/entrypoint @@ -1,10 +1,8 @@ #!/bin/bash +env > /tmp/passed.env source /opt/core_run.env cmd=$1 - -# [[ $DEVELOPMENT && $cmd == "${ENTRYPOINT_CMD:-start}" ]] && echo "development mode enabled, idling container" && cmd=idle - case "$cmd" in maphostid) @@ -34,7 +32,7 @@ cat | /bin/bash -l ;; ${ENTRYPOINT_CMD:-start}) shift 1 -/bin/bash -l -c '${ENTRYPOINT_CMD_PATH:-$BIN_DIR/${ENTRYPOINT_CMD:-start}} $@' $0 "$@" +exec /bin/bash -l -c '${ENTRYPOINT_CMD_PATH:-$BIN_DIR/${ENTRYPOINT_CMD:-start}} $@' $0 "$@" ;; *) echo "--- command passed to container: $* ---" diff --git a/core/rootfs/opt/env/run.env b/core/rootfs/opt/env/run.env deleted file mode 100644 index 9c10621..0000000 --- a/core/rootfs/opt/env/run.env +++ /dev/null @@ -1 +0,0 @@ -export DEFAULT_DIR=/opt/bin \ No newline at end of file diff --git a/core/rootfs/opt/lib/uci-shell b/core/rootfs/opt/lib/uci-shell index 412e5a0..d53c53d 100755 --- a/core/rootfs/opt/lib/uci-shell +++ b/core/rootfs/opt/lib/uci-shell @@ -25,5 +25,7 @@ else uci_bash_shell_install fi +mkdir /root/shell + echo "----------- uci shell install complete ------" diff --git a/lib/build.lib b/lib/build.lib index a437d61..d1d88e7 100755 --- a/lib/build.lib +++ b/lib/build.lib @@ -261,10 +261,10 @@ local src; local spath; local spaths # will determine if there are any minimal build source files/directories check_dir () { if - [ $(ls $1/packages/*system.pkgs 2> /dev/null) ] || \ - [ $(ls $1/packages/system/*.pkgs 2> /dev/null) ] || \ - [ -f $1/packages/repositories.sh ] || \ - [ -f $1/packages/packages.sh ] + [[ "$(ls $1/packages/*system.pkgs 2> /dev/null)" ]] || \ + [[ "$(ls $1/packages/system/*.pkgs 2> /dev/null)" ]] || \ + [[ -f $1/packages/repositories.sh ]] || \ + [[ -f $1/packages/packages.sh ]]; then _packages_=true return 0 diff --git a/lib/cmds/try.sh b/lib/cmds/try.sh index 1944370..6f1195d 100755 --- a/lib/cmds/try.sh +++ b/lib/cmds/try.sh @@ -85,7 +85,7 @@ try_container () { image=${image:-$IMAGE_NAME} if [[ ! ( $build && $image ) ]]; then - echo attempting to getting image name from environment file + echo attempting to get image name from environment file source_env_file $efile image=$(make_image_name) fi diff --git a/test/src/core/run b/test/src/core/run new file mode 100644 index 0000000..94578bf --- /dev/null +++ b/test/src/core/run @@ -0,0 +1,14 @@ +#!/bin/bash +cat ./run +echo This file is run file contents above was in the custom core directory +echo so it was executed. It can now do any modifications to the core layer +echo you can put any additional files you need and call them from this run file +echo the script enters the custom directory so all your reference can be relative. +source .env +env | grep CUST +ls -la +echo rest of the copied core files can be found in /opt +ls -la /opt +echo now it will modify the core_run.env file +echo "echo the core_run.env file was modifed by custom core script" >> /opt/core_run.env + diff --git a/test/src/rootfs/opt/env/run.env b/test/src/rootfs/opt/env/run.env index 9c10621..5e6d8f4 100644 --- a/test/src/rootfs/opt/env/run.env +++ b/test/src/rootfs/opt/env/run.env @@ -1 +1,2 @@ -export DEFAULT_DIR=/opt/bin \ No newline at end of file +export DEFAULT_DIR=/opt/bin +export TESTENVAR=thisisatest \ No newline at end of file