config/.gitea/workflows/sync-consul.yml
xiaolipro e19ebab1e6
Some checks failed
Sync Consul Config / sync (push) Failing after 1s
test
2026-09-21 16:18:53 +08:00

60 lines
2.0 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.

# 复制到配置仓 .gitea/workflows/sync-consul.yml
# push master → prod Consul;push test → test Consul
name: Sync Consul Config
on:
push:
branches: [master, test]
jobs:
sync:
runs-on: k3s-host
steps:
- name: Checkout and sync
run: |
set -euxo pipefail
REF="${{ gitea.ref_name }}"
case "$REF" in
test) TARGET=test ;;
master) TARGET=prod ;;
*) echo "unsupported branch: $REF"; exit 1 ;;
esac
case "$TARGET" in
test)
export KUBECONFIG=/root/.kube/k3s-test.yaml
export NAMESPACE=test
;;
*)
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
export NAMESPACE=prod
;;
esac
export RESTART_APIS=1
REPO="${{ gitea.repository }}"
SHA="${{ gitea.sha }}"
test -n "$REPO" && [[ "$REPO" == */* ]]
test -n "$SHA"
echo "TARGET=$TARGET REF=$REF NAMESPACE=$NAMESPACE"
GITEA_HTTP="https://git.ideship.com"
WORK="/data/ci-build/config-${TARGET}"
GITEA_USER="$(kubectl --kubeconfig=/etc/rancher/k3s/k3s.yaml -n prod get secret kaniko-git -o jsonpath='{.data.GITEA_USER}' | base64 -d)"
GIT_TOKEN="$(kubectl --kubeconfig=/etc/rancher/k3s/k3s.yaml -n prod get secret kaniko-git -o jsonpath='{.data.GIT_TOKEN}' | base64 -d)"
GITEA_USER="${GITEA_USER:-gitea}"
rm -rf "$WORK"
mkdir -p "$WORK"
cd "$WORK"
git init -q
git remote add origin "${GITEA_HTTP}/${REPO}.git"
AUTH_B64="$(printf '%s:%s' "$GITEA_USER" "$GIT_TOKEN" | base64 | tr -d '\n\r ')"
git -c http.extraHeader="Authorization: Basic ${AUTH_B64}" \
fetch --depth 1 --quiet --no-tags origin "$SHA"
git checkout --force --quiet FETCH_HEAD
chmod +x scripts/sync-to-consul.sh
./scripts/sync-to-consul.sh