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

70 lines
1.9 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
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
}
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
}