fix: deal with no src/ directory in current directory
fix: save old image by retagging or overwrite add: allow only breaking cache for initialzation run of buildmaster
parent
87bc2057c6
commit
c343cbb148
|
@ -13,9 +13,9 @@ RUN echo -e "\n ************************************************* \n"\
|
||||||
echo " ---- running packages install script ---"; /bin/sh ./packages.sh; \
|
echo " ---- running packages install script ---"; /bin/sh ./packages.sh; \
|
||||||
echo -e "\n********************************************************"
|
echo -e "\n********************************************************"
|
||||||
|
|
||||||
ARG CACHE_BUST
|
ARG BUST_INIT_CACHE
|
||||||
RUN echo -e "\n ************************************************* \n" \
|
RUN echo -e "\n ************************************************* \n" \
|
||||||
echo "****** CACHE_BUST ${CACHE_BUST} "; \
|
echo "****** BUST_INIT_CACHE ${BUST_INIT_CACHE} "; \
|
||||||
echo "****** Running Initialization Script "; \
|
echo "****** Running Initialization Script "; \
|
||||||
chmod -R +x .; \
|
chmod -R +x .; \
|
||||||
pwd; ls -la; \
|
pwd; ls -la; \
|
||||||
|
|
38
build
38
build
|
@ -40,12 +40,16 @@ exit_abnormal() { # Function: Exit with error.
|
||||||
scripts_dir=$SDIR/src
|
scripts_dir=$SDIR/src
|
||||||
[[ -z "$PS1" ]] || no_prompt=true
|
[[ -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}
|
# echo processing: option:$OPTION argument:$OPTARG index:$OPTIND remaining:${@:$OPTIND}
|
||||||
case "$OPTION" in
|
case "$OPTION" in
|
||||||
o)
|
o)
|
||||||
overwrite=true
|
overwrite=true
|
||||||
;;
|
;;
|
||||||
|
i)
|
||||||
|
BUST_INIT_CACHE=$(date)
|
||||||
|
# export BUST_INIT_CACHE=$(date)
|
||||||
|
;;
|
||||||
v)
|
v)
|
||||||
verbose=true
|
verbose=true
|
||||||
;;
|
;;
|
||||||
|
@ -114,6 +118,18 @@ done
|
||||||
|
|
||||||
shift $((OPTIND - 1))
|
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}
|
target=${1:-dev}
|
||||||
LINUX_DISTRO=${LINUX_DISTRO:-alpine}
|
LINUX_DISTRO=${LINUX_DISTRO:-alpine}
|
||||||
name=$2
|
name=$2
|
||||||
|
@ -121,7 +137,19 @@ RUSER=${3:-$RUSER}
|
||||||
|
|
||||||
IMAGE_NAME=$([[ $RUSER ]] && echo ${RUSER}/)${name}$([[ (! $exclude_distro) && $name ]] && echo "-")$([[ ! $exclude_distro ]] && echo ${LINUX_DISTRO})
|
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
|
# 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
|
if [[ $BASE_IMAGE ]]; then
|
||||||
echo determining DISTRO of base image: $BASE_IMAGE
|
echo determining DISTRO of base image: $BASE_IMAGE
|
||||||
|
@ -140,6 +168,8 @@ export IMAGE_NAME
|
||||||
export LINUX_DISTRO
|
export LINUX_DISTRO
|
||||||
export SCRIPTS
|
export SCRIPTS
|
||||||
export KEEP
|
export KEEP
|
||||||
|
export SYSADMIN_PW
|
||||||
|
export BUST_INIT_CACHE
|
||||||
|
|
||||||
echo "******************************************"
|
echo "******************************************"
|
||||||
echo "Building with base image: $BASE_IMAGE"
|
echo "Building with base image: $BASE_IMAGE"
|
||||||
|
@ -183,7 +213,7 @@ fusermount -u .src > /dev/null 2>&1
|
||||||
mkdir .src
|
mkdir .src
|
||||||
bindfs ${scripts_dir:-src} .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
|
fusermount -u .src > /dev/null 2>&1
|
||||||
rm -rf .src/
|
rm -rf .src/
|
||||||
|
@ -202,7 +232,7 @@ fi
|
||||||
|
|
||||||
if [[ ($try || $target == "dev") ]] && [[ ! $no_prompt ]]; then
|
if [[ ($try || $target == "dev") ]] && [[ ! $no_prompt ]]; then
|
||||||
echo trying newly built image in a container
|
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
|
fi
|
||||||
|
|
||||||
popd > /dev/null
|
popd > /dev/null
|
||||||
|
|
|
@ -20,7 +20,7 @@ variable "KEEP" {
|
||||||
variable "SYSADMIN_PW" {
|
variable "SYSADMIN_PW" {
|
||||||
default = ""
|
default = ""
|
||||||
}
|
}
|
||||||
variable "CACHE_BUST" {
|
variable "BUST_INIT_CACHE" {
|
||||||
default = "1"
|
default = "1"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ target "amd" {
|
||||||
SCRIPTS = "/build/${SCRIPTS}"
|
SCRIPTS = "/build/${SCRIPTS}"
|
||||||
KEEP = "${KEEP}"
|
KEEP = "${KEEP}"
|
||||||
SYSADMIN_PW = "${SYSADMIN_PW}"
|
SYSADMIN_PW = "${SYSADMIN_PW}"
|
||||||
CACHE_BUST = "${CACHE_BUST}"
|
BUST_INIT_CACHE = "${BUST_INIT_CACHE}"
|
||||||
}
|
}
|
||||||
tags = tag("")
|
tags = tag("")
|
||||||
platforms = ["linux/amd64"]
|
platforms = ["linux/amd64"]
|
||||||
|
|
Loading…
Reference in New Issue