diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index b73a361..fc40c97 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -2,7 +2,7 @@ name: Docker Image CI on: push: - branches: [ "main" ] + branches: [ "main", "dev" ] jobs: @@ -32,7 +32,11 @@ jobs: - name: Determine Image Tags id: tags run: | - echo "tags=${{ secrets.DOCKERHUB_USERNAME }}/maimbot-adapter:latest,${{ secrets.DOCKERHUB_USERNAME }}/maimbot-adapter:main-$(date -u +'%Y%m%d%H%M%S')" >> $GITHUB_OUTPUT + if [ "${{ github.ref_name }}" == "main" ]; then + echo "tags=${{ secrets.DOCKERHUB_USERNAME }}/maimbot-adapter:latest,${{ secrets.DOCKERHUB_USERNAME }}/maimbot-adapter:main-$(date -u +'%Y%m%d%H%M%S')" >> $GITHUB_OUTPUT + elif [ "${{ github.ref_name }}" == "dev" ]; then + echo "tags=${{ secrets.DOCKERHUB_USERNAME }}/maimbot-adapter:dev,${{ secrets.DOCKERHUB_USERNAME }}/maimbot-adapter:dev-$(date -u +'%Y%m%d%H%M%S')" >> $GITHUB_OUTPUT + fi - name: Build and Push Docker Image uses: docker/build-push-action@v5 @@ -42,8 +46,8 @@ jobs: platforms: linux/amd64,linux/arm64 tags: ${{ steps.tags.outputs.tags }} push: true - cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/maimbot-adapter:buildcache - cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/maimbot-adapter:buildcache,mode=max + cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/maimbot-adapter:buildcache-${{ github.ref_name }} + cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/maimbot-adapter:buildcache-${{ github.ref_name }},mode=max labels: | org.opencontainers.image.created=${{ steps.tags.outputs.date_tag }} org.opencontainers.image.revision=${{ github.sha }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 7dee666..d50a5f0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.13.2-slim +FROM python:3.13.5-slim LABEL authors="infinitycat233" # Copy uv and maim_message diff --git a/src/config/config.py b/src/config/config.py index a219078..5143f39 100644 --- a/src/config/config.py +++ b/src/config/config.py @@ -1,5 +1,6 @@ import os from dataclasses import dataclass +from datetime import datetime import tomlkit import shutil @@ -56,11 +57,16 @@ def update_config(): else: logger.info("已有配置文件未检测到版本号,可能是旧版本。将进行更新") + # 创建备份文件夹 + backup_dir = "config_backup" + os.makedirs(backup_dir, exist_ok=True) + # 备份文件名 - old_backup_path = "config.toml.back" + timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") + old_backup_path = os.path.join(backup_dir, f"config.toml.bak.{timestamp}") # 备份旧配置文件 - shutil.move(old_config_path, old_backup_path) + shutil.copy2(old_config_path, old_backup_path) logger.info(f"已备份旧配置文件到: {old_backup_path}") # 复制模板文件到配置目录