feat(deploy): 一条命令链部署——双单文件 + Caddy + DATABASE_URL 单源
多阶段镜像编出 server/engine 单文件与前端静态;compose 起 pg/server/engine/caddy; 启动时自动迁移;仅用 DATABASE_URL,postgres 建库参数由 entrypoint 拆解。
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
# 站点地址按部署环境改:
|
||||
# 本地/内网 HTTP → :80
|
||||
# 公网 HTTPS → your.domain.example(Caddy 自动签证书)
|
||||
:80 {
|
||||
root * /srv
|
||||
|
||||
# 接口反代到 server 容器
|
||||
handle /api/* {
|
||||
reverse_proxy server:18456
|
||||
}
|
||||
|
||||
# SPA:非 /api 的路径回退 index.html
|
||||
handle {
|
||||
try_files {path} /index.html
|
||||
file_server
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
#!/bin/sh
|
||||
# 把 DATABASE_URL 的主机改写为 compose 服务名 postgres,再启动应用
|
||||
set -e
|
||||
|
||||
if [ -z "$DATABASE_URL" ]; then
|
||||
echo "DATABASE_URL is required" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
export DATABASE_URL="$(echo "$DATABASE_URL" | sed -E 's#(@)[^:/]+(:[0-9]+)?(/)#\1postgres\2\3#')"
|
||||
|
||||
exec "$@"
|
||||
@@ -0,0 +1,19 @@
|
||||
#!/bin/sh
|
||||
# 从 DATABASE_URL 拆出官方镜像建库所需的 POSTGRES_*,再交回原入口
|
||||
set -e
|
||||
|
||||
if [ -z "$DATABASE_URL" ]; then
|
||||
echo "DATABASE_URL is required" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
u="${DATABASE_URL#*://}"
|
||||
auth="${u%%@*}"
|
||||
rest="${u#*@}"
|
||||
|
||||
export POSTGRES_USER="${auth%%:*}"
|
||||
export POSTGRES_PASSWORD="${auth#*:}"
|
||||
export POSTGRES_DB="${rest#*/}"
|
||||
export POSTGRES_DB="${POSTGRES_DB%%\?*}"
|
||||
|
||||
exec docker-entrypoint.sh postgres
|
||||
Reference in New Issue
Block a user