itfx/.github/workflows/master.yml
2026-09-03 11:16:09 +08:00

79 lines
2.7 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: .github/workflows/deploy.yml
#
# Secrets: SSH_K3S_HOST / SSH_K3S_USERNAME / SSH_K3S_PASSWORD
# 集群:
# GIT_TOKEN=... TCR_USERNAME=... TCR_PASSWORD=... ./scripts/16-setup-kaniko.sh
# ./scripts/17-test-github-access.sh # 选 GIT_FETCH_MODE / KANIKO_NODE_ROLE
#
# 构建全程在集群 Pod 内完成git + kanikoActions 只 SSH 触发并跟日志
#
name: Build and Deploy
on:
push:
branches: [master]
workflow_dispatch:
env:
GIT_URL: https://github.com/xiaoliutral/itfx.git
DOCKERFILE: src/InterfaceForward.Api/Dockerfile
IMAGE_NAME: interfaceforward_api
DEPLOY_NAME: interfaceforward-api
CONTAINER_NAME: interfaceforward-api
TCR_REGISTRY: ccr.ccs.tencentyun.com
TCR_NAMESPACE: ideship
K3S_DIR: /data/k3s
KUBECONFIG: /etc/rancher/k3s/k3s.yaml
NAMESPACE: prod
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Show image
id: info
run: |
TAG="${{ github.sha }}"
IMG="${{ env.TCR_REGISTRY }}/${{ env.TCR_NAMESPACE }}/${{ env.IMAGE_NAME }}:${TAG}"
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
echo "image=${IMG}" >> "$GITHUB_OUTPUT"
echo "Will build: ${IMG}"
- name: Build image (Kaniko logs)
uses: appleboy/ssh-action@v1.2.0
with:
host: ${{ secrets.SSH_K3S_HOST }}
username: ${{ secrets.SSH_K3S_USERNAME }}
password: ${{ secrets.SSH_K3S_PASSWORD }}
command_timeout: 50m
request_pty: true
script_stop: true
script: |
set -euxo pipefail
export KUBECONFIG=${{ env.KUBECONFIG }}
cd ${{ env.K3S_DIR }}
chmod +x scripts/ci-kaniko-build.sh
./scripts/ci-kaniko-build.sh \
"${{ env.GIT_URL }}" \
"${{ env.DOCKERFILE }}" \
"${{ env.IMAGE_NAME }}" \
"${{ steps.info.outputs.tag }}" \
"${{ steps.info.outputs.tag }}"
- name: Deploy
uses: appleboy/ssh-action@v1.2.0
with:
host: ${{ secrets.SSH_K3S_HOST }}
username: ${{ secrets.SSH_K3S_USERNAME }}
password: ${{ secrets.SSH_K3S_PASSWORD }}
command_timeout: 5m
script_stop: true
script: |
set -euxo pipefail
export KUBECONFIG=${{ env.KUBECONFIG }}
IMG="${{ steps.info.outputs.image }}"
kubectl -n ${{ env.NAMESPACE }} set image deploy/${{ env.DEPLOY_NAME }} \
${{ env.CONTAINER_NAME }}=${IMG}
kubectl -n ${{ env.NAMESPACE }} rollout status deploy/${{ env.DEPLOY_NAME }} --timeout=180s
kubectl -n ${{ env.NAMESPACE }} get pods -l app=${{ env.DEPLOY_NAME }} -o wide