feat: add Docker support with multi-stage build and CI/CD workflow
All checks were successful
Build and Push Docker Image / build (push) Successful in 1m42s
All checks were successful
Build and Push Docker Image / build (push) Successful in 1m42s
- Introduced Dockerfile for multi-stage build process using Node.js and Nginx. - Added .dockerignore to exclude unnecessary files from Docker context. - Created nginx.conf for server configuration, including gzip compression and SPA routing. - Implemented Gitea CI/CD workflow for building and pushing Docker images on version tags.
This commit is contained in:
36
Dockerfile
Normal file
36
Dockerfile
Normal file
@@ -0,0 +1,36 @@
|
||||
# 第一阶段: 构建应用
|
||||
FROM node:22-alpine AS builder
|
||||
|
||||
# 安装 pnpm
|
||||
RUN npm install -g pnpm
|
||||
|
||||
# 设置工作目录
|
||||
WORKDIR /app
|
||||
|
||||
# 复制依赖配置文件
|
||||
COPY package.json pnpm-lock.yaml ./
|
||||
|
||||
# 安装依赖
|
||||
RUN pnpm install --frozen-lockfile
|
||||
|
||||
# 复制源代码
|
||||
COPY . .
|
||||
|
||||
# 构建应用
|
||||
RUN pnpm build
|
||||
|
||||
# 第二阶段: 运行应用
|
||||
FROM nginx:alpine
|
||||
|
||||
# 复制自定义 nginx 配置
|
||||
COPY nginx.conf /etc/nginx/nginx.conf
|
||||
|
||||
# 从构建阶段复制构建产物
|
||||
COPY --from=builder /app/dist /usr/share/nginx/html
|
||||
|
||||
# 暴露端口
|
||||
EXPOSE 80
|
||||
|
||||
# 启动 nginx
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
|
||||
Reference in New Issue
Block a user