89 lines
2.4 KiB
YAML
89 lines
2.4 KiB
YAML
name: Deploy to Test Environment
|
|
|
|
on:
|
|
push:
|
|
tags:
|
|
- 'v*-test'
|
|
workflow_dispatch:
|
|
|
|
concurrency:
|
|
group: deploy-test
|
|
cancel-in-progress: false
|
|
|
|
env:
|
|
ENVIRONMENT: test
|
|
REGISTRY: registry.cn-hangzhou.aliyuncs.com
|
|
IMAGE_NAME: ${{ github.repository }}
|
|
|
|
jobs:
|
|
deploy:
|
|
name: Deploy to Test
|
|
runs-on: ubuntu-latest
|
|
environment:
|
|
name: test
|
|
url: https://test.fischerx.com
|
|
timeout-minutes: 45
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup kubectl
|
|
uses: azure/setup-kubectl@v4
|
|
with:
|
|
version: 'v1.28.0'
|
|
|
|
- name: Configure Kubernetes credentials
|
|
run: |
|
|
mkdir -p ~/.kube
|
|
echo "${{ secrets.KUBE_CONFIG_TEST }}" | base64 -d > ~/.kube/config
|
|
chmod 600 ~/.kube/config
|
|
|
|
- name: Verify Kubernetes connection
|
|
run: kubectl cluster-info
|
|
|
|
- name: Log in to Aliyun Container Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ secrets.ALIYUN_REGISTRY_USERNAME }}
|
|
password: ${{ secrets.ALIYUN_REGISTRY_PASSWORD }}
|
|
|
|
- name: Extract tag version
|
|
id: extract_version
|
|
run: |
|
|
TAG=${GITHUB_REF#refs/tags/}
|
|
VERSION=${TAG%%-test}
|
|
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
|
|
|
|
- name: Deploy to Kubernetes
|
|
run: |
|
|
echo "Deploying version ${{ steps.extract_version.outputs.VERSION }} to test environment..."
|
|
# 这里添加具体的部署脚本
|
|
# 示例:
|
|
# kubectl set image deployment/fischerx-api fischerx-api=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.extract_version.outputs.VERSION }}
|
|
# kubectl rollout status deployment/fischerx-api
|
|
|
|
- name: Run database migrations
|
|
run: |
|
|
echo "Running database migrations..."
|
|
# 这里添加数据库迁移命令
|
|
|
|
- name: Run integration tests
|
|
run: |
|
|
echo "Running integration tests..."
|
|
# 这里添加集成测试命令
|
|
|
|
- name: Health check
|
|
run: |
|
|
echo "Running health checks..."
|
|
# 这里添加健康检查脚本
|
|
|
|
- name: Send deployment notification
|
|
if: always()
|
|
uses: 8398a7/action-slack@v3
|
|
with:
|
|
status: ${{ job.status }}
|
|
text: 'Deployment to test environment ${{ job.status }}'
|
|
webhook_url: ${{ secrets.SLACK_WEBHOOK_URL }}
|