Browse Source

[Python] uWSGI: fix build and unblock (#8115)

Oleg S 2 years ago
parent
commit
21d2c18ae8

+ 6 - 4
frameworks/Python/uwsgi/benchmark_config.json

@@ -3,13 +3,14 @@
   "tests": [{
   "tests": [{
     "default": {
     "default": {
       "json_url": "/json",
       "json_url": "/json",
+      "plaintext_url": "/plaintext",
       "port": 8080,
       "port": 8080,
       "approach": "Stripped",
       "approach": "Stripped",
       "classification": "Platform",
       "classification": "Platform",
       "database": "None",
       "database": "None",
       "framework": "None",
       "framework": "None",
       "language": "Python",
       "language": "Python",
-      "flavor": "Python2",
+      "flavor": "Python3",
       "orm": "Raw",
       "orm": "Raw",
       "platform": "None",
       "platform": "None",
       "webserver": "uWSGI",
       "webserver": "uWSGI",
@@ -18,17 +19,18 @@
       "display_name": "uwsgi",
       "display_name": "uwsgi",
       "notes": "",
       "notes": "",
       "versus": "",
       "versus": "",
-      "tags": ["broken"]
+      "tags": [ ]
     },
     },
     "nginx-uwsgi": {
     "nginx-uwsgi": {
       "json_url": "/json",
       "json_url": "/json",
+      "plaintext_url": "/plaintext",
       "port": 8080,
       "port": 8080,
       "approach": "Stripped",
       "approach": "Stripped",
       "classification": "Platform",
       "classification": "Platform",
       "database": "None",
       "database": "None",
       "framework": "None",
       "framework": "None",
       "language": "Python",
       "language": "Python",
-      "flavor": "Python2",
+      "flavor": "Python3",
       "orm": "Raw",
       "orm": "Raw",
       "platform": "None",
       "platform": "None",
       "webserver": "nginx-uWSGI",
       "webserver": "nginx-uWSGI",
@@ -37,7 +39,7 @@
       "display_name": "uwsgi",
       "display_name": "uwsgi",
       "notes": "",
       "notes": "",
       "versus": "",
       "versus": "",
-      "tags": ["broken"]
+      "tags": [ ]
     }
     }
   }]
   }]
 }
 }

+ 2 - 0
frameworks/Python/uwsgi/config.toml

@@ -3,6 +3,7 @@ name = "uwsgi"
 
 
 [main]
 [main]
 urls.json = "/json"
 urls.json = "/json"
+urls.plaintext = "/plaintext"
 approach = "Stripped"
 approach = "Stripped"
 classification = "Platform"
 classification = "Platform"
 database = "None"
 database = "None"
@@ -15,6 +16,7 @@ versus = ""
 
 
 [nginx-uwsgi]
 [nginx-uwsgi]
 urls.json = "/json"
 urls.json = "/json"
+urls.plaintext = "/plaintext"
 approach = "Stripped"
 approach = "Stripped"
 classification = "Platform"
 classification = "Platform"
 database = "None"
 database = "None"

+ 40 - 13
frameworks/Python/uwsgi/hello.py

@@ -1,17 +1,44 @@
-import ujson
+import os
+import sys
+import time
 from email.utils import formatdate
 from email.utils import formatdate
 
 
+try:
+    from ujson import dumps as jsonify
+except:
+    from json import dumps as jsonify
+
+g_time = 0
+g_asctime = ""
 
 
 def application(environ, start_response):
 def application(environ, start_response):
-    response = {
-      "message": "Hello, World!"
-    }
-    data = ujson.dumps(response)
-    response_headers = [
-        ('Server', 'uwsgi'),
-        ('Date', formatdate(timeval=None, localtime=False, usegmt=True)),
-        ('Content-Type', 'application/json'),
-        ('Content-Length', str(len(data)))
-    ]
-    start_response('200 OK', response_headers)
-    return [data]
+    global g_time
+    global g_asctime
+    
+    path = environ["PATH_INFO"]
+    headers = [ ('Server', 'uWSGI') ]
+
+    curr_time = int(time.time())
+    if curr_time != g_time:
+        g_time = curr_time
+        g_asctime = formatdate(timeval=None, localtime=False, usegmt=True)
+        
+    headers.append( ('Date', g_asctime ) )
+
+    if path == '/plaintext':
+        data = b'Hello, World!'
+        headers.append( ('Content-Type', 'text/plain') )
+        headers.append( ('Content-Length', str(len(data))) )
+        start_response('200 OK', headers)
+        return [ data ]
+    
+    if path == '/json':
+        data = jsonify( {"message": "Hello, World!"} ).encode('utf8')
+        headers.append( ('Content-Type', 'application/json') )
+        headers.append( ('Content-Length', str(len(data))) )
+        start_response('200 OK', headers)
+        return [ data ]
+
+    headers.append( ('Content-Length', '0') )
+    start_response('400 Bad Request', headers)
+    return [ b'' ]

+ 3 - 3
frameworks/Python/uwsgi/requirements.txt

@@ -1,3 +1,3 @@
-gevent==1.1.0
-uwsgi==2.0.17.1
-ujson==1.35
+gevent==22.10.2
+uwsgi==2.0.21
+ujson==5.4.0

+ 5 - 4
frameworks/Python/uwsgi/uwsgi-nginx-uwsgi.dockerfile

@@ -1,16 +1,17 @@
-FROM python:2.7.15-stretch
+FROM python:3.9-bullseye
 
 
 RUN curl -s http://nginx.org/keys/nginx_signing.key | apt-key add -
 RUN curl -s http://nginx.org/keys/nginx_signing.key | apt-key add -
-RUN echo "deb http://nginx.org/packages/debian/ stretch nginx" >> /etc/apt/sources.list
-RUN echo "deb-src http://nginx.org/packages/debian/ stretch nginx" >> /etc/apt/sources.list
+RUN echo "deb http://nginx.org/packages/debian/ bullseye nginx" >> /etc/apt/sources.list
+RUN echo "deb-src http://nginx.org/packages/debian/ bullseye nginx" >> /etc/apt/sources.list
 
 
 RUN apt-get update -yqq && apt-get install -yqq nginx
 RUN apt-get update -yqq && apt-get install -yqq nginx
+RUN apt-get install python3-dev -y
 
 
 ADD ./ /uw
 ADD ./ /uw
 
 
 WORKDIR /uw
 WORKDIR /uw
 
 
-RUN pip install -r /uw/requirements.txt
+RUN pip3 install -U pip; pip3 install -r /uw/requirements.txt
 
 
 RUN sed -i 's|include .*/conf/uwsgi_params;|include /etc/nginx/uwsgi_params;|g' /uw/nginx.conf
 RUN sed -i 's|include .*/conf/uwsgi_params;|include /etc/nginx/uwsgi_params;|g' /uw/nginx.conf
 
 

+ 5 - 4
frameworks/Python/uwsgi/uwsgi.dockerfile

@@ -1,10 +1,11 @@
-FROM python:2.7.15-stretch
+FROM python:3.9-bullseye
 
 
-ADD ./ /uw
+RUN apt-get update -yqq
+RUN apt-get install python3-dev -y
 
 
 WORKDIR /uw
 WORKDIR /uw
-
-RUN pip install -r /uw/requirements.txt
+COPY ./ /uw
+RUN pip3 install -U pip; pip3 install -r /uw/requirements.txt
 
 
 EXPOSE 8080
 EXPOSE 8080