Skip to content

Commit 6d0fe2c

Browse files
authored
Merge pull request #49 from Hiram-Wong/main
cicd docker build and fix dockerfile
2 parents 43e0feb + a95dbe4 commit 6d0fe2c

File tree

2 files changed

+73
-10
lines changed

2 files changed

+73
-10
lines changed

.github/workflows/build-docker.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: build-docker
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- v*
9+
10+
env:
11+
REGISTRY: ghcr.io
12+
IMAGE_NAME: ${{ github.repository }}
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: read
19+
packages: write
20+
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v4
24+
25+
- name: Set up QEMU
26+
uses: docker/setup-qemu-action@v3
27+
28+
- name: Set up Docker Buildx
29+
uses: docker/setup-buildx-action@v3
30+
31+
- name: Login to GitHub Container Registry
32+
uses: docker/login-action@v3
33+
with:
34+
registry: ${{ env.REGISTRY }}
35+
username: ${{ github.actor }}
36+
password: ${{ secrets.GITHUB_TOKEN }}
37+
38+
- name: Extract metadata (tags, labels)
39+
id: meta
40+
uses: docker/metadata-action@v5
41+
with:
42+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
43+
44+
- name: Build and push
45+
uses: docker/build-push-action@v6
46+
with:
47+
platforms: linux/amd64,linux/arm64
48+
context: .
49+
file: Dockerfile
50+
push: true
51+
tags: ${{ steps.meta.outputs.tags }}
52+
labels: ${{ steps.meta.outputs.labels }}

Dockerfile

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 构建器阶段
2-
# 使用node:current-alpine3.21作为基础镜像
3-
FROM node:current-alpine3.21 AS builder
2+
# 使用node:20-alpine(17 < version < 23)作为基础镜像
3+
FROM node:20-alpine AS builder
44

55
# 安装git
66
RUN apk add --no-cache git
@@ -14,18 +14,14 @@ WORKDIR /app
1414
# 克隆GitHub仓库到工作目录
1515
RUN git clone https://github.com/hjdhnx/drpy-node.git .
1616

17-
# 设置npm镜像为npmmirror
18-
RUN npm config set registry https://registry.npmmirror.com
19-
20-
# 全局安装pm2工具(yarn已经自带了不需要再自己装)
21-
RUN npm install -g pm2
22-
2317
# 安装项目依赖项和puppeteer
2418
RUN yarn && yarn add puppeteer
2519

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

3026
# 运行器阶段
3127
# 使用alpine:latest作为基础镜像来创建一个更小的镜像
@@ -36,13 +32,28 @@ FROM alpine:latest AS runner
3632
WORKDIR /app
3733

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

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

46+
# 安装python3依赖
47+
RUN apk add --no-cache python3 \
48+
py3-pip \
49+
py3-setuptools \
50+
py3-wheel
51+
52+
# 激活python3虚拟环境并安装依pip3赖
53+
RUN python3 -m venv /app/.venv && \
54+
. /app/.venv/bin/activate && \
55+
pip3 install -r /app/spider/py/base/requirements.txt
56+
4657
# 暴露应用程序端口(根据您的项目需求调整)
4758
EXPOSE 5757
4859

0 commit comments

Comments
 (0)