add cicd 迁移
Some checks failed
Build and Deploy Log Center / build-and-deploy (push) Failing after 12m39s
Some checks failed
Build and Deploy Log Center / build-and-deploy (push) Failing after 12m39s
This commit is contained in:
parent
cbcf7737d0
commit
eeb27514bb
@ -3,8 +3,8 @@ name: Build and Deploy Log Center
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
|
||||||
- master
|
- master
|
||||||
|
- dev
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-and-deploy:
|
build-and-deploy:
|
||||||
@ -13,6 +13,20 @@ jobs:
|
|||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Set environment by branch
|
||||||
|
run: |
|
||||||
|
if [[ "${{ github.ref_name }}" == "master" ]]; then
|
||||||
|
echo "CR_ORG=prod" >> $GITHUB_ENV
|
||||||
|
echo "DEPLOY_ENV=production" >> $GITHUB_ENV
|
||||||
|
echo "DOMAIN_API=qiyuan-log-center-api.airlabs.art" >> $GITHUB_ENV
|
||||||
|
echo "DOMAIN_WEB=qiyuan-log-center-web.airlabs.art" >> $GITHUB_ENV
|
||||||
|
elif [[ "${{ github.ref_name }}" == "dev" ]]; then
|
||||||
|
echo "CR_ORG=dev" >> $GITHUB_ENV
|
||||||
|
echo "DEPLOY_ENV=development" >> $GITHUB_ENV
|
||||||
|
echo "DOMAIN_API=qiyuan-log-center-api.test.airlabs.art" >> $GITHUB_ENV
|
||||||
|
echo "DOMAIN_WEB=qiyuan-log-center-web.test.airlabs.art" >> $GITHUB_ENV
|
||||||
|
fi
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v2
|
uses: docker/setup-buildx-action@v2
|
||||||
with:
|
with:
|
||||||
@ -20,12 +34,12 @@ jobs:
|
|||||||
[registry."docker.io"]
|
[registry."docker.io"]
|
||||||
mirrors = ["https://docker.m.daocloud.io", "https://docker.1panel.live", "https://hub.rat.dev"]
|
mirrors = ["https://docker.m.daocloud.io", "https://docker.1panel.live", "https://hub.rat.dev"]
|
||||||
|
|
||||||
- name: Login to Huawei Cloud SWR
|
- name: Login to Volcano Engine CR
|
||||||
uses: docker/login-action@v2
|
uses: docker/login-action@v2
|
||||||
with:
|
with:
|
||||||
registry: ${{ secrets.SWR_SERVER }}
|
registry: ${{ secrets.CR_SERVER }}
|
||||||
username: ${{ secrets.SWR_USERNAME }}
|
username: ${{ secrets.CR_USERNAME }}
|
||||||
password: ${{ secrets.SWR_PASSWORD }}
|
password: ${{ secrets.CR_PASSWORD }}
|
||||||
|
|
||||||
# Build API Image
|
# Build API Image
|
||||||
- name: Build and Push API
|
- name: Build and Push API
|
||||||
@ -35,7 +49,7 @@ jobs:
|
|||||||
docker buildx build \
|
docker buildx build \
|
||||||
--push \
|
--push \
|
||||||
--provenance=false \
|
--provenance=false \
|
||||||
--tag ${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/log-center-api:latest \
|
--tag ${{ secrets.CR_SERVER }}/${{ env.CR_ORG }}/log-center-api:latest \
|
||||||
-f ./Dockerfile \
|
-f ./Dockerfile \
|
||||||
. 2>&1 | tee /tmp/build-api.log
|
. 2>&1 | tee /tmp/build-api.log
|
||||||
|
|
||||||
@ -47,8 +61,8 @@ jobs:
|
|||||||
docker buildx build \
|
docker buildx build \
|
||||||
--push \
|
--push \
|
||||||
--provenance=false \
|
--provenance=false \
|
||||||
--build-arg VITE_API_BASE_URL=https://qiyuan-log-center-api.airlabs.art \
|
--build-arg VITE_API_BASE_URL=https://${{ env.DOMAIN_API }} \
|
||||||
--tag ${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/log-center-web:latest \
|
--tag ${{ secrets.CR_SERVER }}/${{ env.CR_ORG }}/log-center-web:latest \
|
||||||
-f ./web/Dockerfile \
|
-f ./web/Dockerfile \
|
||||||
./web 2>&1 | tee /tmp/build-web.log
|
./web 2>&1 | tee /tmp/build-web.log
|
||||||
|
|
||||||
@ -60,7 +74,7 @@ jobs:
|
|||||||
docker buildx build \
|
docker buildx build \
|
||||||
--push \
|
--push \
|
||||||
--provenance=false \
|
--provenance=false \
|
||||||
--tag ${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/k8s-pod-monitor:latest \
|
--tag ${{ secrets.CR_SERVER }}/${{ env.CR_ORG }}/k8s-pod-monitor:latest \
|
||||||
-f ./k8s-monitor/Dockerfile \
|
-f ./k8s-monitor/Dockerfile \
|
||||||
./k8s-monitor 2>&1 | tee /tmp/build-monitor.log
|
./k8s-monitor 2>&1 | tee /tmp/build-monitor.log
|
||||||
|
|
||||||
@ -70,21 +84,34 @@ jobs:
|
|||||||
chmod +x kubectl
|
chmod +x kubectl
|
||||||
mv kubectl /usr/local/bin/
|
mv kubectl /usr/local/bin/
|
||||||
|
|
||||||
- name: Deploy to K3s
|
- name: Set kubeconfig
|
||||||
uses: Azure/k8s-set-context@v3
|
run: |
|
||||||
with:
|
mkdir -p $HOME/.kube
|
||||||
method: kubeconfig
|
if [[ "${{ github.ref_name }}" == "master" ]]; then
|
||||||
kubeconfig: ${{ secrets.KUBE_CONFIG }}
|
echo "${{ secrets.VOLCANO_PROD_KUBE_CONFIG }}" > $HOME/.kube/config
|
||||||
|
elif [[ "${{ github.ref_name }}" == "dev" ]]; then
|
||||||
|
echo "${{ secrets.VOLCANO_TEST_KUBE_CONFIG }}" > $HOME/.kube/config
|
||||||
|
fi
|
||||||
|
chmod 600 $HOME/.kube/config
|
||||||
|
|
||||||
- name: Update K8s Manifests
|
- name: Deploy to K3s
|
||||||
id: deploy
|
id: deploy
|
||||||
run: |
|
run: |
|
||||||
echo "Environment: Production"
|
echo "Environment: ${{ env.DEPLOY_ENV }}"
|
||||||
|
echo "API Domain: ${{ env.DOMAIN_API }}"
|
||||||
|
echo "Web Domain: ${{ env.DOMAIN_WEB }}"
|
||||||
|
|
||||||
# Replace image placeholders
|
# 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-api:latest|${{ secrets.CR_SERVER }}/${{ env.CR_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}/log-center-web:latest|${{ secrets.CR_SERVER }}/${{ env.CR_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
|
sed -i "s|\${CI_REGISTRY_IMAGE}/k8s-pod-monitor:latest|${{ secrets.CR_SERVER }}/${{ env.CR_ORG }}/k8s-pod-monitor:latest|g" k8s/monitor-cronjob.yaml
|
||||||
|
|
||||||
|
# Replace domain placeholders in ingress
|
||||||
|
sed -i "s|qiyuan-log-center-api.airlabs.art|${{ env.DOMAIN_API }}|g" k8s/ingress.yaml
|
||||||
|
sed -i "s|qiyuan-log-center-web.airlabs.art|${{ env.DOMAIN_WEB }}|g" k8s/ingress.yaml
|
||||||
|
|
||||||
|
# Replace LOG_CENTER_URL in monitor
|
||||||
|
sed -i "s|https://qiyuan-log-center-api.airlabs.art|https://${{ env.DOMAIN_API }}|g" k8s/monitor-cronjob.yaml
|
||||||
|
|
||||||
# Apply configurations and capture output
|
# Apply configurations and capture output
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
@ -153,11 +180,11 @@ jobs:
|
|||||||
ERROR_TYPE="DockerBuildError"
|
ERROR_TYPE="DockerBuildError"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
curl -s -X POST "https://qiyuan-log-center-api.airlabs.art/api/v1/logs/report" \
|
curl -s -X POST "https://${{ env.DOMAIN_API }}/api/v1/logs/report" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d "{
|
-d "{
|
||||||
\"project_id\": \"${PROJECT_ID}\",
|
\"project_id\": \"${PROJECT_ID}\",
|
||||||
\"environment\": \"${{ github.ref_name }}\",
|
\"environment\": \"${{ env.DEPLOY_ENV }}\",
|
||||||
\"level\": \"ERROR\",
|
\"level\": \"ERROR\",
|
||||||
\"source\": \"${SOURCE}\",
|
\"source\": \"${SOURCE}\",
|
||||||
\"commit_hash\": \"${{ github.sha }}\",
|
\"commit_hash\": \"${{ github.sha }}\",
|
||||||
|
|||||||
@ -11,10 +11,10 @@ load_dotenv()
|
|||||||
DB_USER = os.getenv("DB_USER")
|
DB_USER = os.getenv("DB_USER")
|
||||||
DB_PASSWORD = os.getenv("DB_PASSWORD")
|
DB_PASSWORD = os.getenv("DB_PASSWORD")
|
||||||
DB_HOST = os.getenv("DB_HOST")
|
DB_HOST = os.getenv("DB_HOST")
|
||||||
DB_PORT = os.getenv("DB_PORT", "5432")
|
DB_PORT = os.getenv("DB_PORT", "3306")
|
||||||
DB_NAME = os.getenv("DB_NAME")
|
DB_NAME = os.getenv("DB_NAME")
|
||||||
|
|
||||||
DATABASE_URL = f"postgresql+asyncpg://{DB_USER}:{DB_PASSWORD}@{DB_HOST}:{DB_PORT}/{DB_NAME}"
|
DATABASE_URL = f"mysql+aiomysql://{DB_USER}:{DB_PASSWORD}@{DB_HOST}:{DB_PORT}/{DB_NAME}?charset=utf8mb4"
|
||||||
|
|
||||||
_engine = None
|
_engine = None
|
||||||
|
|
||||||
@ -57,9 +57,9 @@ async def init_db():
|
|||||||
"ALTER TABLE repairtask ADD COLUMN IF NOT EXISTS failure_reason TEXT",
|
"ALTER TABLE repairtask ADD COLUMN IF NOT EXISTS failure_reason TEXT",
|
||||||
# Log source support
|
# Log source support
|
||||||
"ALTER TABLE errorlog ADD COLUMN IF NOT EXISTS 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 MODIFY COLUMN file_path VARCHAR(255) NULL",
|
||||||
"ALTER TABLE errorlog ALTER COLUMN line_number DROP NOT NULL",
|
"ALTER TABLE errorlog MODIFY COLUMN line_number INTEGER NULL",
|
||||||
"CREATE INDEX IF NOT EXISTS ix_errorlog_source ON errorlog (source)",
|
"CREATE INDEX ix_errorlog_source ON errorlog (source)",
|
||||||
# ErrorLog failure_reason
|
# ErrorLog failure_reason
|
||||||
"ALTER TABLE errorlog ADD COLUMN IF NOT EXISTS failure_reason TEXT",
|
"ALTER TABLE errorlog ADD COLUMN IF NOT EXISTS failure_reason TEXT",
|
||||||
# Bug severity (1-10 AI评估等级)
|
# Bug severity (1-10 AI评估等级)
|
||||||
|
|||||||
@ -328,9 +328,9 @@ async def get_repair_reports(
|
|||||||
if project_id:
|
if project_id:
|
||||||
query = query.where(RepairTask.project_id == project_id)
|
query = query.where(RepairTask.project_id == project_id)
|
||||||
if error_log_id:
|
if error_log_id:
|
||||||
# PostgreSQL JSONB contains: error_log_ids @> '[28]'
|
# MySQL JSON contains
|
||||||
query = query.where(
|
query = query.where(
|
||||||
text(f"error_log_ids @> '{json.dumps([error_log_id])}'::jsonb")
|
text(f"JSON_CONTAINS(error_log_ids, '{json.dumps([error_log_id])}')")
|
||||||
)
|
)
|
||||||
|
|
||||||
offset = (page - 1) * page_size
|
offset = (page - 1) * page_size
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
fastapi
|
fastapi
|
||||||
uvicorn[standard]
|
uvicorn[standard]
|
||||||
sqlmodel
|
sqlmodel
|
||||||
psycopg2-binary
|
aiomysql
|
||||||
asyncpg
|
pymysql
|
||||||
python-dotenv
|
python-dotenv
|
||||||
httpx
|
httpx
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user