Split prep and render scripts

This commit is contained in:
Daniel Berteaud 2023-09-10 14:07:12 +02:00
parent 640d9a3924
commit 5ff5575363
1 changed files with 20 additions and 4 deletions

24
ctctl
View File

@ -407,7 +407,7 @@ build_image(){
local FOUND=0
for DIR in ./images ./output/images; do
if [ -d $DIR/${IMAGE_NAME} ]; then
docker build ${NO_CACHE} -t ${DOCKER_IMAGE} ${CTCTL_DOCKER_BUILD_OPTS:-} --progress=plain $DIR/${IMAGE_NAME} &&\
docker build ${NO_CACHE} -t ${DOCKER_IMAGE} -t ${LATEST} ${CTCTL_DOCKER_BUILD_OPTS:-} --progress=plain $DIR/${IMAGE_NAME} &&\
docker push ${DOCKER_IMAGE} &&\
docker push ${LATEST}
FOUND=1
@ -421,6 +421,22 @@ build_image(){
unset DOCKER_BUILDKIT
}
# Run all executable in the render.d directory
handle_render_scripts(){
for DIR in ./output ./; do
if [ -d "${DIR}/render.d" ]; then
for H in $(find ${DIR}/render.d -type f -o -type l | sort); do
if [ -x "${H}" ]; then
echo "Running render script ${H}"
$H $1
else
echo "Skiping render script $H (not executable)"
fi
done
fi
done
}
# Run all executable in the prep.d directory
handle_prep_scripts(){
for DIR in ./output ./; do
@ -558,7 +574,7 @@ render_templates(){
find ./ -maxdepth 1 -type f \( -name \*nomad.hcl -o -name \*.nomad \) -exec nomad fmt {} \;
# Run prep.d scripts
handle_prep_scripts
handle_render_scripts
done
# Cleanup variables
@ -571,8 +587,7 @@ render_templates(){
MERGED_CONF=$(mktemp tmp.XXXXXXXX.yml)
get_merged_conf > ${MERGED_CONF}
# TODO : handle prep scripts with the new bundles system
handle_prep_scripts ${MERGED_CONF}
handle_render_scripts ${MERGED_CONF}
for TEMPLATE in $(find . -type f -name \*.tpl ! -path "*templates/*"); do
local DIR=$(dirname ${TEMPLATE})
@ -713,6 +728,7 @@ case $1 in
prep)
update_submodules
render_templates
handle_prep_scripts
load_policies
load_consul_conf
build_required_images