From 229d86e1583bf4185f114c20cbfb7a7f5113ffe1 Mon Sep 17 00:00:00 2001 From: zyc <1439655764@qq.com> Date: Tue, 24 Feb 2026 10:30:36 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E8=BF=81=E7=A7=BB=E4=BA=8B=E5=8A=A1=E4=B8=AD=E6=96=AD?= =?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=8C=E8=A1=A5=E5=85=85=20k8s-monitor=20?= =?UTF-8?q?=E6=9E=84=E5=BB=BA=E6=B5=81=E6=B0=B4=E7=BA=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - database.py: 使用 IF NOT EXISTS 避免 PostgreSQL 事务中断导致后续迁移 SQL 不执行 - deploy.yaml: 补充 k8s-pod-monitor 镜像构建和 CronJob 部署步骤 Co-Authored-By: Claude Opus 4.6 --- .gitea/workflows/deploy.yaml | 16 ++++++++++++++-- app/database.py | 10 +++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/.gitea/workflows/deploy.yaml b/.gitea/workflows/deploy.yaml index 617839a..11bddae 100644 --- a/.gitea/workflows/deploy.yaml +++ b/.gitea/workflows/deploy.yaml @@ -49,6 +49,16 @@ jobs: build-args: | VITE_API_BASE_URL=https://qiyuan-log-center-api.airlabs.art + # Build K8s Monitor Image + - name: Build and Push K8s Monitor + uses: docker/build-push-action@v4 + with: + context: ./k8s-monitor + file: ./k8s-monitor/Dockerfile + push: true + provenance: false + tags: ${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/k8s-pod-monitor:latest + - name: Setup Kubectl run: | curl -LO "https://files.m.daocloud.io/dl.k8s.io/release/v1.28.2/bin/linux/amd64/kubectl" @@ -68,12 +78,14 @@ jobs: # Replace image placeholders sed -i "s|\${CI_REGISTRY_IMAGE}/log-center-api:latest|${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/log-center-api:latest|g" k8s/api-deployment-prod.yaml sed -i "s|\${CI_REGISTRY_IMAGE}/log-center-web:latest|${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/log-center-web:latest|g" k8s/web-deployment-prod.yaml - + sed -i "s|\${CI_REGISTRY_IMAGE}/k8s-pod-monitor:latest|${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/k8s-pod-monitor:latest|g" k8s/monitor-cronjob.yaml + # Apply configurations kubectl apply -f k8s/api-deployment-prod.yaml kubectl apply -f k8s/web-deployment-prod.yaml kubectl apply -f k8s/ingress.yaml - + kubectl apply -f k8s/monitor-cronjob.yaml + # Restart deployments kubectl rollout restart deployment/log-center-api kubectl rollout restart deployment/log-center-web diff --git a/app/database.py b/app/database.py index fdd687b..aeb047f 100644 --- a/app/database.py +++ b/app/database.py @@ -25,19 +25,19 @@ async def init_db(): # Migrate: add new columns to existing repairtask table migrations = [ - "ALTER TABLE repairtask ADD COLUMN repair_round INTEGER DEFAULT 1", - "ALTER TABLE repairtask ADD COLUMN failure_reason TEXT", + "ALTER TABLE repairtask ADD COLUMN IF NOT EXISTS repair_round INTEGER DEFAULT 1", + "ALTER TABLE repairtask ADD COLUMN IF NOT EXISTS failure_reason TEXT", # Log source support - "ALTER TABLE errorlog ADD COLUMN source VARCHAR(20) DEFAULT 'runtime'", + "ALTER TABLE errorlog ADD COLUMN IF NOT EXISTS source VARCHAR(20) DEFAULT 'runtime'", "ALTER TABLE errorlog ALTER COLUMN file_path DROP NOT NULL", "ALTER TABLE errorlog ALTER COLUMN line_number DROP NOT NULL", - "CREATE INDEX ix_errorlog_source ON errorlog (source)", + "CREATE INDEX IF NOT EXISTS ix_errorlog_source ON errorlog (source)", ] for sql in migrations: try: await conn.execute(text(sql)) except Exception: - pass # Column already exists + pass # Already applied async def get_session() -> AsyncSession: async_session = sessionmaker(