Files
lpt-infra/.gitea/workflows/deploy.yml
T

86 lines
2.5 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.
name: lpt-infra Manual Deploy
on:
workflow_dispatch:
inputs:
environment:
description: '部署环境(all/dev/prod'
required: true
type: choice
options:
- all
- dev
- prod
env:
REPO_URL: http://git.cat-shark.xyz/cat-shark/lpt-infra.git
KUBECTL_VERSION: v1.36.2
jobs:
deploy:
runs-on: ubuntu-latest
env:
KUBECONFIG: /tmp/kubeconfig
steps:
- name: Checkout code
run: |
set -euo pipefail
git clone "$REPO_URL" .
git checkout "${{ gitea.sha }}"
- name: Setup kubectl
run: |
set -euo pipefail
curl -sLO "https://dl.k8s.io/release/$KUBECTL_VERSION/bin/linux/amd64/kubectl"
chmod +x kubectl
mv kubectl /usr/local/bin/
echo "${{ secrets.KUBECONFIG_B64 }}" | base64 -d > /tmp/kubeconfig
chmod 600 /tmp/kubeconfig
if [ ! -s /tmp/kubeconfig ]; then
echo "ERROR: KUBECONFIG_B64 secret 为空,请先在 lpt-infra 仓库配置 Secret"
exit 1
fi
kubectl --kubeconfig=/tmp/kubeconfig config view --minify >/dev/null
- name: Apply manifests
run: |
set -euo pipefail
ENV="${{ inputs.environment }}"
case "$ENV" in
all)
echo "Applying dev/ ..."
kubectl --kubeconfig=/tmp/kubeconfig apply -f dev/
echo "Applying prod/ ..."
kubectl --kubeconfig=/tmp/kubeconfig apply -f prod/
;;
dev)
echo "Applying dev/ ..."
kubectl --kubeconfig=/tmp/kubeconfig apply -f dev/
;;
prod)
echo "Applying prod/ ..."
kubectl --kubeconfig=/tmp/kubeconfig apply -f prod/
;;
*)
echo "ERROR: unknown environment=$ENV"
exit 1
;;
esac
- name: Verify status
run: |
set -euo pipefail
ENV="${{ inputs.environment }}"
case "$ENV" in
all)
kubectl --kubeconfig=/tmp/kubeconfig get deploy,pods -n lpt-dev
kubectl --kubeconfig=/tmp/kubeconfig get deploy,pods -n lpt-prod
;;
dev)
kubectl --kubeconfig=/tmp/kubeconfig get deploy,pods -n lpt-dev
;;
prod)
kubectl --kubeconfig=/tmp/kubeconfig get deploy,pods -n lpt-prod
;;
esac