training_data/Dockerfile

93 lines
2.7 KiB
Docker
Raw Normal View History

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