73 lines
3.8 KiB
YAML
73 lines
3.8 KiB
YAML
name: Deploy im-server (k3s test cluster)
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
inputs:
|
|
image_tag:
|
|
description: '镜像tag,默认为 test(与集群 kustomization 里的 newTag 一致)'
|
|
required: false
|
|
|
|
jobs:
|
|
deploy:
|
|
runs-on: deploy-host
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: 确定镜像tag
|
|
id: vars
|
|
run: |
|
|
TAG="${{ github.event.inputs.image_tag }}"
|
|
[ -z "$TAG" ] && TAG=test
|
|
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: 登录镜像仓库
|
|
run: echo "${{ secrets.REGISTRY_TOKEN }}" | docker login git.118im.com -u admin --password-stdin
|
|
|
|
- name: 构建并推送镜像(从本仓库源码编译,不是官方预编译包)
|
|
run: |
|
|
docker build -f docker/tinode/Dockerfile.build \
|
|
-t git.118im.com/im_team/im-server:${{ steps.vars.outputs.tag }} .
|
|
docker push git.118im.com/im_team/im-server:${{ steps.vars.outputs.tag }}
|
|
|
|
- name: 部署到k3s测试集群
|
|
run: |
|
|
mkdir -p ~/.kube
|
|
echo "${{ secrets.KUBECONFIG }}" > ~/.kube/config
|
|
chmod 600 ~/.kube/config
|
|
kubectl set resources statefulset/im-server -n im-server-system -c im-server \
|
|
--requests=cpu=1,memory=512Mi --limits=cpu=2,memory=1Gi
|
|
kubectl set env statefulset/im-server -n im-server-system -c im-server \
|
|
CLUSTER_PROXY_TO_MASTER_BUFFER=4096 \
|
|
CLUSTER_PROXY_TO_MASTER_WORKERS=16 \
|
|
CLUSTER_PROXY_TO_MASTER_ENQUEUE_TIMEOUT_MS=300 \
|
|
CLUSTER_ROUTE_RETRIES=3 \
|
|
CLUSTER_ROUTE_RETRY_BACKOFF_MS=25
|
|
kubectl patch statefulset/im-server -n im-server-system --type=strategic -p \
|
|
'{"spec":{"template":{"spec":{"containers":[{"name":"im-server","readinessProbe":{"httpGet":{"path":"/healthz","port":6060},"timeoutSeconds":3,"periodSeconds":10,"failureThreshold":3},"livenessProbe":{"httpGet":{"path":"/livez","port":6060},"timeoutSeconds":3,"periodSeconds":20,"failureThreshold":3}}]}}}}'
|
|
if kubectl auth can-i get services -n im-server-system >/dev/null 2>&1 && \
|
|
kubectl auth can-i patch services -n im-server-system >/dev/null 2>&1; then
|
|
kubectl patch service/im-server -n im-server-system --type=merge -p \
|
|
'{"spec":{"sessionAffinity":"None"}}'
|
|
else
|
|
echo "::warning::ci-deployer cannot get/patch Service; skipped sessionAffinity update"
|
|
fi
|
|
if kubectl auth can-i get ingresses.networking.k8s.io -n im-server-system >/dev/null 2>&1 && \
|
|
kubectl auth can-i patch ingresses.networking.k8s.io -n im-server-system >/dev/null 2>&1 && \
|
|
kubectl get ingress/im-server -n im-server-system >/dev/null 2>&1; then
|
|
kubectl annotate ingress/im-server -n im-server-system --overwrite \
|
|
nginx.ingress.kubernetes.io/load-balance=least_conn
|
|
else
|
|
echo "::warning::ci-deployer cannot manage Ingress/im-server or it does not exist; skipped least_conn update"
|
|
fi
|
|
kubectl rollout restart statefulset/im-server -n im-server-system
|
|
kubectl rollout status statefulset/im-server -n im-server-system --timeout=300s
|
|
|
|
resources="$(kubectl get statefulset/im-server -n im-server-system -o \
|
|
jsonpath='{.spec.template.spec.containers[?(@.name=="im-server")].resources}')"
|
|
liveness="$(kubectl get statefulset/im-server -n im-server-system -o \
|
|
jsonpath='{.spec.template.spec.containers[?(@.name=="im-server")].livenessProbe.httpGet.path}')"
|
|
echo "effective resources=${resources} liveness=${liveness}"
|
|
if [ "${liveness}" != "/livez" ] || ! echo "${resources}" | grep -q '"cpu":"2"'; then
|
|
echo "::warning::StatefulSet resources/probes were reconciled away; update the ArgoCD source kustomization"
|
|
fi
|