PythonMindset commited on
Commit
62d3ebf
·
1 Parent(s): 1983b47

Optimize production deployment: use Gunicorn instead of Flask dev server for better performance

Browse files
Files changed (3) hide show
  1. Dockerfile +3 -2
  2. app.py +6 -3
  3. requirements.txt +2 -1
Dockerfile CHANGED
@@ -1,4 +1,4 @@
1
- FROM python:3.11-slim
2
 
3
  WORKDIR /app
4
 
@@ -9,4 +9,5 @@ COPY . .
9
 
10
  EXPOSE 7860
11
 
12
- CMD ["python", "app.py"]
 
 
1
+ FROM python:3.11-slim
2
 
3
  WORKDIR /app
4
 
 
9
 
10
  EXPOSE 7860
11
 
12
+ # Utiliser Gunicorn au lieu de Flask dev server
13
+ CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--workers", "2", "--threads", "4", "--timeout", "120", "app:app"]
app.py CHANGED
@@ -1,10 +1,13 @@
1
- from flask import Flask, render_template, send_from_directory
2
  import os
3
 
4
- app = Flask(__name__,
5
  static_folder='static',
6
  template_folder='.')
7
 
 
 
 
8
  @app.route('/')
9
  def index():
10
  return send_from_directory('.', 'index.html')
@@ -15,4 +18,4 @@ def serve_static(path):
15
 
16
  if __name__ == '__main__':
17
  port = int(os.environ.get('PORT', 7860))
18
- app.run(host='0.0.0.0', port=port, debug=False)
 
1
+ from flask import Flask, send_from_directory
2
  import os
3
 
4
+ app = Flask(__name__,
5
  static_folder='static',
6
  template_folder='.')
7
 
8
+ # Configuration optimisée pour production
9
+ app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 31536000 # Cache 1 an pour fichiers statiques
10
+
11
  @app.route('/')
12
  def index():
13
  return send_from_directory('.', 'index.html')
 
18
 
19
  if __name__ == '__main__':
20
  port = int(os.environ.get('PORT', 7860))
21
+ app.run(host='0.0.0.0', port=port, debug=False)
requirements.txt CHANGED
@@ -1 +1,2 @@
1
- Flask==3.0.0
 
 
1
+ Flask==3.0.0
2
+ gunicorn==21.2.0