diff --git a/.ebextensions/python27.config b/.ebextensions/python27.config new file mode 100644 index 000000000..0d7b06efb --- /dev/null +++ b/.ebextensions/python27.config @@ -0,0 +1,38 @@ +# Yum install the packages we need for python2.7 +# on the EC2 box. python27-devel, make and httpd-devel +# are required for getting modwsgi setup with python27. +packages: + yum: + python27: [] + python27-devel: [] + make: [] + httpd-devel: [] + +commands: + # The modwsgi version currently installed on the system + # is built with support for python2.6 only. This + # command compiles and installs modwsgi with python2.7 support. + installmodwsgi27: + command: '[ -f mod_wsgi-3.4.tar.gz ] && echo "mod_wsgi-3.4 is already installed" || { wget http://modwsgi.googlecode.com/files/mod_wsgi-3.4.tar.gz; tar xzvf mod_wsgi-3.4.tar.gz; cd mod_wsgi-3.4; ./configure --with-python=python27; make; make install; } | iconv -f utf-8 -t us-ascii//TRANSLIT' + + # When our app is being deployed a virtualenv is setup + # automatically for us. This injects the --python=python2.7 + # argument into the virtualenv CLI. This tells virtualenv to + # use python2.7 instead of the default python2.6. + usepython27: + command: grep "python2.7" 03deploy.py || sed -i 's/--distribute/--python=python2.7 &/' 03deploy.py + cwd: /opt/elasticbeanstalk/hooks/appdeploy/pre + +container_commands: + # Now that our app is installed using python2.7 we + # need to fix some paths that the wsgi configuration + # has pointing to python2.6. Copy the default eb wsgi.conf, + # check it into git and replace the paths pointing + # to python2.6. Check this diff out for the changes required: + # https://github.com/leetreveil/elasticbeanstalk-python27/commit/3b3c955cfe686b9df77e0dddaf299ce6e1a20f32 + 01replacewsgiconf: + command: scp /opt/python/ondeck/app/wsgi.conf /opt/python/ondeck/wsgi.conf + +option_settings: + "aws:elasticbeanstalk:container:python:staticfiles": + "/static": "static/" \ No newline at end of file diff --git a/.gitignore b/.gitignore index 854a5a5fb..beed9c400 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.pyc venv +.elasticbeanstalk/ diff --git a/wsgi.py b/application.py similarity index 70% rename from wsgi.py rename to application.py index b598e2fc6..c4e4f602e 100644 --- a/wsgi.py +++ b/application.py @@ -1,6 +1,6 @@ import logging -from app import app +from app import app as application import endpoints.index import endpoints.api @@ -8,9 +8,12 @@ import endpoints.web import endpoints.tags import endpoints.registry +# Remove this for prod config +application.debug = True + if __name__ == '__main__': FORMAT = '%(asctime)-15s - %(levelname)s - %(pathname)s - ' + \ '%(funcName)s - %(message)s' logging.basicConfig(format=FORMAT, level=logging.DEBUG) - app.run(port=5001, debug=True) + application.run(port=5001, debug=True) diff --git a/endpoints/registry.py b/endpoints/registry.py index 2cad43ee8..42aebf19e 100644 --- a/endpoints/registry.py +++ b/endpoints/registry.py @@ -1,8 +1,8 @@ import logging +import json from flask import make_response, request, session, Response, abort -import simplejson as json from functools import wraps from datetime import datetime from time import time diff --git a/endpoints/tags.py b/endpoints/tags.py index 46d64a985..b9b331c7f 100644 --- a/endpoints/tags.py +++ b/endpoints/tags.py @@ -1,8 +1,8 @@ import logging +import json from flask import abort, request, jsonify, make_response -import simplejson as json import storage diff --git a/requirements-nover.txt b/requirements-nover.txt new file mode 100644 index 000000000..7cdb7d4b6 --- /dev/null +++ b/requirements-nover.txt @@ -0,0 +1,8 @@ +peewee +flask +py-bcrypt +Flask-Principal +Flask-Login +Flask-Mail +python-dateutil +boto \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 560d03df5..2c28e828a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,17 @@ -peewee -flask -py-bcrypt -Flask-Principal -Flask-Login -Flask-Mail \ No newline at end of file +Flask==0.10.1 +Flask-Login==0.2.7 +Flask-Mail==0.9.0 +Flask-Principal==0.4.0 +Jinja2==2.7.1 +MarkupSafe==0.18 +Werkzeug==0.9.4 +argparse==1.2.1 +blinker==1.3 +boto==2.13.3 +distribute==0.6.34 +itsdangerous==0.23 +peewee==2.1.4 +py-bcrypt==0.4 +python-dateutil==2.1 +six==1.4.1 +wsgiref==0.1.2 diff --git a/wsgi.conf b/wsgi.conf new file mode 100644 index 000000000..956ff0040 --- /dev/null +++ b/wsgi.conf @@ -0,0 +1,28 @@ + +LoadModule wsgi_module modules/mod_wsgi.so +WSGIPythonHome /opt/python/run/venv +WSGISocketPrefix run/wsgi +WSGIRestrictEmbedded On + + + +Alias /static /opt/python/current/app/static/ + +Order allow,deny +Allow from all + + + +WSGIScriptAlias / /opt/python/current/app/application.py + + + +Order allow,deny +Allow from all + + +WSGIDaemonProcess wsgi processes=1 threads=15 display-name=%{GROUP} \ + python-path=/opt/python/current/app:/opt/python/run/venv/lib/python2.7/site-packages user=wsgi group=wsgi \ + home=/opt/python/current/app +WSGIProcessGroup wsgi +