From 58079daba9573b582e06aba397c1623fb16f2949 Mon Sep 17 00:00:00 2001 From: plf1996 Date: Thu, 18 Jun 2026 14:26:15 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=20Gitea=20Actions=20?= =?UTF-8?q?CI/CD=20=E2=80=94=20tag=20=E9=A9=B1=E5=8A=A8=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E9=83=A8=E7=BD=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - git push → 构建镜像 (sha-xxx) → 部署到 test (graphrag-test) - git push --tags → 构建镜像 (vx.y.z) → 部署到 prod (graphrag-prod) - DNS + hostAliases + nodeAffinity 固化到 deployment yaml - 前后端均固定到 k8smaster 节点,便于 CI 导入 containerd 镜像 --- .gitea/workflows/ci.yml | 87 +++++++++++++++++++++++++++++++ k8s/base/backend-deployment.yaml | 21 ++++++++ k8s/base/frontend-deployment.yaml | 17 ++++++ 3 files changed, 125 insertions(+) create mode 100644 .gitea/workflows/ci.yml diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml new file mode 100644 index 0000000..e3b71b9 --- /dev/null +++ b/.gitea/workflows/ci.yml @@ -0,0 +1,87 @@ +name: GraphRAG CI/CD + +on: + push: + branches: [master] + tags: ['v*'] + +jobs: + build-and-deploy: + runs-on: docker + steps: + - name: Clone + run: | + git clone https://git.plfai.cn/test/GraphRAGAgent.git . + git checkout ${GITHUB_SHA} + + - name: Set image tag + id: tag + run: | + if echo "${GITHUB_REF}" | grep -q 'refs/tags/'; then + IMG_TAG="${GITHUB_REF#refs/tags/}" + echo "ENV=prod" >> "$GITHUB_OUTPUT" + else + IMG_TAG="sha-${GITHUB_SHA:0:7}" + echo "ENV=test" >> "$GITHUB_OUTPUT" + fi + echo "TAG=${IMG_TAG}" >> "$GITHUB_OUTPUT" + echo "Image tag: ${IMG_TAG}" + + - name: Build backend + run: | + docker build --network host \ + -f backend/Dockerfile \ + -t registry.plfai.cn/graphrag-backend:${{ steps.tag.outputs.TAG }} \ + -t registry.plfai.cn/graphrag-backend:latest \ + . + + - name: Build frontend + run: | + docker build --network host \ + -f frontend/Dockerfile \ + -t registry.plfai.cn/graphrag-frontend:${{ steps.tag.outputs.TAG }} \ + -t registry.plfai.cn/graphrag-frontend:latest \ + . + + - name: Push images + run: | + echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login registry.plfai.cn -u k3s --password-stdin + docker push registry.plfai.cn/graphrag-backend:${{ steps.tag.outputs.TAG }} + docker push registry.plfai.cn/graphrag-backend:latest + docker push registry.plfai.cn/graphrag-frontend:${{ steps.tag.outputs.TAG }} + docker push registry.plfai.cn/graphrag-frontend:latest + + - name: Import to containerd + run: | + docker save registry.plfai.cn/graphrag-backend:${{ steps.tag.outputs.TAG }} | k3s ctr images import - + docker save registry.plfai.cn/graphrag-frontend:${{ steps.tag.outputs.TAG }} | k3s ctr images import - + + - name: Deploy to test + if: steps.tag.outputs.ENV == 'test' + run: | + NS=graphrag-test + TAG=${{ steps.tag.outputs.TAG }} + + k3s kubectl set image deployment/backend backend=registry.plfai.cn/graphrag-backend:${TAG} -n ${NS} + k3s kubectl set image deployment/frontend frontend=registry.plfai.cn/graphrag-frontend:${TAG} -n ${NS} + + k3s kubectl rollout status deployment/backend -n ${NS} --timeout=120s + k3s kubectl rollout status deployment/frontend -n ${NS} --timeout=60s + + sleep 3 + curl -sk --connect-timeout 10 --retry 3 https://test-graphrag.plfai.cn/api/v1/health | grep healthy + + - name: Deploy to prod + if: steps.tag.outputs.ENV == 'prod' + run: | + NS=graphrag-prod + TAG=${{ steps.tag.outputs.TAG }} + + k3s kubectl set image deployment/backend backend=registry.plfai.cn/graphrag-backend:${TAG} -n ${NS} + k3s kubectl set image deployment/frontend frontend=registry.plfai.cn/graphrag-frontend:${TAG} -n ${NS} + + k3s kubectl rollout status deployment/backend -n ${NS} --timeout=120s + k3s kubectl rollout status deployment/frontend -n ${NS} --timeout=60s + + sleep 3 + curl -sk --connect-timeout 10 --retry 3 https://graphrag.plfai.cn/api/v1/health | grep healthy diff --git a/k8s/base/backend-deployment.yaml b/k8s/base/backend-deployment.yaml index bd99d49..b3005e9 100644 --- a/k8s/base/backend-deployment.yaml +++ b/k8s/base/backend-deployment.yaml @@ -17,6 +17,27 @@ spec: app: graphrag component: backend spec: + hostAliases: + - ip: "10.42.0.1" + hostnames: + - keycloak.plfai.cn + dnsConfig: + options: + - name: ndots + value: "1" + - name: timeout + value: "3" + - name: attempts + value: "2" + affinity: + nodeAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + nodeSelectorTerms: + - matchExpressions: + - key: kubernetes.io/hostname + operator: In + values: + - k8smaster containers: - name: backend image: registry.plfai.cn/graphrag-backend:latest diff --git a/k8s/base/frontend-deployment.yaml b/k8s/base/frontend-deployment.yaml index 4cb30b9..ad976b2 100644 --- a/k8s/base/frontend-deployment.yaml +++ b/k8s/base/frontend-deployment.yaml @@ -17,6 +17,23 @@ spec: app: graphrag component: frontend spec: + dnsConfig: + options: + - name: ndots + value: "1" + - name: timeout + value: "3" + - name: attempts + value: "2" + affinity: + nodeAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + nodeSelectorTerms: + - matchExpressions: + - key: kubernetes.io/hostname + operator: In + values: + - k8smaster containers: - name: frontend image: registry.plfai.cn/graphrag-frontend:latest