Merge pull request #644 from infinitycat233/refactor

使用uv加速docker镜像构建
This commit is contained in:
SengokuCola
2025-04-03 22:23:25 +08:00
committed by GitHub
2 changed files with 12 additions and 5 deletions

View File

@@ -13,6 +13,9 @@ on:
jobs: jobs:
build-and-push: build-and-push:
runs-on: ubuntu-latest runs-on: ubuntu-latest
env:
DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USERNAME }}
DATE_TAG: $(date -u +'%Y-%m-%dT%H-%M-%S')
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v4 uses: actions/checkout@v4
@@ -40,7 +43,7 @@ jobs:
elif [ "${{ github.ref }}" == "refs/heads/main-fix" ]; then elif [ "${{ github.ref }}" == "refs/heads/main-fix" ]; then
echo "tags=${{ secrets.DOCKERHUB_USERNAME }}/maimbot:main-fix" >> $GITHUB_OUTPUT echo "tags=${{ secrets.DOCKERHUB_USERNAME }}/maimbot:main-fix" >> $GITHUB_OUTPUT
elif [ "${{ github.ref }}" == "refs/heads/refactor" ]; then # 新增 refactor 分支处理 elif [ "${{ github.ref }}" == "refs/heads/refactor" ]; then # 新增 refactor 分支处理
echo "tags=${{ secrets.DOCKERHUB_USERNAME }}/maimbot:refactor" >> $GITHUB_OUTPUT echo "tags=${{ secrets.DOCKERHUB_USERNAME }}/maimbot:refactor,${{ secrets.DOCKERHUB_USERNAME }}/maimbot:refactor$(date -u +'%Y%m%d%H%M%S')" >> $GITHUB_OUTPUT
fi fi
- name: Build and Push Docker Image - name: Build and Push Docker Image
@@ -52,4 +55,7 @@ jobs:
tags: ${{ steps.tags.outputs.tags }} tags: ${{ steps.tags.outputs.tags }}
push: true push: true
cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/maimbot:buildcache cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/maimbot:buildcache
cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/maimbot:buildcache,mode=max cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/maimbot:buildcache,mode=max
labels: |
org.opencontainers.image.created=${{ steps.tags.outputs.date_tag }}
org.opencontainers.image.revision=${{ github.sha }}

View File

@@ -1,4 +1,5 @@
FROM python:3.13.2-slim-bookworm FROM python:3.13.2-slim-bookworm
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
# 工作目录 # 工作目录
WORKDIR /MaiMBot WORKDIR /MaiMBot
@@ -9,9 +10,9 @@ COPY requirements.txt .
COPY maim_message /maim_message COPY maim_message /maim_message
# 安装依赖 # 安装依赖
RUN pip install --upgrade pip RUN uv pip install --system --upgrade pip
RUN pip install -e /maim_message RUN uv pip install --system -e /maim_message
RUN pip install --upgrade -r requirements.txt RUN uv pip install --system -r requirements.txt
# 复制项目代码 # 复制项目代码
COPY . . COPY . .