itfx/.gitea/workflows/deploy.yml
2026-09-21 15:42:49 +08:00

78 lines
2.2 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 复制到 itfx 仓库 .gitea/workflows/deploy.yml
# push master/main → prod;push test → test
name: Build and Deploy
on:
push:
branches: [master, main, test]
workflow_dispatch:
inputs:
target:
description: Deploy target (仅手动;push 时由分支决定)
type: choice
options:
- prod
- test
default: prod
env:
CSPROJ: src/InterfaceForward.Api/InterfaceForward.Api.csproj
IMAGE_NAME: interfaceforward_api
DEPLOY_NAME: interfaceforward-api
CONTAINER_NAME: interfaceforward-api
TCR_REGISTRY: ccr.ccs.tencentyun.com
TCR_NAMESPACE: ideship
jobs:
deploy:
runs-on: k3s-host
steps:
- name: Build and deploy
run: |
set -euxo pipefail
REF="${{ gitea.ref_name }}"
if [[ "${{ gitea.event_name }}" == "workflow_dispatch" ]]; then
TARGET="${{ inputs.target }}"
TARGET="${TARGET:-prod}"
else
case "$REF" in
test) TARGET=test ;;
*) TARGET=prod ;;
esac
fi
SHA="${{ gitea.sha }}"
REPO="${{ gitea.repository }}"
test -n "$REPO" && [[ "$REPO" == */* ]]
case "$TARGET" in
test) TAG="test-${SHA}" ;;
*) TAG="${SHA}" ;;
esac
IMG="${{ env.TCR_REGISTRY }}/${{ env.TCR_NAMESPACE }}/${{ env.IMAGE_NAME }}:${TAG}"
echo "TARGET=$TARGET REF=$REF REPO=$REPO TAG=$TAG host=$(hostname)"
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
unset NAMESPACE
cd /data/k3s
./scripts/ci-publish-container.sh "$REPO" "${{ env.CSPROJ }}" \
"${{ env.IMAGE_NAME }}" "$TAG" "$SHA"
case "$TARGET" in
test)
export KUBECONFIG=/root/.kube/k3s-test.yaml
export NAMESPACE=test
export MANIFEST_ROOT=/data/k3s-test
;;
*)
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
export NAMESPACE=prod
export MANIFEST_ROOT=/data/k3s
;;
esac
test -f "$KUBECONFIG"
./scripts/ci-deploy-api.sh "${{ env.DEPLOY_NAME }}" \
"${{ env.CONTAINER_NAME }}" "$IMG"