Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: Dockerfile
  • Loading branch information
Hiram-Wong committed Aug 30, 2025
commit 18b8a0c4a3b4c03ae491878399b470b2debfa41d
34 changes: 27 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 构建器阶段
# 使用node:current-alpine3.21作为基础镜像
FROM node:current-alpine3.21 AS builder
# 使用node:20-alpine(17 < version < 23)作为基础镜像
FROM node:20-alpine AS builder

# 安装git
RUN apk add --no-cache git
Expand All @@ -17,32 +17,52 @@ RUN git clone https://github.com/hjdhnx/drpy-node.git .
# 设置npm镜像为npmmirror
RUN npm config set registry https://registry.npmmirror.com

# 全局安装pm2工具(yarn已经自带了不需要再自己装)
RUN npm install -g pm2

# 安装项目依赖项和puppeteer
RUN yarn && yarn add puppeteer

# 复制工作目录中的所有文件到一个临时目录中
# 以便在运行器阶段中使用
RUN mkdir /tmp/drpys && cp -r /app/* /tmp/drpys/
RUN mkdir -p /tmp/drpys && \
cp -r /app/. /tmp/drpys/


# 运行器阶段
# 使用alpine:latest作为基础镜像来创建一个更小的镜像
# 但是无法用pm2
FROM alpine:latest AS runner

# OCI labels: https://github.com/opencontainers/image-spec/blob/main/annotations.md
LABEL org.opencontainers.image.authors="hjdhnx"
LABEL org.opencontainers.image.licenses="GPL-3.0"
LABEL org.opencontainers.image.title="drpyS"
LABEL org.opencontainers.image.source="https://github.com/hjdhnx/drpy-node"

# 创建一个工作目录
WORKDIR /app

# 复制构建器阶段中准备好的文件和依赖项到运行器阶段的工作目录中
COPY --from=builder /tmp/drpys /app
COPY --from=builder /tmp/drpys/. /app
RUN cp /app/.env.development /app/.env && \
rm -f /app/.env.development && \
sed -i 's|^VIRTUAL_ENV[[:space:]]*=[[:space:]]*$|VIRTUAL_ENV=/app/.venv|' /app/.env && \
echo '{"ali_token":"","ali_refresh_token":"","quark_cookie":"","uc_cookie":"","bili_cookie":"","thread":"10","enable_dr2":"1","enable_py":"2"}' > /app/config/env.json

# 安装Node.js运行时(如果需要的话,这里已经假设在构建器阶段中安装了所有必要的Node.js依赖项)
# 由于我们已经将node_modules目录复制到了运行器阶段,因此这里不需要再次安装npm或node_modules中的依赖项
# 但是,我们仍然需要安装Node.js运行时本身(除非drpys项目是一个纯静态资源服务,不需要Node.js运行时)
RUN apk add --no-cache nodejs

# 安装python3依赖
RUN apk add --no-cache python3 \
py3-pip \
py3-setuptools \
py3-wheel

# 激活python3虚拟环境并安装依pip3赖
RUN python3 -m venv /app/.venv && \
. /app/.venv/bin/activate && \
pip3 install -r /app/spider/py/base/requirements.txt -i https://mirrors.cloud.tencent.com/pypi/simple

# 暴露应用程序端口(根据您的项目需求调整)
EXPOSE 5757

Expand Down