增强开发部署构建配置
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
services:
|
services:
|
||||||
db:
|
db:
|
||||||
image: postgres:15-alpine
|
image: postgres:15-alpine
|
||||||
|
pull_policy: if_not_present
|
||||||
container_name: ctms_db
|
container_name: ctms_db
|
||||||
restart: always
|
restart: always
|
||||||
environment:
|
environment:
|
||||||
@@ -24,6 +25,7 @@ services:
|
|||||||
build:
|
build:
|
||||||
context: ./backend
|
context: ./backend
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
|
pull: false
|
||||||
container_name: ctms_backend
|
container_name: ctms_backend
|
||||||
restart: always
|
restart: always
|
||||||
ports:
|
ports:
|
||||||
@@ -44,6 +46,7 @@ services:
|
|||||||
build:
|
build:
|
||||||
context: ./backend
|
context: ./backend
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
|
pull: false
|
||||||
command: python scripts/init_production.py
|
command: python scripts/init_production.py
|
||||||
environment:
|
environment:
|
||||||
DATABASE_URL: postgresql+asyncpg://ctms_user:secret_password@db/ctms_db
|
DATABASE_URL: postgresql+asyncpg://ctms_user:secret_password@db/ctms_db
|
||||||
@@ -62,7 +65,9 @@ services:
|
|||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
dockerfile: nginx/Dockerfile
|
dockerfile: nginx/Dockerfile
|
||||||
|
pull: false
|
||||||
args:
|
args:
|
||||||
|
NPM_CONFIG_REGISTRY: ${NPM_CONFIG_REGISTRY:-https://registry.npmmirror.com}
|
||||||
VITE_RUNTIME_ENV: ${ENV:-production}
|
VITE_RUNTIME_ENV: ${ENV:-production}
|
||||||
VITE_ALLOW_INSECURE_DEV_LOGIN: ${VITE_ALLOW_INSECURE_DEV_LOGIN:-false}
|
VITE_ALLOW_INSECURE_DEV_LOGIN: ${VITE_ALLOW_INSECURE_DEV_LOGIN:-false}
|
||||||
container_name: ctms_nginx
|
container_name: ctms_nginx
|
||||||
|
|||||||
+11
-1
@@ -2,8 +2,18 @@ FROM node:20-alpine AS build
|
|||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
ARG NPM_CONFIG_REGISTRY=https://registry.npmjs.org/
|
||||||
|
ENV NPM_CONFIG_REGISTRY=$NPM_CONFIG_REGISTRY
|
||||||
|
|
||||||
COPY package*.json ./
|
COPY package*.json ./
|
||||||
RUN npm ci
|
RUN --mount=type=cache,target=/root/.npm \
|
||||||
|
npm ci \
|
||||||
|
--prefer-offline \
|
||||||
|
--no-audit \
|
||||||
|
--fetch-retries=5 \
|
||||||
|
--fetch-retry-mintimeout=20000 \
|
||||||
|
--fetch-retry-maxtimeout=120000 \
|
||||||
|
--replace-registry-host=npmjs
|
||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|||||||
@@ -29,6 +29,9 @@ export default defineConfig({
|
|||||||
server: {
|
server: {
|
||||||
host: true,
|
host: true,
|
||||||
port: 5173,
|
port: 5173,
|
||||||
|
hmr: {
|
||||||
|
clientPort: 8888,
|
||||||
|
},
|
||||||
proxy: {
|
proxy: {
|
||||||
"/api": {
|
"/api": {
|
||||||
target: "http://backend:8000",
|
target: "http://backend:8000",
|
||||||
|
|||||||
+10
-1
@@ -2,13 +2,22 @@ FROM node:20-alpine AS frontend-build
|
|||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
ARG NPM_CONFIG_REGISTRY=https://registry.npmjs.org/
|
||||||
ARG VITE_RUNTIME_ENV=production
|
ARG VITE_RUNTIME_ENV=production
|
||||||
ARG VITE_ALLOW_INSECURE_DEV_LOGIN=false
|
ARG VITE_ALLOW_INSECURE_DEV_LOGIN=false
|
||||||
|
ENV NPM_CONFIG_REGISTRY=$NPM_CONFIG_REGISTRY
|
||||||
ENV VITE_RUNTIME_ENV=$VITE_RUNTIME_ENV
|
ENV VITE_RUNTIME_ENV=$VITE_RUNTIME_ENV
|
||||||
ENV VITE_ALLOW_INSECURE_DEV_LOGIN=$VITE_ALLOW_INSECURE_DEV_LOGIN
|
ENV VITE_ALLOW_INSECURE_DEV_LOGIN=$VITE_ALLOW_INSECURE_DEV_LOGIN
|
||||||
|
|
||||||
COPY frontend/package*.json ./
|
COPY frontend/package*.json ./
|
||||||
RUN npm ci
|
RUN --mount=type=cache,target=/root/.npm \
|
||||||
|
npm ci \
|
||||||
|
--prefer-offline \
|
||||||
|
--no-audit \
|
||||||
|
--fetch-retries=5 \
|
||||||
|
--fetch-retry-mintimeout=20000 \
|
||||||
|
--fetch-retry-maxtimeout=120000 \
|
||||||
|
--replace-registry-host=npmjs
|
||||||
|
|
||||||
COPY frontend/ ./
|
COPY frontend/ ./
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|||||||
@@ -472,11 +472,19 @@ run_backend_init() {
|
|||||||
run_build_and_start() {
|
run_build_and_start() {
|
||||||
if [[ "$SKIP_BUILD" -eq 1 ]]; then
|
if [[ "$SKIP_BUILD" -eq 1 ]]; then
|
||||||
step "启动服务(跳过镜像构建)"
|
step "启动服务(跳过镜像构建)"
|
||||||
|
if [[ "$TARGET_ENV" == "dev" ]]; then
|
||||||
|
run_quiet "启动开发容器并刷新后端/Nginx/Vite" -- compose_cmd up -d --force-recreate backend nginx frontend-dev
|
||||||
|
else
|
||||||
run_quiet "启动容器" -- compose_cmd up -d
|
run_quiet "启动容器" -- compose_cmd up -d
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
step "构建镜像并启动服务"
|
step "构建镜像并启动服务"
|
||||||
|
if [[ "$TARGET_ENV" == "dev" ]]; then
|
||||||
|
run_quiet "构建并刷新开发容器(首次较慢)" -- compose_cmd up -d --build --force-recreate backend nginx frontend-dev
|
||||||
|
else
|
||||||
run_quiet "构建镜像并启动容器(首次较慢)" -- compose_cmd up -d --build
|
run_quiet "构建镜像并启动容器(首次较慢)" -- compose_cmd up -d --build
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
run_migrations() {
|
run_migrations() {
|
||||||
@@ -571,6 +579,7 @@ run_health_checks() {
|
|||||||
local expect_rsa=0
|
local expect_rsa=0
|
||||||
[[ "$runtime_env" == "production" ]] && expect_rsa=1
|
[[ "$runtime_env" == "production" ]] && expect_rsa=1
|
||||||
check_container_status
|
check_container_status
|
||||||
|
check_dev_nginx_mode
|
||||||
check_backend_environment "$runtime_env" "$login_key_id" "$expect_rsa"
|
check_backend_environment "$runtime_env" "$login_key_id" "$expect_rsa"
|
||||||
step "探测 HTTP 接口可用性"
|
step "探测 HTTP 接口可用性"
|
||||||
check_http_endpoint "/health"
|
check_http_endpoint "/health"
|
||||||
@@ -578,6 +587,18 @@ run_health_checks() {
|
|||||||
ok "HTTP 接口全部就绪"
|
ok "HTTP 接口全部就绪"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
check_dev_nginx_mode() {
|
||||||
|
[[ "$TARGET_ENV" == "dev" ]] || return 0
|
||||||
|
|
||||||
|
step "校验开发 Nginx 代理配置"
|
||||||
|
if compose_cmd exec -T nginx sh -c 'grep -q "frontend_dev" /etc/nginx/nginx.conf && grep -q "proxy_pass http://frontend_dev" /etc/nginx/nginx.conf' >/dev/null 2>&1; then
|
||||||
|
ok "Nginx 已代理到 Vite dev server"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
fail "当前 Nginx 未加载开发配置,请重试:bash scripts/install-ctms.sh dev --skip-migrate --verbose"
|
||||||
|
}
|
||||||
|
|
||||||
# ── 完成提示 ─────────────────────────────────
|
# ── 完成提示 ─────────────────────────────────
|
||||||
|
|
||||||
show_success() {
|
show_success() {
|
||||||
|
|||||||
Reference in New Issue
Block a user