e7ab963ae3
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (push) Successful in 1s
CI/CD Pipeline / Check push changed paths (push) Successful in 6s
CI/CD Pipeline / Build Staging Web Image (push) Successful in 31s
CI/CD Pipeline / Build Staging API Image (push) Successful in 34s
CI/CD Pipeline / Build Staging Worker Image (push) Successful in 42s
CI/CD Pipeline / Validate - Python (mypy + alembic) (push) Successful in 2m3s
CI/CD Pipeline / Integration Tests (push) Successful in 2m29s
CI/CD Pipeline / Validate - Style (push) Successful in 3m19s
CI/CD Pipeline / Frontend Unit Tests (push) Successful in 3m45s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Successful in 1m53s
CI/CD Pipeline / ACR Image Cleanup (push) Successful in 1m53s
CI/CD Pipeline / Staging E2E Tests (push) Failing after 3m1s
CI/CD Pipeline / Staging API Integration Tests (push) Successful in 4m14s
CI/CD Pipeline / Unit Tests (push) Successful in 9m15s
CI/CD Pipeline / Validate - Security (push) Successful in 9m34s
CI/CD Pipeline / Production Browser E2E (push) Has been skipped
CI/CD Pipeline / Deploy Production (push) Failing after 124h2m20s
CI/CD Pipeline / Build Production Web Image (push) Failing after 124h2m24s
CI/CD Pipeline / Retag skipped Staging Web Image (push) Failing after 124h9m10s
CI/CD Pipeline / PR Build Web Image (push) Failing after 124h11m57s
CI/CD Pipeline / PR Build API Image (push) Failing after 124h11m42s
CI/CD Pipeline / Build Production API Image (push) Failing after 124h2m9s
CI/CD Pipeline / CI Gate (push) Failing after 124h2m9s
CI/CD Pipeline / Build Production Worker Image (push) Failing after 124h2m9s
CI/CD Pipeline / Canary Release to Production (push) Failing after 124h2m5s
CI/CD Pipeline / Retag skipped Staging Worker Image (push) Failing after 124h8m54s
CI/CD Pipeline / Retag skipped Staging API Image (push) Failing after 124h8m55s
CI/CD Pipeline / PR Build Worker Image (push) Failing after 124h11m41s
CI/CD Pipeline / Frontend Lint (push) Failing after 124h11m42s
CI/CD Pipeline / Check if frontend-only change (push) Failing after 124h11m47s
Co-authored-by: xiaoxia <dev@xiaoxiajianji.com> Co-committed-by: xiaoxia <dev@xiaoxiajianji.com>
50 lines
2.0 KiB
Bash
Executable File
50 lines
2.0 KiB
Bash
Executable File
#!/bin/sh
|
||
# Select nginx config based on APP_ENV (staging/production).
|
||
#
|
||
# 两种运行模式:
|
||
# 1. CI/CD 部署(staging/production):部署脚本通过 `-v 宿主机文件:/etc/nginx/conf.d/default.conf:ro`
|
||
# 把宿主机生成的带 resolver/docker upstream 的配置 bind mount 进来,entrypoint 不应改动。
|
||
# bind mount 的文件是 readonly 的,rm 会报 EBUSY ("Resource busy"),直接 exec nginx 即可。
|
||
# 2. 本地 docker-compose / 直接 `docker run`(无外部挂载):镜像烤入了 nginx-staging.conf 与
|
||
# nginx-production.conf 到 /etc/nginx/,entrypoint 根据 APP_ENV 把 default.conf 换成正确的 symlink。
|
||
#
|
||
# 策略:
|
||
# - 如果 /etc/nginx/conf.d/default.conf 已经是指向目标 conf 的 symlink,什么都不做;
|
||
# - 否则尝试 rm -f 再 ln -s;rm 失败说明是外部 bind mount(已有正确配置),不阻塞启动;
|
||
# - 兜底:只要 conf.d 目录里有 .conf 文件(含 bind mount 来的),就直接启动 nginx。
|
||
set -e
|
||
|
||
NGINX_CONF_DIR="/etc/nginx/conf.d"
|
||
TARGET_CONF=""
|
||
|
||
case "${APP_ENV:-production}" in
|
||
staging)
|
||
TARGET_CONF="/etc/nginx/nginx-staging.conf"
|
||
;;
|
||
*)
|
||
TARGET_CONF="/etc/nginx/nginx-production.conf"
|
||
;;
|
||
esac
|
||
|
||
DEFAULT_CONF="$NGINX_CONF_DIR/default.conf"
|
||
|
||
# 1. 已经是正确的 symlink:直接启动
|
||
if [ -L "$DEFAULT_CONF" ] && [ "$(readlink "$DEFAULT_CONF" 2>/dev/null)" = "$TARGET_CONF" ]; then
|
||
exec nginx -g "daemon off;"
|
||
fi
|
||
|
||
# 2. 尝试替换为目标 symlink(无 bind mount 的场景)
|
||
# 若 rm 失败(bind mount readonly,EBUSY/EPERM),则认为外部已注入配置,不阻塞。
|
||
rm -f "$DEFAULT_CONF" 2>/dev/null || true
|
||
if [ -f "$TARGET_CONF" ] && [ ! -e "$DEFAULT_CONF" ]; then
|
||
ln -s "$TARGET_CONF" "$DEFAULT_CONF" 2>/dev/null || true
|
||
fi
|
||
|
||
# 3. 兜底:至少要有一个 .conf 文件,否则 nginx 起不来
|
||
if ! ls "$NGINX_CONF_DIR"/*.conf >/dev/null 2>&1; then
|
||
echo "ERROR: no nginx config found in $NGINX_CONF_DIR (tried $TARGET_CONF and external bind mount)" >&2
|
||
exit 1
|
||
fi
|
||
|
||
exec nginx -g "daemon off;"
|