93 lines
2.7 KiB
Docker
Executable File
93 lines
2.7 KiB
Docker
Executable File
# 基础镜像
|
|
FROM node:18.17-alpine as base
|
|
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \
|
|
echo "https://mirrors.aliyun.com/alpine/v3.18/community" >> /etc/apk/repositories
|
|
|
|
RUN yarn config set registry https://registry.npmmirror.com
|
|
RUN yarn global add pnpm && pnpm config set registry https://registry.npmmirror.com
|
|
WORKDIR /app
|
|
COPY pnpm-workspace.yaml ./
|
|
COPY package*.json pnpm-lock.yaml* ./
|
|
COPY tsconfig.base.json .
|
|
|
|
|
|
FROM base As server-build
|
|
WORKDIR /app
|
|
COPY . .
|
|
RUN pnpm install
|
|
RUN pnpm --filter common build
|
|
RUN pnpm --filter tus build
|
|
RUN pnpm --filter utils build
|
|
RUN pnpm --filter server build
|
|
|
|
FROM base As server-prod-dep
|
|
WORKDIR /app
|
|
COPY packages/common /app/packages/common
|
|
COPY packages/tus /app/packages/tus
|
|
COPY apps/server /app/apps/server
|
|
RUN pnpm install --filter common --prod
|
|
RUN pnpm install --filter tus --prod
|
|
RUN pnpm install --filter utils --prod
|
|
RUN pnpm install --filter server --prod
|
|
|
|
|
|
|
|
FROM server-prod-dep as server
|
|
WORKDIR /app
|
|
ENV NODE_ENV production
|
|
COPY --from=server-build /app/packages/common/dist ./packages/common/dist
|
|
COPY --from=server-build /app/packages/tus/dist ./packages/tus/dist
|
|
COPY --from=server-build /app/apps/server/dist ./apps/server/dist
|
|
COPY apps/server/entrypoint.sh ./apps/server/entrypoint.sh
|
|
RUN chmod +x ./apps/server/entrypoint.sh
|
|
RUN apk add --no-cache ffmpeg
|
|
|
|
EXPOSE 3000
|
|
|
|
ENTRYPOINT [ "/app/apps/server/entrypoint.sh" ]
|
|
|
|
|
|
|
|
FROM base AS web-build
|
|
# 复制其余文件到工作目录
|
|
COPY . .
|
|
RUN pnpm install
|
|
RUN pnpm --filter web build
|
|
|
|
# 第二阶段,使用 nginx 提供服务
|
|
FROM nginx:stable-alpine as web
|
|
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
|
|
# 设置工作目录
|
|
WORKDIR /usr/share/nginx/html
|
|
# 设置环境变量
|
|
ENV NODE_ENV production
|
|
# 将构建的文件从上一阶段复制到当前镜像中
|
|
COPY --from=web-build /app/apps/web/dist .
|
|
# 删除默认的nginx配置文件并添加自定义配置
|
|
RUN rm /etc/nginx/conf.d/default.conf
|
|
COPY apps/web/nginx.conf /etc/nginx/conf.d
|
|
# 添加 entrypoint 脚本,并确保其可执行
|
|
COPY apps/web/entrypoint.sh /usr/bin/
|
|
RUN chmod +x /usr/bin/entrypoint.sh
|
|
# 安装 envsubst 以支持环境变量替换
|
|
RUN apk add --no-cache gettext
|
|
# 暴露 80 端口
|
|
EXPOSE 80
|
|
|
|
CMD ["/usr/bin/entrypoint.sh"]
|
|
|
|
|
|
# 使用 Nginx 的 Alpine 版本作为基础镜像
|
|
FROM nginx:stable-alpine as nginx
|
|
# 替换 Alpine 的软件源为阿里云镜像
|
|
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
|
|
# 设置工作目录
|
|
WORKDIR /usr/share/nginx/html
|
|
# 设置环境变量
|
|
ENV NODE_ENV production
|
|
# 安装 envsubst 和 inotify-tools
|
|
RUN apk add --no-cache gettext inotify-tools
|
|
# 创建 /data/uploads 目录
|
|
RUN mkdir -p /data/uploads
|
|
# 暴露 80 端口
|
|
EXPOSE 80 |