Repository navigation
102 lines (88 loc) · 3.74 KB
/
Copy pathdeploy.yml
File metadata and controls
102 lines (88 loc) · 3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
name: python-learning Deploy
# 部署通道:阿里云 Cloud Assistant(aliyun ecs RunCommand),不用 SSH。
# 原因同 java-study:GitHub Actions runner 属境外出口,直连 47.93.15.207:22 会被
# 阿里云上游静默丢包(安全组规则在该层之下,加了也无效)。Cloud Assistant 走 HTTPS API。
on:
push:
branches: [main]
paths-ignore:
- '**/*.md'
- 'docs/**'
workflow_dispatch:
concurrency:
group: python-learning-deploy
cancel-in-progress: false
jobs:
deploy:
name: 部署到 ECS
runs-on: ubuntu-latest
environment: production
steps:
- uses: actions/checkout@v4
- name: 记录版本
id: before
run: |
echo "commit=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"
echo "message=$(git log -1 --pretty='%s')" >> "$GITHUB_OUTPUT"
- name: 通过 Cloud Assistant 下发部署脚本
env:
ALICLOUD_ACCESS_KEY_ID: ${{ secrets.ALIYUN_AK }}
ALICLOUD_ACCESS_KEY_SECRET: ${{ secrets.ALIYUN_SK }}
REGION: cn-beijing
INSTANCE_ID: i-2zecv4kgasiw24p97v0t
run: |
set -eo pipefail
curl -fsSL -o aliyun-cli.tgz https://aliyuncli.alicdn.com/aliyun-cli-linux-latest-amd64.tgz
tar -xzf aliyun-cli.tgz
install -m 0755 aliyun /usr/local/bin/aliyun
aliyun configure set --mode AK --profile ecs-deploy \
--region "$REGION" \
--access-key-id "$ALICLOUD_ACCESS_KEY_ID" \
--access-key-secret "$ALICLOUD_ACCESS_KEY_SECRET" >/dev/null
IID=$(aliyun ecs RunCommand --profile ecs-deploy --region "$REGION" \
--Type RunShellScript --Timeout 1800 \
--InstanceId.1 "$INSTANCE_ID" \
--ContentEncoding Base64 \
--CommandContent "$(base64 -w0 < deploy/deploy-python.sh)" \
| python3 -c "import sys,json; print(json.load(sys.stdin)['InvokeId'])")
echo "InvokeId=$IID"
echo "::add-mask::$IID"
while :; do
STATUS=$(aliyun ecs DescribeInvocationResults --profile ecs-deploy \
--region "$REGION" --InvokeId "$IID" | python3 deploy/ca_result.py status)
echo " 状态: $STATUS"
case "$STATUS" in Running|Pending) sleep 15 ;; *) break ;; esac
done
# 用仓库内脚本解析,避免内联多行 Python 顶断 YAML 缩进
aliyun ecs DescribeInvocationResults --profile ecs-deploy \
--region "$REGION" --InvokeId "$IID" | python3 deploy/ca_result.py output \
| tee /tmp/ca-output.log
grep -q "PYTHON-LEARNING DEPLOY DONE" /tmp/ca-output.log || {
echo "::error::部署未完成"; exit 1; }
- name: 部署结果
if: always()
run: |
{
echo "### 部署完成"
echo ""
echo "- commit: \`${{ steps.before.outputs.commit }}\` — ${{ steps.before.outputs.message }}"
echo "- 站点: http://47.93.15.207:8084/"
echo ""
echo '```'
tail -30 /tmp/ca-output.log 2>/dev/null || echo '(无输出)'
echo '```'
} >> "$GITHUB_STEP_SUMMARY"
- name: 外网复验(无 token)
run: |
set -eo pipefail
sleep 5
echo -n "首页 : "
curl -sS --max-time 15 -o /dev/null -w '%{http_code}\n' http://47.93.15.207:8084/
echo -n "auth/me : "
curl -sS --max-time 15 http://47.93.15.207:8084/api/auth/me
echo ""
echo -n "summary : "
curl -sS --max-time 15 -o /dev/null -w '%{http_code}\n' http://47.93.15.207:8084/api/summary
echo -n "health : "
curl -sS --max-time 15 http://47.93.15.207:8084/api/health
echo ""