-
Notifications
You must be signed in to change notification settings - Fork 80
executable file
·218 lines (172 loc) · 7.95 KB
/
[Client]Push Docker image.yml
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
name: Client_Push Docker image
on:
release:
types: [ created ]
jobs:
test:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./YuYuWechatV2_Client
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install Docker Compose
run: |
sudo apt-get update
sudo apt-get install -y docker-compose
docker-compose --version
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: ls
run: ls
- name: pwd
run: pwd
- name: Build and run Docker containers
run: docker-compose -f "./GitHub Action Build Docker.yml" up -d --build
- name: Wait for the server to start
run: sleep 20
- name: Display Docker logs
run: docker-compose -f "./GitHub Action Build Docker.yml" logs
# Test endpoints without login
- name: Test main endpoint without login
run: |
response=$(curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:7500/home/)
if [ $response -ne 302 ]; then
echo "Main endpoint accessible without login, expected it to be protected."
exit 1
fi
- name: Test schedule_management endpoint without login
run: |
response=$(curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:7500/schedule_management/)
if [ $response -ne 302 ]; then
echo "schedule_management endpoint accessible without login, expected it to be protected."
exit 1
fi
- name: Test send_message_management endpoint without login
run: |
response=$(curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:7500/send_message_management/)
if [ $response -ne 302 ]; then
echo "send_message_management endpoint accessible without login, expected it to be protected."
exit 1
fi
- name: Test log_view endpoint without login
run: |
response=$(curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:7500/logs/)
if [ $response -ne 302 ]; then
echo "log_view endpoint accessible without login, expected it to be protected."
exit 1
fi
- name: Test error_detection_view endpoint without login
run: |
response=$(curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:7500/error_detection/)
if [ $response -ne 302 ]; then
echo "error_detection endpoint accessible without login, expected it to be protected."
exit 1
fi
# Create a superuser
- name: Create superuser
run: |
docker exec -e DJANGO_SUPERUSER_PASSWORD="12345" yuyuwechatv2_client python manage.py createsuperuser --no-input --username testuser --email [email protected]
# Login and store session cookies
- name: Login and store session cookies
run: |
curl -c cookies.txt -d "username=testuser&password=12345" -X POST http://127.0.0.1:7500/login/
# Test endpoints with login
- name: Test main endpoint with login
run: curl -b cookies.txt --fail http://127.0.0.1:7500/
- name: Test get_server_ip endpoint with login
run: curl -b cookies.txt --fail http://127.0.0.1:7500/get_server_ip/
- name: Test set_server_ip endpoint with login
run: |
curl -b cookies.txt --fail -X POST -H "Content-Type: application/json" -d '{"server_ip": "127.0.0.1"}' http://127.0.0.1:7500/set_server_ip/
- name: Test schedule_management endpoint with login
run: curl -b cookies.txt --fail http://127.0.0.1:7500/schedule_management/
- name: Test send_message_management endpoint with login
run: curl -b cookies.txt --fail http://127.0.0.1:7500/send_message_management/
- name: Test start_celery endpoint with login
run: curl -b cookies.txt --fail -X POST http://127.0.0.1:7500/start_celery/
- name: Wait for the celery to start
run: sleep 5
- name: Test check_celery_running endpoint with login
run: curl -b cookies.txt --fail http://127.0.0.1:7500/check_celery_running/
- name: Test stop_celery endpoint with login
run: curl -b cookies.txt --fail http://127.0.0.1:7500/stop_celery/
- name: Test check_wechat_status endpoint with login
run: curl -b cookies.txt --fail http://127.0.0.1:7500/check_wechat_status/
- name: Test log_view endpoint with login
run: curl -b cookies.txt --fail http://127.0.0.1:7500/logs/
- name: Test log_counts endpoint with login
run: curl -b cookies.txt --fail http://127.0.0.1:7500/log_counts/
- name: Test clear_logs endpoint with login
run: curl -b cookies.txt --fail -X POST http://127.0.0.1:7500/clear_logs/
- name: Test error_detection_view endpoint with login
run: curl -b cookies.txt --fail http://127.0.0.1:7500/error_detection/
- name: Test check_errors endpoint with login
run: curl -b cookies.txt --fail http://127.0.0.1:7500/check_errors/
# - name: Test handle_error_cron endpoint with login
# run: |
# curl -b cookies.txt --fail -X POST -H "Content-Type: application/json" -d '{"action": "ignore", "task_id": 1, "correct_time": "2023-08-01 12:00:00"}' http://127.0.0.1:7500/handle_error_cron/
- name: Test export_database endpoint with login
run: curl -b cookies.txt --fail -X POST http://127.0.0.1:7500/export_database/ -o db_backup.json
- name: Test import_database endpoint with login
run: |
curl -b cookies.txt --fail -F "db_file=@db_backup.json" http://127.0.0.1:7500/import_database/
- name: Stop and remove Docker container
run: docker-compose -f "./GitHub Action Build Docker.yml" down
- name: Change permissions for postgres_data directory
run: sudo chmod -R 777 postgres_data
- name: Build Docker image
if: success()
run: docker build -t yuyuwechatv2_client:latest .
- name: Save Docker image to tar file
if: success()
run: docker save yuyuwechatv2_client:latest -o yuyuwechatv2_client.tar
- name: Compress Docker image tar file
if: success()
run: gzip yuyuwechatv2_client.tar
- name: Modify permissions of the compressed file
if: success()
run: chmod 777 yuyuwechatv2_client.tar.gz
- name: Check generated files and permissions
if: success()
run: |
pwd
ls -lh
ls -lh yuyuwechatv2_client.tar.gz
- name: Upload release asset
if: success()
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: /home/runner/work/YuYuWechat/YuYuWechat/YuYuWechatV2_Client/yuyuwechatv2_client.tar.gz
asset_name: yuyuwechatv2_client.tar.gz
asset_content_type: application/gzip
- name: Upload release asset
if: success()
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: /home/runner/work/YuYuWechat/YuYuWechat/YuYuWechatV2_Client/docker-compose.yml
asset_name: docker-compose.yml
asset_content_type: application/yaml
- name: Log in to Docker Hub
if: success()
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push Docker image
if: success()
uses: docker/build-push-action@v4
with:
context: ./YuYuWechatV2_Client
push: true
tags: |
${{ secrets.DOCKER_USERNAME }}/yuyuwechatv2_client:latest
${{ secrets.DOCKER_USERNAME }}/yuyuwechatv2_client:${{ github.ref_name }}
platforms: linux/amd64,linux/arm64