add docker support
This commit is contained in:
53
.docker/Dockerfile
Normal file
53
.docker/Dockerfile
Normal file
@ -0,0 +1,53 @@
|
||||
# 构建阶段使用 Node 镜像
|
||||
FROM node:22-alpine as builder
|
||||
|
||||
# 设置工作目录
|
||||
WORKDIR /app
|
||||
|
||||
# 设置阿里云镜像源
|
||||
RUN yarn config set registry https://registry.npmmirror.com/ && \
|
||||
npm config set registry https://registry.npmmirror.com/
|
||||
|
||||
# 复制 package.json 和 yarn.lock
|
||||
COPY package.json yarn.lock ./
|
||||
|
||||
# 安装依赖
|
||||
RUN yarn
|
||||
|
||||
# 复制源代码
|
||||
COPY . .
|
||||
|
||||
# 构建项目
|
||||
RUN yarn build
|
||||
|
||||
# 使用轻量级的 Node 镜像作为基础镜像
|
||||
FROM node:22-alpine
|
||||
|
||||
# 设置工作目录
|
||||
WORKDIR /app
|
||||
|
||||
# 设置阿里云镜像源
|
||||
RUN yarn config set registry https://registry.npmmirror.com/ && \
|
||||
npm config set registry https://registry.npmmirror.com/
|
||||
|
||||
# 安装简单的静态文件服务器
|
||||
RUN yarn global add serve
|
||||
|
||||
# 将构建产物复制到工作目录
|
||||
COPY --from=builder /app/dist ./dist
|
||||
|
||||
# 复制环境变量注入脚本
|
||||
COPY .docker/env.sh ./env.sh
|
||||
RUN chmod +x ./env.sh
|
||||
|
||||
# 暴露服务端口
|
||||
EXPOSE 5000
|
||||
|
||||
# 设置环境变量
|
||||
ENV PORT=5000
|
||||
ENV NODE_ENV=production
|
||||
ARG BASE_URL
|
||||
ENV BASE_URL=${BASE_URL}
|
||||
|
||||
# 启动命令:先执行环境变量注入脚本,再启动静态服务器
|
||||
CMD ["/bin/sh", "-c", "./env.sh && serve -s dist"]
|
Reference in New Issue
Block a user