-
Notifications
You must be signed in to change notification settings - Fork 26
82 lines (72 loc) · 2.99 KB
/
Copy pathdocker-check.yaml
File metadata and controls
82 lines (72 loc) · 2.99 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
name: Docker Check
permissions:
contents: read
issues: write
pull-requests: write
on:
issue_comment:
types:
- created
jobs:
docker-check:
name: Docker Check
runs-on: ubuntu-latest
if: github.event.issue.pull_request && contains(github.event.comment.body, '/cmd docker --check')
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.issue.pull_request.head.sha }}
repository: ${{ github.event.repository.full_name }}
- name: Post Initial Status
if: github.event_name == 'issue_comment'
uses: peter-evans/create-or-update-comment@v3
with:
issue-number: ${{ github.event.issue.number }}
body: |
## 🐳 Docker Check Status
> CI triggered by command `/cmd docker --check`.
**Status:** ⏳ **Building**... Preparing environment and running Docker health checks.
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Set up Docker Compose
uses: docker/setup-compose-action@v1
- name: Run docker compose
working-directory: ./template/nestJs
run: docker compose -f docker-compose-ci.yml up -d
- name: Wait Service
working-directory: ./template/nestJs
run: |
timeout 60 bash -c '
until [[ "$(docker compose -f docker-compose-ci.yml ps --services --filter "status=running" | wc -l)" -ge 1 ]]; do
sleep 2
done
'
- name: Send HealthCheck Request
run: curl -k --retry 20 --retry-delay 5 --retry-all-errors -f http://localhost:3000/healthCheck
- name: Update Status on Failure
if: failure() && github.event_name == 'issue_comment'
uses: peter-evans/create-or-update-comment@v3
with:
issue-number: ${{ github.event.issue.number }}
body: |
## ❌ Docker Check Status FAILED
> CI triggered by command `/cmd docker --check`.
**Status:** **FAILURE!** The service failed to start or did not pass the health check.
[查看完整的 CI 运行日志](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
- name: Check service logs
if: failure()
working-directory: ./template/nestJs
run: docker compose -f docker-compose-ci.yml logs back
- name: Update Status on Success
if: success() && github.event_name == 'issue_comment'
uses: peter-evans/create-or-update-comment@v3
with:
issue-number: ${{ github.event.issue.number }}
body: |
## ✅ Docker Check Status
> CI triggered by command `/cmd docker --check`.
**Status:** **SUCCESS!** Service is built, running, and responded to health check on `http://localhost:3000/healthCheck`.
- name: Shutdown Service
working-directory: ./template/nestJs
run: docker compose -f docker-compose-ci.yml down