Skip to content

Commit 6c80b5c

Browse files
committed
Validate env and wait for postgres before migrate
1 parent 99969c3 commit 6c80b5c

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

deploy/local-deploy.sh

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,25 @@ if [ ! -f ".env" ]; then
3333
exit 1
3434
fi
3535

36+
set -a
37+
. ./.env
38+
set +a
39+
40+
if [ -z "${POSTGRES_PASSWORD:-}" ]; then
41+
echo "POSTGRES_PASSWORD 未配置,请先修改 .env"
42+
exit 1
43+
fi
44+
45+
if [ -z "${DATABASE_URL:-}" ]; then
46+
echo "DATABASE_URL 未配置,请先修改 .env"
47+
exit 1
48+
fi
49+
50+
if [ -z "${REDIS_URL:-}" ]; then
51+
echo "REDIS_URL 未配置,请先修改 .env"
52+
exit 1
53+
fi
54+
3655
printf "后端镜像名 [%s]: " "$APP_IMAGE"
3756
read -r input_app_image || true
3857
if [ -n "${input_app_image:-}" ]; then
@@ -120,7 +139,11 @@ export APP_IMAGE_TAG="$IMAGE_TAG"
120139
export EDGE_PORT
121140

122141
docker compose -f "$COMPOSE_FILE" up -d postgres redis
123-
docker compose -f "$COMPOSE_FILE" run --rm api prts-migrate
142+
143+
echo "等待 PostgreSQL 就绪..."
144+
docker compose -f "$COMPOSE_FILE" exec -T postgres sh -c 'until pg_isready -U postgres -d prts_translation_system; do sleep 1; done'
145+
146+
docker compose -f "$COMPOSE_FILE" run --rm --use-aliases api prts-migrate
124147
docker compose -f "$COMPOSE_FILE" up -d --remove-orphans
125148

126149
echo ""

0 commit comments

Comments
 (0)