2024-01-19 10:01:49 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
set -e
|
|
|
|
set -u
|
|
|
|
# DEBUG
|
|
|
|
#set -x
|
|
|
|
|
|
|
|
common_start() {
|
2024-02-29 17:18:40 +00:00
|
|
|
figlet -w 120 "${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-02-29 11:30:21 +00:00
|
|
|
idhub_branch="${idhub_branch:-main}"
|
2024-01-19 10:01:49 +00:00
|
|
|
|
|
|
|
# detach on production deployment
|
|
|
|
if [ "${deployment}" = 'prod' ]; then
|
|
|
|
detach='-d'
|
|
|
|
fi
|
|
|
|
|
2024-02-29 11:30:21 +00:00
|
|
|
# TODO at some point it would be better to use pull-repos.sh
|
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
|
2024-02-29 11:30:21 +00:00
|
|
|
git checkout ${idhub_branch}
|
|
|
|
git pull
|
|
|
|
fi
|
|
|
|
)
|
|
|
|
|
|
|
|
(
|
|
|
|
cd ./ssikit_trustchain
|
|
|
|
if [ -d .git ]; then
|
|
|
|
git checkout master
|
2024-01-23 09:42:42 +00:00
|
|
|
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
|
2024-02-06 14:56:24 +00:00
|
|
|
idhub_dir="${idhub}__${target}"
|
2024-02-06 13:50:38 +00:00
|
|
|
if [ "${persistence}" = "n" ]; then
|
|
|
|
# no data persistence: cleanup previous possible data
|
2024-02-06 14:56:24 +00:00
|
|
|
rm -rf "./${idhub_dir}"
|
2024-02-06 13:50:38 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# detect existing deployment
|
2024-02-06 14:56:24 +00:00
|
|
|
if [ -d "./${idhub_dir}" ]; then
|
|
|
|
git -C "${idhub_dir}" pull
|
2024-02-06 13:50:38 +00:00
|
|
|
# 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}"
|
2024-02-06 13:50:38 +00:00
|
|
|
# ensure the copy does not contain a DB
|
2024-02-06 14:56:24 +00:00
|
|
|
rm -f "${idhub_dir}/db.sqlite3"
|
2024-02-06 13:50:38 +00:00
|
|
|
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-03-15 08:03:02 +00:00
|
|
|
wait_seconds="${wait_seconds:0}"
|
2024-01-25 14:57:20 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
}
|