Files
patbond-api/deploy/init-secrets.sh
T
lixi b22eaede28
CI / backend-test (push) Successful in 9m51s
update
2026-09-04 16:53:43 +08:00

27 lines
1.0 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# 生成 docker compose 运行所需的本地机密:RS256 密钥对 + .env(DB 口令、内部令牌)。
# 产物全部被 .gitignore 忽略,绝不入库;重复执行是幂等的(已存在则不覆盖)。
set -euo pipefail
cd "$(dirname "$0")/.."
mkdir -p deploy/keys
if [ ! -f deploy/keys/jwt-private.pem ]; then
openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -out deploy/keys/jwt-private.pem
echo "已生成 deploy/keys/jwt-private.pem"
fi
openssl pkey -in deploy/keys/jwt-private.pem -pubout -out deploy/keys/jwt-public.pem
echo "已生成 deploy/keys/jwt-public.pem"
if [ ! -f .env ]; then
{
echo "PATBOND_DB_PASSWORD=$(openssl rand -hex 16)"
echo "PATBOND_INTERNAL_TOKEN=$(openssl rand -hex 32)"
} > .env
echo "已生成 .env(随机 DB 口令与内部令牌)"
fi
# 容器内以 uid 10001 运行,密钥需可读
chmod 644 deploy/keys/jwt-public.pem deploy/keys/jwt-private.pem
echo "OKdeploy/keys/ 与 .env 就绪(均已被 .gitignore 忽略)"