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