Ali2206 commited on
Commit
c0559a6
Β·
1 Parent(s): b19e5b5

Add missing files: start_server.py, mongodb.env.example, and fix Dockerfile paths

Browse files
Files changed (3) hide show
  1. Dockerfile +4 -4
  2. mongodb.env.example +8 -0
  3. start_server.py +83 -0
Dockerfile CHANGED
@@ -3,18 +3,18 @@ FROM python:3.9-slim
3
  WORKDIR /app
4
 
5
  # Copy requirements first for better caching
6
- COPY server/requirements.txt .
7
  RUN pip install --no-cache-dir -r requirements.txt
8
 
9
  # Copy the rest of the application
10
- COPY server/ .
11
 
12
  # Expose the port that FastAPI will run on
13
  EXPOSE 8000
14
 
15
  # Set environment variables
16
  ENV PORT=8000
17
- ENV CORS_ORIGIN=https://ali2206-checklist.hf.space
18
 
19
  # Run the FastAPI application
20
- CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
 
3
  WORKDIR /app
4
 
5
  # Copy requirements first for better caching
6
+ COPY requirements.txt .
7
  RUN pip install --no-cache-dir -r requirements.txt
8
 
9
  # Copy the rest of the application
10
+ COPY . .
11
 
12
  # Expose the port that FastAPI will run on
13
  EXPOSE 8000
14
 
15
  # Set environment variables
16
  ENV PORT=8000
17
+ ENV CORS_ORIGIN=*
18
 
19
  # Run the FastAPI application
20
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]
mongodb.env.example ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ # MongoDB Configuration
2
+ MONGODB_URI=mongodb+srv://yakdhanali97:Syrou2206@cluster0.szf60ea.mongodb.net/audit_checklist?retryWrites=true&w=majority&appName=Cluster0
3
+
4
+ # Server Configuration
5
+ PORT=5000
6
+
7
+ # CORS Configuration
8
+ CORS_ORIGIN=http://localhost:3000
start_server.py ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ FastAPI Server Startup Script
4
+ =============================
5
+
6
+ This script provides an easy way to start the FastAPI server with proper
7
+ configuration and error handling.
8
+
9
+ Usage:
10
+ python start_server.py
11
+ python start_server.py --port 8000
12
+ python start_server.py --host 0.0.0.0 --port 5000
13
+ """
14
+
15
+ import argparse
16
+ import sys
17
+ import os
18
+ import uvicorn
19
+ from pathlib import Path
20
+
21
+ def main():
22
+ """Main function to start the FastAPI server"""
23
+
24
+ # Add the server directory to Python path
25
+ server_dir = Path(__file__).parent
26
+ sys.path.insert(0, str(server_dir))
27
+
28
+ # Parse command line arguments
29
+ parser = argparse.ArgumentParser(description='Start the Audit Checklist FastAPI server')
30
+ parser.add_argument('--host', default='0.0.0.0', help='Host to bind the server to (default: 0.0.0.0)')
31
+ parser.add_argument('--port', type=int, default=5000, help='Port to bind the server to (default: 5000)')
32
+ parser.add_argument('--reload', action='store_true', default=True, help='Enable auto-reload for development')
33
+ parser.add_argument('--log-level', default='info', choices=['debug', 'info', 'warning', 'error'], help='Log level')
34
+
35
+ args = parser.parse_args()
36
+
37
+ # Check if environment file exists
38
+ env_file = server_dir / 'mongodb.env'
39
+ if not env_file.exists():
40
+ print("❌ Error: mongodb.env file not found!")
41
+ print("Please create the mongodb.env file with your MongoDB connection string.")
42
+ print("Example:")
43
+ print("MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/database")
44
+ print("PORT=5000")
45
+ print("CORS_ORIGIN=http://localhost:3000")
46
+ sys.exit(1)
47
+
48
+ # Load environment variables
49
+ from dotenv import load_dotenv
50
+ load_dotenv(env_file)
51
+
52
+ # Check if MongoDB URI is set
53
+ if not os.getenv('MONGODB_URI'):
54
+ print("❌ Error: MONGODB_URI not found in mongodb.env file!")
55
+ sys.exit(1)
56
+
57
+ print("πŸš€ Starting Audit Checklist FastAPI Server...")
58
+ print(f"πŸ“ Host: {args.host}")
59
+ print(f"πŸ”Œ Port: {args.port}")
60
+ print(f"πŸ”„ Auto-reload: {'Enabled' if args.reload else 'Disabled'}")
61
+ print(f"πŸ“Š Log level: {args.log_level}")
62
+ print(f"πŸ“š API Documentation: http://{args.host}:{args.port}/docs")
63
+ print(f"πŸ” Health Check: http://{args.host}:{args.port}/health")
64
+ print("-" * 50)
65
+
66
+ try:
67
+ # Start the server
68
+ uvicorn.run(
69
+ "main:app",
70
+ host=args.host,
71
+ port=args.port,
72
+ reload=args.reload,
73
+ log_level=args.log_level,
74
+ access_log=True
75
+ )
76
+ except KeyboardInterrupt:
77
+ print("\nπŸ‘‹ Server stopped by user")
78
+ except Exception as e:
79
+ print(f"❌ Error starting server: {e}")
80
+ sys.exit(1)
81
+
82
+ if __name__ == "__main__":
83
+ main()