diff --git a/Dockerfile b/Dockerfile index 4cb9383..ca7bec9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,9 +13,9 @@ RUN echo -e "\n ************************************************* \n"\ echo " ---- running packages install script ---"; /bin/sh ./packages.sh; \ echo -e "\n********************************************************" -ARG CACHE_BUST +ARG BUST_INIT_CACHE RUN echo -e "\n ************************************************* \n" \ - echo "****** CACHE_BUST ${CACHE_BUST} "; \ + echo "****** BUST_INIT_CACHE ${BUST_INIT_CACHE} "; \ echo "****** Running Initialization Script "; \ chmod -R +x .; \ pwd; ls -la; \ diff --git a/build b/build index 7c54652..0c65ede 100755 --- a/build +++ b/build @@ -40,12 +40,16 @@ exit_abnormal() { # Function: Exit with error. scripts_dir=$SDIR/src [[ -z "$PS1" ]] || no_prompt=true -while getopts ':b:d:t:ncr:u:pxhs:w:akvo' OPTION; do +while getopts ':b:d:t:ncr:u:pxhs:w:akvoi' OPTION; do # echo processing: option:$OPTION argument:$OPTARG index:$OPTIND remaining:${@:$OPTIND} case "$OPTION" in o) overwrite=true ;; + i) + BUST_INIT_CACHE=$(date) + # export BUST_INIT_CACHE=$(date) + ;; v) verbose=true ;; @@ -114,6 +118,18 @@ done shift $((OPTIND - 1)) +if [[ ! -d $scripts_dir ]]; then + if [[ ! $no_prompt ]]; then + echo -e "\e[1;31mWARNING: build scripts directory$scripts_dir does not exist.\e[1;37m" + echo "Do you want to use the base scripts" + read -n 1 -p "directory at $BDIR/src? to continue [y]=>" REPLY + [[ $REPLY != "y" ]] && echo -e "\n" && return 0 + echo + fi + echo -e "\e[1;31mscripts directory $scripts_dir was not found using base build scripts at $BDIR/src\e[1;37m" + scripts_dir=$BDIR/src +fi + target=${1:-dev} LINUX_DISTRO=${LINUX_DISTRO:-alpine} name=$2 @@ -121,7 +137,19 @@ RUSER=${3:-$RUSER} IMAGE_NAME=$([[ $RUSER ]] && echo ${RUSER}/)${name}$([[ (! $exclude_distro) && $name ]] && echo "-")$([[ ! $exclude_distro ]] && echo ${LINUX_DISTRO}) # TODO writing to existing tag untags existing image so write a new tag to that image then continue -[[ $(image_exists $IMAGE_NAME) ]] && [[ ! $overwrite ]] && { echo local image \'$(make_tag $IMAGE_NAME)\' exists use -o to overwrite; return 1; } + +# retag existing image and remove former tag +if [[ $(image_exists $IMAGE_NAME) ]]; then + if [[ $overwrite ]]; then + image_delete $IMAGE_NAME + else + newtag=$(date +'%d%H%M%S') + echo image exists retaging $(make_tag $IMAGE_NAME) with tag :$newtag + image_tag $IMAGE_NAME $IMAGE_NAME:$newtag + image_tag -r $IMAGE_NAME + fi +fi + if [[ $BASE_IMAGE ]]; then echo determining DISTRO of base image: $BASE_IMAGE @@ -140,6 +168,8 @@ export IMAGE_NAME export LINUX_DISTRO export SCRIPTS export KEEP +export SYSADMIN_PW +export BUST_INIT_CACHE echo "******************************************" echo "Building with base image: $BASE_IMAGE" @@ -183,7 +213,7 @@ fusermount -u .src > /dev/null 2>&1 mkdir .src bindfs ${scripts_dir:-src} .src -docker buildx --builder ${builder} bake ${nocache} ${target} 2>&1 | tee build.log +docker buildx --builder ${builder} bake ${nocache} ${target} 2>&1 | tee $SDIR/${exIMAGE_NAME//\//-}build.log fusermount -u .src > /dev/null 2>&1 rm -rf .src/ @@ -202,7 +232,7 @@ fi if [[ ($try || $target == "dev") ]] && [[ ! $no_prompt ]]; then echo trying newly built image in a container - try_container $([[ $target == "deploy" ]] && echo -p) $IMAGE_NAME + try_container -m opt $([[ $target == "deploy" ]] && echo -p) $IMAGE_NAME fi popd > /dev/null diff --git a/docker-bake.hcl b/docker-bake.hcl index 85c9140..d31949d 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -20,7 +20,7 @@ variable "KEEP" { variable "SYSADMIN_PW" { default = "" } -variable "CACHE_BUST" { +variable "BUST_INIT_CACHE" { default = "1" } @@ -51,13 +51,13 @@ target "amd" { context = "." dockerfile = "Dockerfile" args = { - LINUX_DISTRO = "${LINUX_DISTRO}" - BASE_IMAGE = "${BASE_IMAGE}" - TAG = "${TAG}" - SCRIPTS = "/build/${SCRIPTS}" - KEEP = "${KEEP}" - SYSADMIN_PW = "${SYSADMIN_PW}" - CACHE_BUST = "${CACHE_BUST}" + LINUX_DISTRO = "${LINUX_DISTRO}" + BASE_IMAGE = "${BASE_IMAGE}" + TAG = "${TAG}" + SCRIPTS = "/build/${SCRIPTS}" + KEEP = "${KEEP}" + SYSADMIN_PW = "${SYSADMIN_PW}" + BUST_INIT_CACHE = "${BUST_INIT_CACHE}" } tags = tag("") platforms = ["linux/amd64"]