更改镜像插件为倒序

This commit is contained in:
dxin
2025-12-19 11:43:42 +08:00
parent 480dcd46c3
commit 62a4ced1a6
27 changed files with 595 additions and 5 deletions

View File

@@ -1,12 +1,18 @@
# ===============================
# 1) 依赖安装 + 构建阶段
# ===============================
FROM registry.cn-hangzhou.aliyuncs.com/docker_mirror/node:20.15.0-alpine AS build
FROM node:20.15.0-alpine AS build
WORKDIR /app
# 安装 pnpm 和 git前端使用 pnpm 管理依赖git生成版本信息
RUN npm install -g pnpm --registry=https://registry.npmmirror.com \
&& echo "https://mirrors.aliyun.com/alpine/v$(cat /etc/alpine-release | cut -d '.' -f 1-2)/main/" > /etc/apk/repositories \
&& echo "https://mirrors.aliyun.com/alpine/v$(cat /etc/alpine-release | cut -d '.' -f 1-2)/community/" >> /etc/apk/repositories \
&& apk add --no-cache git
# 只拷贝 package.json加快缓存命中
COPY package.json ./
COPY package.json pnpm-lock.yaml* ./
# 预先安装依赖(利用缓存)
RUN pnpm install --registry=https://registry.npmmirror.com
@@ -14,7 +20,7 @@ RUN pnpm install --registry=https://registry.npmmirror.com
# 拷贝全部代码
COPY . .
# 要求 package.json 中的 script 形如build:sit, build:test, build:prod
# package.json内定义了 build 脚本,执行构建
RUN pnpm build
RUN mv /app/dist/main/index.html /app/dist/index.html
@@ -22,12 +28,13 @@ 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
FROM nginx:1.25-alpine AS runtime
ENV TZ=Asia/Shanghai
# 清理默认 nginx 静态内容
RUN rm -rf /usr/share/nginx/html/*
# 拷贝自定义 nginx 配置文件
COPY nginx.conf /etc/nginx/nginx.conf
# 拷贝 build 结果

View File

@@ -1,4 +1,7 @@
# nginx.conf
user nginx;
worker_processes auto;
events {
worker_connections 1024;
}
@@ -51,6 +54,7 @@ http {
# 静态资源缓存优化
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
root /usr/share/nginx/html;
expires 1y;
add_header Cache-Control "public, immutable";
access_log off;