2024-01-19 10:01:49 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
set -e
|
|
|
|
set -u
|
|
|
|
# DEBUG
|
|
|
|
#set -x
|
|
|
|
|
|
|
|
common_start() {
|
2024-02-05 19:06:12 +00:00
|
|
|
figlet -w 100 "${target}"
|
2024-01-19 10:01:49 +00:00
|
|
|
|
|
|
|
deployment="${1:-${deployment:-}}"
|
|
|
|
action="${action:-deploy}"
|
2024-02-06 13:29:14 +00:00
|
|
|
persistence="${persistence:-y}"
|
2024-01-19 10:01:49 +00:00
|
|
|
|
|
|
|
# detach on production deployment
|
|
|
|
if [ "${deployment}" = 'prod' ]; then
|
|
|
|
detach='-d'
|
|
|
|
fi
|
|
|
|
|
2024-02-05 18:18:57 +00:00
|
|
|
# ensure uses main branch branch and that it is up to date
|
2024-01-19 10:01:49 +00:00
|
|
|
(
|
|
|
|
cd ./IdHub
|
2024-01-23 09:42:42 +00:00
|
|
|
if [ -d .git ]; then
|
|
|
|
git checkout main
|
|
|
|
git pull
|
|
|
|
fi
|
2024-01-19 10:01:49 +00:00
|
|
|
)
|
|
|
|
|
2024-02-06 13:50:38 +00:00
|
|
|
# process idhubs instances for the purpose
|
|
|
|
for idhub in ${idhubs}; do
|
|
|
|
if [ "${persistence}" = "n" ]; then
|
|
|
|
# no data persistence: cleanup previous possible data
|
|
|
|
rm -rf "./${idhub}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# detect existing deployment
|
|
|
|
if [ -d "./${idhub}" ]; then
|
|
|
|
git -C "${idhub}" pull
|
|
|
|
# looks new
|
|
|
|
else
|
|
|
|
echo "Detected new deployment, recreating git repos ${idhub}"
|
|
|
|
cp -rp IdHub "${idhub}"
|
|
|
|
# ensure the copy does not contain a DB
|
|
|
|
rm -f "${idhub}/db.sqlite3"
|
|
|
|
fi
|
|
|
|
done
|
2024-02-06 13:29:14 +00:00
|
|
|
|
2024-01-19 10:01:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
common_end() {
|
|
|
|
|
2024-02-05 18:18:57 +00:00
|
|
|
dc_file="docker-compose__${target}.yml"
|
2024-02-06 13:29:14 +00:00
|
|
|
|
|
|
|
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
|
2024-01-19 10:01:49 +00:00
|
|
|
make idhub_build
|
|
|
|
|
|
|
|
if [ "${action:-}" = "deploy" ]; then
|
2024-02-05 18:18:57 +00:00
|
|
|
docker compose -p ${target} -f ${dc_file} up ${detach:-}
|
2024-01-25 14:57:20 +00:00
|
|
|
wait_seconds="${wait_seconds:-20}"
|
|
|
|
echo "Give ${wait_seconds} seconds to this new deployment to be setted up"
|
|
|
|
sleep "${wait_seconds}"
|
2024-01-19 10:01:49 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
}
|