添加安装部署脚本
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
FROM node:22-alpine AS builder
|
||||
WORKDIR /app
|
||||
COPY frontend/package*.json ./
|
||||
RUN npm ci
|
||||
COPY frontend/ ./
|
||||
RUN npm run build
|
||||
|
||||
FROM nginx:alpine
|
||||
COPY --from=builder /app/dist /usr/share/nginx/html
|
||||
COPY deploy/podman/images/frontend/nginx.conf /etc/nginx/conf.d/default.conf
|
||||
COPY deploy/podman/images/frontend/docker-entrypoint.sh /docker-entrypoint.d/40-inject-config.sh
|
||||
RUN chmod +x /docker-entrypoint.d/40-inject-config.sh
|
||||
EXPOSE 80
|
||||
@@ -0,0 +1,22 @@
|
||||
#!/bin/sh
|
||||
# 由 nginx 官方镜像的入口脚本自动执行(位于 /docker-entrypoint.d/)
|
||||
# 将 config.js 中的占位符替换为运行期环境变量
|
||||
|
||||
set -e
|
||||
|
||||
CONFIG_FILE=/usr/share/nginx/html/config.js
|
||||
|
||||
if [ ! -f "$CONFIG_FILE" ]; then
|
||||
echo "[entrypoint] $CONFIG_FILE 不存在,跳过注入" >&2
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ -z "${API_BASE_URL:-}" ]; then
|
||||
echo "[entrypoint] 错误:必须设置 API_BASE_URL 环境变量" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 用 | 作分隔符,避免 URL 里的 / 干扰
|
||||
sed -i "s|__API_BASE_URL__|${API_BASE_URL}|g" "$CONFIG_FILE"
|
||||
|
||||
echo "[entrypoint] 已注入 API_BASE_URL=${API_BASE_URL}"
|
||||
@@ -0,0 +1,21 @@
|
||||
server {
|
||||
listen 80;
|
||||
server_name _;
|
||||
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
|
||||
gzip on;
|
||||
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript image/svg+xml;
|
||||
gzip_min_length 1024;
|
||||
|
||||
location ~* \.(?:css|js|woff2?|ttf|eot|svg|png|jpg|jpeg|gif|ico|webp)$ {
|
||||
expires 7d;
|
||||
add_header Cache-Control "public, immutable";
|
||||
try_files $uri =404;
|
||||
}
|
||||
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user