Compare commits

..

1 Commits

Author SHA1 Message Date
repair-agent
394f30255e fix: auto repair bugs #85 2026-04-02 17:50:18 +08:00
2 changed files with 44 additions and 36 deletions

View File

@ -1,10 +1,11 @@
name: Build and Deploy Log Center
on:
"on":
push:
branches:
- main
- master
- dev
jobs:
build-and-deploy:
@ -13,78 +14,85 @@ jobs:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
config-inline: |
[registry."docker.io"]
mirrors = ["https://docker.m.daocloud.io", "https://docker.1panel.live", "https://hub.rat.dev"]
- name: Set environment by branch
run: |
SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7)
BUILD_DATE=$(date +%Y%m%d)
- name: Login to Huawei Cloud SWR
uses: docker/login-action@v2
with:
registry: ${{ secrets.SWR_SERVER }}
username: ${{ secrets.SWR_USERNAME }}
password: ${{ secrets.SWR_PASSWORD }}
if [[ "${{ github.ref_name }}" == "main" || "${{ github.ref_name }}" == "master" ]]; then
echo "IMAGE_TAG=prod-${BUILD_DATE}-${SHORT_SHA}" >> $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 "IMAGE_TAG=dev-${BUILD_DATE}-${SHORT_SHA}" >> $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: Login to Registry
run: |
echo "${{ secrets.SWR_PASSWORD }}" | docker login --username "${{ secrets.SWR_USERNAME }}" --password-stdin ${{ secrets.SWR_SERVER }}
# Build API Image
- name: Build and Push API
id: build-api
run: |
set -o pipefail
docker buildx build \
--push \
--provenance=false \
docker build \
--tag ${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/log-center-api:${{ env.IMAGE_TAG }} \
--tag ${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/log-center-api:latest \
-f ./Dockerfile \
. 2>&1 | tee /tmp/build-api.log
docker push ${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/log-center-api:${{ env.IMAGE_TAG }}
docker push ${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/log-center-api:latest
# Build Web Image
- name: Build and Push Web
id: build-web
run: |
set -o pipefail
docker buildx build \
--push \
--provenance=false \
--build-arg VITE_API_BASE_URL=https://qiyuan-log-center-api.airlabs.art \
docker build \
--build-arg VITE_API_BASE_URL=https://${{ env.DOMAIN_API }} \
--tag ${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/log-center-web:${{ env.IMAGE_TAG }} \
--tag ${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/log-center-web:latest \
-f ./web/Dockerfile \
./web 2>&1 | tee /tmp/build-web.log
docker push ${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/log-center-web:${{ env.IMAGE_TAG }}
docker push ${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/log-center-web:latest
# Build K8s Monitor Image
- name: Build and Push K8s Monitor
id: build-monitor
run: |
set -o pipefail
docker buildx build \
--push \
--provenance=false \
docker build \
--tag ${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/k8s-pod-monitor:${{ env.IMAGE_TAG }} \
--tag ${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/k8s-pod-monitor:latest \
-f ./k8s-monitor/Dockerfile \
./k8s-monitor 2>&1 | tee /tmp/build-monitor.log
docker push ${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/k8s-pod-monitor:${{ env.IMAGE_TAG }}
docker push ${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/k8s-pod-monitor:latest
- name: Setup Kubectl
- name: Setup Kubectl and Kubeconfig
run: |
curl -LO "https://files.m.daocloud.io/dl.k8s.io/release/v1.28.2/bin/linux/amd64/kubectl"
chmod +x kubectl
mv kubectl /usr/local/bin/
mkdir -p $HOME/.kube
echo "${{ secrets.KUBE_CONFIG }}" > $HOME/.kube/config
chmod 600 $HOME/.kube/config
- name: Deploy to K3s
uses: Azure/k8s-set-context@v3
with:
method: kubeconfig
kubeconfig: ${{ secrets.KUBE_CONFIG }}
- name: Update K8s Manifests
- name: Deploy to K8s
id: deploy
run: |
echo "Environment: Production"
echo "Environment: ${{ env.DEPLOY_ENV }}"
# 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
sed -i "s|\${CI_REGISTRY_IMAGE}/log-center-api:latest|${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/log-center-api:${{ env.IMAGE_TAG }}|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:${{ env.IMAGE_TAG }}|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:${{ env.IMAGE_TAG }}|g" k8s/monitor-cronjob.yaml
# Apply configurations and capture output
set -o pipefail

View File

@ -5,7 +5,7 @@ WORKDIR /app
# Install dependencies
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
RUN pip install --no-cache-dir -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com -r requirements.txt
# Production stage
FROM python:3.12-slim AS production-stage