#!/usr/bin/env bash # 渲染 deploy/templates/*.tpl → deploy/nginx、deploy/redis,并创建运行所需目录。 # 约定:每次 up 之前(或改模板/.env 后)必须重跑本脚本。幂等,可反复执行。 set -eu cd "$(dirname "$0")" if [ -f .env ]; then set -a; . ./.env; set +a fi NGINX_CLIENT_MAX_BODY_SIZE=${NGINX_CLIENT_MAX_BODY_SIZE:-200m} REDIS_MAXMEMORY=${REDIS_MAXMEMORY:-128mb} REDIS_MAXMEMORY_POLICY=${REDIS_MAXMEMORY_POLICY:-allkeys-lru} for t in templates/nginx.conf.tpl templates/default.conf.tpl templates/redis.conf.tpl; do [ -f "$t" ] || { echo "prepare.sh: missing template $t" >&2; exit 1; } done mkdir -p nginx/conf.d redis logs/nginx api/storage sed -e "s|{{NGINX_CLIENT_MAX_BODY_SIZE}}|${NGINX_CLIENT_MAX_BODY_SIZE}|g" \ templates/nginx.conf.tpl > nginx/nginx.conf sed -e "s|{{NGINX_CLIENT_MAX_BODY_SIZE}}|${NGINX_CLIENT_MAX_BODY_SIZE}|g" \ templates/default.conf.tpl > nginx/conf.d/default.conf sed -e "s|{{REDIS_MAXMEMORY}}|${REDIS_MAXMEMORY}|g" \ -e "s|{{REDIS_MAXMEMORY_POLICY}}|${REDIS_MAXMEMORY_POLICY}|g" \ templates/redis.conf.tpl > redis/redis.conf echo "prepare.sh: rendered nginx($(pwd)/nginx), redis($(pwd)/redis), logs($(pwd)/logs/nginx), storage($(pwd)/api/storage)"