feat: 添加 Gitea Actions CI/CD — tag 驱动环境部署
GraphRAG CI/CD / build-and-deploy (push) Failing after 3m49s
GraphRAG CI/CD / build-and-deploy (push) Failing after 3m49s
- git push → 构建镜像 (sha-xxx) → 部署到 test (graphrag-test) - git push --tags → 构建镜像 (vx.y.z) → 部署到 prod (graphrag-prod) - DNS + hostAliases + nodeAffinity 固化到 deployment yaml - 前后端均固定到 k8smaster 节点,便于 CI 导入 containerd 镜像
This commit is contained in:
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user