This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
idhub-docker/build__common.sh

71 lines
2.0 KiB
Bash
Raw Normal View History

#!/bin/sh
set -e
set -u
# DEBUG
#set -x
common_start() {
figlet -w 100 "${target}"
deployment="${1:-${deployment:-}}"
action="${action:-deploy}"
persistence="${persistence:-y}"
# detach on production deployment
if [ "${deployment}" = 'prod' ]; then
detach='-d'
fi
# ensure uses main branch branch and that it is up to date
(
cd ./IdHub
if [ -d .git ]; then
git checkout main
git pull
fi
)
# process idhubs instances for the purpose
for idhub in ${idhubs}; do
2024-02-06 14:56:24 +00:00
idhub_dir="${idhub}__${target}"
if [ "${persistence}" = "n" ]; then
# no data persistence: cleanup previous possible data
2024-02-06 14:56:24 +00:00
rm -rf "./${idhub_dir}"
fi
# detect existing deployment
2024-02-06 14:56:24 +00:00
if [ -d "./${idhub_dir}" ]; then
git -C "${idhub_dir}" pull
# looks new
else
2024-02-06 14:56:24 +00:00
echo "Detected new deployment, recreating git repos ${idhub_dir}"
cp -rp IdHub "${idhub_dir}"
# ensure the copy does not contain a DB
2024-02-06 14:56:24 +00:00
rm -f "${idhub_dir}/db.sqlite3"
fi
done
}
common_end() {
dc_file="docker-compose__${target}.yml"
if [ "${persistence}" = "n" ]; then
# no data persistence, then cleanup docker volume
vol_arg='-v'
fi
docker compose -p ${target} -f ${dc_file} down ${vol_arg:-} || true
make idhub_build
if [ "${action:-}" = "deploy" ]; then
docker compose -p ${target} -f ${dc_file} up ${detach:-}
wait_seconds="${wait_seconds:-20}"
echo "Give ${wait_seconds} seconds to this new deployment to be setted up"
sleep "${wait_seconds}"
fi
}