GitHub Actions commited on
Commit
ebda3d2
Β·
1 Parent(s): 830be50

πŸš€ Auto-deploy from GitHub

Browse files
Files changed (4) hide show
  1. Dockerfile +5 -2
  2. start.sh +24 -0
  3. test_app_startup.py +0 -0
  4. verify_deployment.py +161 -0
Dockerfile CHANGED
@@ -14,5 +14,8 @@ RUN pip install --no-cache-dir --upgrade -r requirements.txt
14
  # Copy project files
15
  COPY --chown=user . .
16
 
17
- # Start FastAPI with uvicorn
18
- CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
 
 
 
 
14
  # Copy project files
15
  COPY --chown=user . .
16
 
17
+ # Make startup script executable
18
+ RUN chmod +x start.sh
19
+
20
+ # Start FastAPI with debug startup script
21
+ CMD ["./start.sh"]
start.sh ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # Startup script for debugging HF Space deployment
3
+
4
+ echo "πŸ” DEBUG: Starting Museum Sexoskop App"
5
+ echo "πŸ“ Current directory: $(pwd)"
6
+ echo "πŸ“ Directory contents:"
7
+ ls -la
8
+
9
+ echo "🐍 Python version: $(python --version)"
10
+ echo "πŸ“¦ Installed packages:"
11
+ pip list | grep -E "(fastapi|uvicorn|pydantic|pillow|qrcode|transformers|torch)"
12
+
13
+ echo "πŸ“ App directory structure:"
14
+ find /app -type d -name "app" -o -name "static" -o -name "templates" | head -20
15
+
16
+ echo "πŸ”§ Testing configuration..."
17
+ if [ -f "/app/test_config.py" ]; then
18
+ python test_config.py
19
+ else
20
+ echo "❌ test_config.py not found"
21
+ fi
22
+
23
+ echo "πŸš€ Starting FastAPI server..."
24
+ exec uvicorn app.main:app --host 0.0.0.0 --port 7860 --log-level debug
test_app_startup.py ADDED
File without changes
verify_deployment.py ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Post-deployment verification script for Hugging Face Space.
4
+ Run this after deployment to verify all endpoints are working correctly.
5
+ """
6
+
7
+ import requests
8
+ import json
9
+ import time
10
+ import argparse
11
+ from typing import Dict, Any
12
+
13
+ def test_endpoint(url: str, method: str = 'GET', data: Dict[Any, Any] = None, timeout: int = 30) -> Dict[str, Any]:
14
+ """Test a single endpoint and return results."""
15
+ try:
16
+ if method.upper() == 'GET':
17
+ response = requests.get(url, timeout=timeout)
18
+ elif method.upper() == 'POST':
19
+ response = requests.post(url, json=data, timeout=timeout)
20
+ else:
21
+ return {"success": False, "error": f"Unsupported method: {method}"}
22
+
23
+ return {
24
+ "success": True,
25
+ "status_code": response.status_code,
26
+ "response_time": response.elapsed.total_seconds(),
27
+ "response_data": response.json() if response.headers.get('content-type', '').startswith('application/json') else response.text[:200]
28
+ }
29
+ except requests.exceptions.Timeout:
30
+ return {"success": False, "error": "Request timed out"}
31
+ except requests.exceptions.ConnectionError:
32
+ return {"success": False, "error": "Connection error"}
33
+ except Exception as e:
34
+ return {"success": False, "error": str(e)}
35
+
36
+ def verify_deployment(base_url: str):
37
+ """Run comprehensive deployment verification."""
38
+ print(f"πŸš€ Starting deployment verification for: {base_url}")
39
+ print("=" * 60)
40
+
41
+ tests = [
42
+ {
43
+ "name": "Root Endpoint",
44
+ "url": f"{base_url}/",
45
+ "method": "GET",
46
+ "expected_status": 200
47
+ },
48
+ {
49
+ "name": "Health Check",
50
+ "url": f"{base_url}/api/v1/health",
51
+ "method": "GET",
52
+ "expected_status": 200
53
+ },
54
+ {
55
+ "name": "Static Files Mount (Should return 404, not 500)",
56
+ "url": f"{base_url}/static/test.txt",
57
+ "method": "GET",
58
+ "expected_status": 404
59
+ },
60
+ {
61
+ "name": "Generate Horoscope",
62
+ "url": f"{base_url}/api/v1/generate-horoscope",
63
+ "method": "POST",
64
+ "data": {
65
+ "terms": ["Test", "Deployment", "Success", "Working", "Happy"],
66
+ "date_of_birth": "1990-01-01"
67
+ },
68
+ "expected_status": 200
69
+ }
70
+ ]
71
+
72
+ results = []
73
+
74
+ for test in tests:
75
+ print(f"\nπŸ” Testing: {test['name']}")
76
+ print(f" URL: {test['url']}")
77
+
78
+ result = test_endpoint(
79
+ url=test['url'],
80
+ method=test['method'],
81
+ data=test.get('data'),
82
+ timeout=30
83
+ )
84
+
85
+ if result['success']:
86
+ status_code = result['status_code']
87
+ expected = test['expected_status']
88
+
89
+ if status_code == expected:
90
+ print(f" βœ… PASS - Status: {status_code}, Time: {result['response_time']:.2f}s")
91
+ if 'response_data' in result:
92
+ print(f" πŸ“ Response: {result['response_data']}")
93
+ else:
94
+ print(f" ❌ FAIL - Expected: {expected}, Got: {status_code}")
95
+ print(f" πŸ“ Response: {result['response_data']}")
96
+ else:
97
+ print(f" ❌ ERROR - {result['error']}")
98
+
99
+ results.append({
100
+ "test": test['name'],
101
+ "result": result,
102
+ "expected_status": test['expected_status']
103
+ })
104
+
105
+ # Small delay between tests
106
+ time.sleep(1)
107
+
108
+ # Summary
109
+ print("\n" + "=" * 60)
110
+ print("πŸ“Š DEPLOYMENT VERIFICATION SUMMARY")
111
+ print("=" * 60)
112
+
113
+ passed = 0
114
+ failed = 0
115
+
116
+ for result in results:
117
+ test_name = result['test']
118
+ test_result = result['result']
119
+ expected = result['expected_status']
120
+
121
+ if test_result['success'] and test_result['status_code'] == expected:
122
+ print(f"βœ… {test_name}")
123
+ passed += 1
124
+ else:
125
+ print(f"❌ {test_name}")
126
+ failed += 1
127
+
128
+ print(f"\nπŸ“ˆ Results: {passed} passed, {failed} failed")
129
+
130
+ if failed == 0:
131
+ print("πŸŽ‰ All tests passed! Deployment is successful.")
132
+ return True
133
+ else:
134
+ print("πŸ’₯ Some tests failed. Check the errors above.")
135
+ return False
136
+
137
+ def main():
138
+ parser = argparse.ArgumentParser(description='Verify Hugging Face Space deployment')
139
+ parser.add_argument(
140
+ '--url',
141
+ default='https://huggingface.co/spaces/ch404/cardserver',
142
+ help='Base URL of the deployed application'
143
+ )
144
+ parser.add_argument(
145
+ '--wait',
146
+ type=int,
147
+ default=0,
148
+ help='Wait N seconds before starting tests (useful for fresh deployments)'
149
+ )
150
+
151
+ args = parser.parse_args()
152
+
153
+ if args.wait > 0:
154
+ print(f"⏰ Waiting {args.wait} seconds for deployment to fully start...")
155
+ time.sleep(args.wait)
156
+
157
+ success = verify_deployment(args.url)
158
+ exit(0 if success else 1)
159
+
160
+ if __name__ == "__main__":
161
+ main()