feat: add AI SoulMate local admin deployment

This commit is contained in:
wlx committed 2026-08-07 13:38:21 +08:00
1 parent bd3d409836
commit 1b5e10bbd0
15 files changed
+665 -24

No files matched your search

+31 -2
View File
@@ -28,6 +28,10 @@ env_value() {
printf '%s' "$value"
}
env_optional_value() {
awk -F= -v key="$1" '$1 == key {sub(/^[^=]*=/, ""); print; exit}' "$env_file"
}
compose_command=(docker compose --env-file "$env_file" -f "$compose_file")
"${compose_command[@]}" config --quiet
@@ -56,6 +60,26 @@ mkdir -p "$staging_directory/minio"
'exec pg_dump --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" --format=custom --compress=6 --no-owner --no-acl' \
> "$staging_directory/postgres.dump"
postgres_user="$(env_value POSTGRES_USER)"
admin_database="$(env_optional_value ADMIN_POSTGRES_DB)"
admin_artifact="null"
if [[ -n "$admin_database" ]]; then
if [[ ! "$admin_database" =~ ^[A-Za-z][A-Za-z0-9_]{0,62}$ ]]; then
printf 'ADMIN_POSTGRES_DB is not a safe PostgreSQL identifier.\n' >&2
exit 1
fi
admin_database_exists="$("${compose_command[@]}" exec -T postgres psql \
--username "$postgres_user" --dbname postgres --tuples-only --no-align \
--command "SELECT 1 FROM pg_database WHERE datname = '$admin_database'")"
if [[ "$admin_database_exists" == "1" ]]; then
"${compose_command[@]}" exec -T postgres pg_dump \
--username "$postgres_user" --dbname "$admin_database" \
--format=custom --compress=6 --no-owner --no-acl \
> "$staging_directory/admin-postgres.dump"
admin_artifact='"admin-postgres.dump"'
fi
fi
"${compose_command[@]}" exec -T redis sh -ec \
'redis-cli --no-auth-warning -a "$REDIS_PASSWORD" SAVE >/dev/null'
redis_container_id="$("${compose_command[@]}" ps -q redis)"
@@ -84,12 +108,13 @@ fi
minio_object_count="$(find "$staging_directory/minio" -type f | wc -l | tr -d '[:space:]')"
cat > "$staging_directory/manifest.yml" <<EOF
schema_version: 1
schema_version: 2
created_at: "$(date --iso-8601=seconds)"
deployment_repository_commit: "$deployment_repository_commit"
compose_file: "$compose_file"
artifacts:
postgres: "postgres.dump"
admin_postgres: $admin_artifact
redis: "redis.rdb"
minio: "minio/"
minio:
@@ -102,7 +127,11 @@ EOF
(
cd "$staging_directory"
find manifest.yml postgres.dump redis.rdb minio -type f -print0 \
checksum_paths=(manifest.yml postgres.dump redis.rdb minio)
if [[ -f admin-postgres.dump ]]; then
checksum_paths+=(admin-postgres.dump)
fi
find "${checksum_paths[@]}" -type f -print0 \
| LC_ALL=C sort -z \
| xargs -0 sha256sum
) > "$staging_directory/checksums.sha256"