2023-06-18 15:52:44 +00:00
|
|
|
#! /bin/bash
|
2023-06-09 00:38:49 +00:00
|
|
|
|
2023-07-17 03:47:16 +00:00
|
|
|
set -e
|
2023-06-27 23:43:04 +00:00
|
|
|
|
2023-07-17 19:44:40 +00:00
|
|
|
source ./scripts/common.sh
|
2023-06-11 21:43:53 +00:00
|
|
|
source ./scripts/env.sh ./.env.schema
|
2023-06-09 01:29:13 +00:00
|
|
|
|
2023-07-17 03:47:16 +00:00
|
|
|
base_or_head="$1"
|
|
|
|
rev="$2"
|
2023-06-09 00:38:49 +00:00
|
|
|
|
2023-07-17 03:47:16 +00:00
|
|
|
if [[ "$base_or_head" = "head" ]]; then
|
2023-06-09 00:38:49 +00:00
|
|
|
port=5433
|
2023-07-17 03:47:16 +00:00
|
|
|
else
|
|
|
|
port=5432
|
2023-06-09 00:38:49 +00:00
|
|
|
fi
|
|
|
|
|
2023-07-20 01:07:48 +00:00
|
|
|
docker compose rm -vsf "$base_or_head" 1>/dev/null
|
2023-07-17 19:44:40 +00:00
|
|
|
|
2023-07-20 00:03:48 +00:00
|
|
|
db() {
|
2023-07-20 00:05:36 +00:00
|
|
|
echo -n "postgresql:///$1?port=$port&user=$POSTGRES_USER&password=$POSTGRES_PASSWORD"
|
2023-07-20 00:03:48 +00:00
|
|
|
}
|
2023-07-17 19:44:40 +00:00
|
|
|
|
|
|
|
isready() {
|
2023-07-19 03:29:40 +00:00
|
|
|
local waited=0
|
2023-07-20 00:03:48 +00:00
|
|
|
until pg_isready -p "$port" 1>/dev/null; do
|
2023-07-19 03:29:40 +00:00
|
|
|
if [[ "$waited" = "10" ]]; then
|
2023-07-19 03:35:46 +00:00
|
|
|
pwd
|
|
|
|
cat docker-compose.yml
|
2023-07-19 03:29:40 +00:00
|
|
|
docker compose logs base
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
sleep 1
|
2023-07-19 03:30:39 +00:00
|
|
|
echo $(( waited++ ))
|
2023-07-19 03:29:40 +00:00
|
|
|
done;
|
2023-07-17 19:44:40 +00:00
|
|
|
}
|
2023-06-09 01:29:13 +00:00
|
|
|
|
2023-07-17 19:44:40 +00:00
|
|
|
initdb() {
|
|
|
|
dropdb=$(mktemp)
|
|
|
|
echo "drop database dnim with (force);" > "$dropdb"
|
2023-07-20 00:03:48 +00:00
|
|
|
psql --quiet $(db postgres) -f "$dropdb" || true
|
|
|
|
psql --quiet $(db postgres) -c "create database dnim"
|
2023-07-17 19:44:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if [[ "$rev" = "empty" ]]; then
|
2023-07-19 03:13:08 +00:00
|
|
|
docker compose up -d "$base_or_head" 1>/dev/null
|
2023-07-17 19:44:40 +00:00
|
|
|
isready
|
|
|
|
initdb
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2023-07-19 03:06:57 +00:00
|
|
|
git worktree remove --force "./$base_or_head" &>/dev/null || true
|
|
|
|
rm -rf "./$base_or_head" &>/dev/null || true
|
|
|
|
git worktree add "./$base_or_head" --detach "$rev" &>/dev/null
|
2023-07-17 19:44:40 +00:00
|
|
|
|
|
|
|
cp docker-compose.yml "./$base_or_head/docker-compose.yml"
|
|
|
|
cp .env.schema "./$base_or_head/.env.schema"
|
|
|
|
|
|
|
|
cd "./$base_or_head"
|
2023-07-19 03:13:08 +00:00
|
|
|
docker compose up -d "$base_or_head" 1>/dev/null
|
2023-07-17 03:47:16 +00:00
|
|
|
|
2023-07-17 19:44:40 +00:00
|
|
|
isready
|
2023-07-20 00:28:33 +00:00
|
|
|
initdb || (
|
|
|
|
cd "./$base_or_head"
|
|
|
|
docker compose logs "$base_or_head"
|
|
|
|
)
|
|
|
|
ls ./schema/ | xargs -I{} bash -c "set -e; $(declare -f query_file); query_file \"$(db dnim)\" ./schema/{}" || \
|
|
|
|
(
|
|
|
|
cd "./$base_or_head"
|
|
|
|
docker compose logs "$base_or_head"
|
|
|
|
)
|