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(