docker编译性能优化

This commit is contained in:
野原小牛
2025-03-03 11:11:39 +08:00
parent a7d44e3f0e
commit 568ceea3a0
3 changed files with 54 additions and 3 deletions

6
.dockerignore Normal file
View File

@@ -0,0 +1,6 @@
.git
__pycache__
*.pyc
*.pyo
*.pyd
.DS_Store

View File

@@ -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

View File

@@ -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" ]