From 568ceea3a072f36cd8216bc6476d8ce27034aaa5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=87=8E=E5=8E=9F=E5=B0=8F=E7=89=9B?= Date: Mon, 3 Mar 2025 11:11:39 +0800 Subject: [PATCH] =?UTF-8?q?docker=E7=BC=96=E8=AF=91=E6=80=A7=E8=83=BD?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 6 ++++++ .gitea/workflows/docker-image.yml | 36 +++++++++++++++++++++++++++++++ Dockerfile | 15 ++++++++++--- 3 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 .dockerignore create mode 100644 .gitea/workflows/docker-image.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..0ed9090fd --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +.git +__pycache__ +*.pyc +*.pyo +*.pyd +.DS_Store \ No newline at end of file diff --git a/.gitea/workflows/docker-image.yml b/.gitea/workflows/docker-image.yml new file mode 100644 index 000000000..a5ac92778 --- /dev/null +++ b/.gitea/workflows/docker-image.yml @@ -0,0 +1,36 @@ +name: Docker Build and Push + +on: + push: + branches: + - aijiang # 推送到main分支时触发 + tags: + - "*" # 推送v开头的tag时触发(例如v1.0.0) + workflow_dispatch: # 允许手动触发 + +jobs: + build-and-push: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: https://gitea.neppure.vip/actions/actions/checkout@v4 + + - name: Set up Docker Buildx + uses: https://gitea.neppure.vip/actions/docker/setup-buildx-action@v3 + + - name: Login to Docker Hub + uses: https://gitea.neppure.vip/actions/docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and Push Docker Image + uses: https://gitea.neppure.vip/actions/docker/build-push-action@v5 + with: + context: . # Docker构建上下文路径 + file: ./Dockerfile # Dockerfile路径 + platforms: linux/amd64,linux/arm64 # 支持arm架构 + tags: | + gitea.neppure.vip/NepPure/maimbot:${{ github.ref_name }} + gitea.neppure.vip/NepPure/maimbot:latest + push: true diff --git a/Dockerfile b/Dockerfile index 225a90a1b..8f2b88f64 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,17 @@ FROM nonebot/nb-cli:latest -WORKDIR / -COPY . /MaiMBot/ + +# 设置工作目录 WORKDIR /MaiMBot + +# 先复制依赖列表 +COPY requirements.txt . + +# 安装依赖(这层会被缓存直到requirements.txt改变) RUN pip install --upgrade -r requirements.txt + +# 然后复制项目代码 +COPY . . + VOLUME [ "/MaiMBot/config" ] EXPOSE 8080 -ENTRYPOINT [ "nb","run" ] +ENTRYPOINT [ "nb","run" ] \ No newline at end of file