feat(deploy): add k01 business cluster manifests for k3s with cnpg, strimzi, redis and mongodb operators
This commit is contained in:
Executable
+58
@@ -0,0 +1,58 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
K01_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
REPO_ROOT="$(cd "$K01_DIR/../.." && pwd)"
|
||||
SQL_DIR="$REPO_ROOT/desc/sql"
|
||||
FIXTURE_DIR="$REPO_ROOT/deploy/dev/fixture"
|
||||
|
||||
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
|
||||
|
||||
declare -A SCHEMA_MAP=(
|
||||
[user-db]=users
|
||||
[player-db]=player
|
||||
[game-db]=game
|
||||
[shop-db]=shop
|
||||
[order-db]=order
|
||||
[wallet-db]=wallet
|
||||
[community-db]=community
|
||||
[review-db]=review
|
||||
[dispute-db]=dispute
|
||||
[notification-db]=notification
|
||||
[search-db]=search
|
||||
)
|
||||
|
||||
psql_exec() {
|
||||
local cluster="$1" sql="$2"
|
||||
kubectl -n juwan exec -i "${cluster}-1" -c postgres -- psql \
|
||||
-v ON_ERROR_STOP=1 -U app -d app <<<"$sql"
|
||||
}
|
||||
|
||||
psql_file() {
|
||||
local cluster="$1" file="$2"
|
||||
kubectl -n juwan exec -i "${cluster}-1" -c postgres -- psql \
|
||||
-v ON_ERROR_STOP=1 -U app -d app < "$file"
|
||||
}
|
||||
|
||||
for cluster in "${!SCHEMA_MAP[@]}"; do
|
||||
domain="${SCHEMA_MAP[$cluster]}"
|
||||
echo ">>> $cluster ($domain)"
|
||||
|
||||
kubectl -n juwan wait --for=condition=Ready "cluster.postgresql.cnpg.io/${cluster}" --timeout=300s
|
||||
|
||||
psql_file "$cluster" "$SQL_DIR/common/update_updated_at_column.sql"
|
||||
|
||||
for f in "$SQL_DIR/$domain"/*.sql; do
|
||||
[ -f "$f" ] || continue
|
||||
echo " schema: $(basename "$f")"
|
||||
psql_file "$cluster" "$f"
|
||||
done
|
||||
|
||||
if [ -f "$FIXTURE_DIR/$domain.sql" ]; then
|
||||
echo " fixture: $domain.sql"
|
||||
psql_file "$cluster" "$FIXTURE_DIR/$domain.sql"
|
||||
fi
|
||||
done
|
||||
|
||||
echo
|
||||
echo "schema + fixture loaded into 11 CNPG clusters"
|
||||
Reference in New Issue
Block a user