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

81 lines
2.3 KiB
Bash
Raw Permalink Normal View History

#!/bin/sh
set -e
set -u
# DEBUG
#set -x
common_start() {
2024-02-29 17:18:40 +00:00
figlet -w 120 "${target}"
deployment="${1:-${deployment:-}}"
action="${action:-deploy}"
persistence="${persistence:-y}"
idhub_branch="${idhub_branch:-main}"
# detach on production deployment
if [ "${deployment}" = 'prod' ]; then
detach='-d'
fi
# TODO at some point it would be better to use pull-repos.sh
# ensure uses main branch branch and that it is up to date
(
cd ./IdHub
if [ -d .git ]; then
git checkout ${idhub_branch}
git pull
fi
)
(
cd ./ssikit_trustchain
if [ -d .git ]; then
git checkout master
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:-0}"
echo "Give ${wait_seconds} seconds to this new deployment to be setted up"
sleep "${wait_seconds}"
fi
}