Merge pull request #30 from platform9/python-improvements

Python environment improvements
This commit is contained in:
Soam Vasani
2016-11-19 20:15:40 -08:00
committed by GitHub
4 changed files with 38 additions and 38 deletions
+12 -3
View File
@@ -1,3 +1,12 @@
FROM python:3-onbuild FROM ubuntu:16.04
CMD [ "python", "./server.py" ]
EXPOSE 8888 RUN apt-get update -y
RUN apt-get install -y python3 python3-pip python3-dev build-essential
COPY . /app
WORKDIR /app
RUN pip3 install -r requirements.txt
ENTRYPOINT ["python3"]
CMD ["server.py"]
+1
View File
@@ -0,0 +1 @@
Flask===0.11.1
+23 -33
View File
@@ -1,42 +1,32 @@
#!/usr/bin/env python #!/usr/bin/env python
import imp import imp
from http.server import BaseHTTPRequestHandler, HTTPServer
# from flask import Flask
# Load the file. from flask import request
# from flask import abort
app = Flask(__name__)
codepath = '/userfunc/user' codepath = '/userfunc/user'
userfunc = None userfunc = None
class testHTTPServer_RequestHandler(BaseHTTPRequestHandler): @app.route('/specialize', methods=['POST'])
def do_POST(self): def load():
global userfunc global userfunc
userfunc = (imp.load_source('user', codepath)).main userfunc = (imp.load_source('user', codepath)).main
self.send_response(200) return ""
self.end_headers()
self.wfile.write(bytes("ok\n", "utf8"))
return
# GET @app.route('/', methods=['GET', 'POST', 'PUT', 'HEAD', 'OPTIONS', 'DELETE'])
def do_GET(self): def f():
global userfunc if userfunc == None:
try: print("Generic container: no requests supported")
print("GET request") abort(500)
message = userfunc(None) return userfunc()
self.send_response(200)
self.end_headers()
self.wfile.write(bytes(message, "utf8"))
return
except:
self.send_response(500)
self.end_headers()
def run(): #
print('starting server...') # TODO: this starts the built-in server, which isn't the most
server_address = ('0.0.0.0', 8888) # efficient. We should use something better.
httpd = HTTPServer(server_address, testHTTPServer_RequestHandler) #
httpd.serve_forever() app.run(host='0.0.0.0', port='8888')
run()
+2 -2
View File
@@ -1,2 +1,2 @@
def main(context): def main():
return "Hello, world!" return "Hello, world!\n"