mirror of
https://github.com/setube/ogame-vue-ts.git
synced 2026-05-12 07:55:11 +08:00
feat(docker): 添加完整的 Docker 构建支持
- 重构 Dockerfile 支持本地完整源码构建流程 - 添加 CI 专用的 Dockerfile.ci 使用预构建产物 - 创建 .dockerignore 和 .dockerignore.ci 文件优化构建上下文 - 添加 build-docker.sh 和 build-docker.bat 本地构建脚本 - 更新 GitHub Actions 工作流支持 Node.js 环境和 pnpm 依赖管理 - 添加 DOCKER.md 详细说明文档 - 优化 nginx 配置和端口暴露设置
This commit is contained in:
38
Dockerfile
38
Dockerfile
@@ -1,22 +1,40 @@
|
||||
FROM node:lts-alpine AS builder
|
||||
# 本地构建用的 Dockerfile
|
||||
# 支持完整的源代码构建流程
|
||||
|
||||
RUN mkdir -p /workspace
|
||||
WORKDIR /workspace
|
||||
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories
|
||||
RUN apk update && apk add git
|
||||
RUN npm config set registry https://registry.npmmirror.com
|
||||
RUN git clone https://github.com/setube/ogame-vue-ts.git
|
||||
RUN mv ./ogame-vue-ts/* . ; rm -rf ./ogame-vue-ts/
|
||||
FROM node:20-alpine AS builder
|
||||
|
||||
RUN npm install -g pnpm ; pnpm install;
|
||||
# 设置工作目录
|
||||
WORKDIR /app
|
||||
|
||||
# 复制 package 文件
|
||||
COPY package.json pnpm-lock.yaml ./
|
||||
|
||||
# 安装 pnpm
|
||||
RUN npm install -g pnpm
|
||||
|
||||
# 安装依赖
|
||||
RUN pnpm install --frozen-lockfile
|
||||
|
||||
# 复制源代码
|
||||
COPY . .
|
||||
|
||||
# 构建项目
|
||||
RUN pnpm run build
|
||||
|
||||
# 生产阶段
|
||||
FROM nginx:alpine
|
||||
|
||||
# 复制 nginx 配置文件
|
||||
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||
|
||||
# 清理默认的 nginx 静态文件
|
||||
RUN rm -rf /usr/share/nginx/html/*
|
||||
COPY --from=builder /workspace/docs /usr/share/nginx/html
|
||||
|
||||
# 复制构建产物到 nginx 静态文件目录
|
||||
COPY --from=builder /app/docs /usr/share/nginx/html
|
||||
|
||||
# 暴露端口
|
||||
EXPOSE 80
|
||||
|
||||
# 启动 nginx
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
Reference in New Issue
Block a user