更改目录

This commit is contained in:
dxin
2025-12-17 17:32:04 +08:00
parent 290abb3fa5
commit 480dcd46c3
28 changed files with 934 additions and 20 deletions

View File

@@ -0,0 +1,42 @@
# ===============================
# 1) 依赖安装 + 构建阶段
# ===============================
FROM registry.cn-hangzhou.aliyuncs.com/docker_mirror/node:20.15.0-alpine AS build
WORKDIR /app
# 只拷贝 package.json加快缓存命中
COPY package.json ./
# 预先安装依赖(利用缓存)
RUN pnpm install --registry=https://registry.npmmirror.com
# 拷贝全部代码
COPY . .
# 要求 package.json 中的 script 形如build:sit, build:test, build:prod
RUN pnpm build
RUN mv /app/dist/main/index.html /app/dist/index.html
# ===============================
# 2) 生产镜像阶段
# ===============================
FROM registry.cn-hangzhou.aliyuncs.com/docker_mirror/nginx:1.25-alpine AS runtime
# 清理默认 nginx 静态内容
RUN rm -rf /usr/share/nginx/html/*
# 拷贝自定义 nginx 配置文件
COPY nginx.conf /etc/nginx/nginx.conf
# 拷贝 build 结果
COPY --from=build /app/dist /usr/share/nginx/html/
# 权限
RUN chmod -R 755 /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

View File

@@ -0,0 +1,65 @@
# nginx.conf
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
# 日志格式
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
error_log /var/log/nginx/error.log;
# 性能优化
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# Gzip 压缩
gzip on;
gzip_vary on;
gzip_min_length 1024;
gzip_types
text/plain
text/css
text/xml
text/javascript
application/json
application/javascript
application/xml+rss
application/atom+xml
image/svg+xml;
# 默认服务器配置
server {
listen 80;
server_name localhost;
# 网站根目录
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
# 静态资源缓存优化
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
expires 1y;
add_header Cache-Control "public, immutable";
access_log off;
}
# 错误页面
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
}

View File

@@ -0,0 +1,41 @@
# ===============================
# 1) 依赖安装 + 构建阶段
# ===============================
FROM node:20.15.0-alpine AS build
WORKDIR /app
RUN npm install -g pnpm
# 只拷贝 package.json加快缓存命中
COPY package.json pnpm-lock.yaml* ./
# 预先安装依赖(利用缓存)
RUN pnpm install --registry=https://registry.npmmirror.com
# 拷贝全部代码
COPY . .
# 要求 package.json 中的 script 形如build:sit, build:test, build:prod
RUN pnpm build
RUN mv /app/dist/main/index.html /app/dist/index.html
# ===============================
# 2) 生产镜像阶段
# ===============================
FROM nginx:1.25-alpine AS runtime
# 清理默认 nginx 静态内容
RUN rm -rf /usr/share/nginx/html/*
# 拷贝 build 结果
COPY --from=build /app/dist /usr/share/nginx/html/
# 权限
RUN chmod -R 755 /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]