I want to know how to deploy a Django production server on IBM Cloud.
Right now I have a Cloud Foundry Python app running without problems. But I'm using python manage.py runserver to start the app on the cloud.
There is a way to run the app without using the django server? Like, how we do running that kind of apps using Apache o Nginx web servers.
UPDATE:
I tried using the Procfile and gunicorn, but it gives me an error when it starts gunicorn.
This is my Procfile.
web: gunicorn my_app.wsgi --workers 2
And the error
ERR Starting gunicorn 18.0
I am using python 3.6 and django 1.11
Cloud Foundry provides out-of-the-box production quality hosting. You don’t need to configure nginx or apache. For more information on how cloud foundry works under the hood, see here
You would however normally configure the method for starting your application. The python buildback documentation describes a few options, for example:
Specify a Start Command
The Python buildpack does not generate a
default start command for your applications.
To stage with the Python buildpack and start an application, do one of
the following:
Required for Cloud Foundry v245 only: Supply a Procfile.
For more
information about Procfiles, see the Configuring a Production Server
topic. The following example Procfile specifies gunicorn as the start
command for a web app running on Gunicorn:
web: gunicorn SERVER-NAME:APP-NAME
Specify a start command with -c.
The following
example specifies waitress-serve as the start command for a web app
running on Waitress:
$ cf push python-app -c "waitress-serve --port=$PORT DJANGO-WEB-APP.wsgi:MY-APP"
Specify a start command in the application manifest by setting the command attribute.
For more
information, see the Deploying with Application Manifests topic.
Related
should i use gunicorn with a python flaks application if i will put in a docker and then use it in a cloud environment.
i have seen a lot of tutorials on how to do a flask application and deploy to a cloud service as a docker Image,
make the flask application
make the last line in docker with:
CMD ["python", "my_app.py"]
push the image and let the cloud service like AWS or azure use their load balancer with the amount of cpu and memeory you want to set as rule before spining another instance.
but i got into this tutorial and is using gunicorn
https://levelup.gitconnected.com/usage-of-gunicorn-for-deploying-python-web-applications-1e296618e1ab
where all the steps are the same, just the last line of the docker would be
CMD ["python" "-m", "gunicorn", "my_app:app"]
now uses the gnunicorn wsgi
and same way push that image to be use in the web application of the cloud.
i understand gunicorn can add more workers and thread as arguments in the cli; what would be the better approach or is one better than other?
Thanks guys.
Yes, you should always use a production server. As covered the the Flask docs, Deploy to Production: Run with a Production Server:
you should not use the built-in development server (flask run). The development server is provided by Werkzeug for convenience, but is not designed to be particularly efficient, stable, or secure.
Using gunicorn (or any other production WSGI server) is a necessary practice for deploying to production for speed, stability, and security. These concerns still persist, even if your app is deployed behind a load-balancer or proxy (like AWS load balancer). Both are necessary (you don't want to expose your WSGI server directly to the open internet, either, it should be behind a proper load balancer / proxy).
I have built a simple Flask app and I want do deploy it on Digital Ocean. I tried gunicorn but debugger and auto reloader no longer works. I was a php developer and I like to save changes and reload to see changes and errors.
You can use gunicorn do deploy your Flask app as described in this tutorial
Gunicorn comes with the ability to log and reload the application.
Apparently you cannot use gunicorn for debug mode as described here
Rails run on Cloud9 without any problem.
What I want to do is as follows:
run Rails on Heroku
run python program by rake task in Rails (especially python for access AWS s3 by boto to get some.)
current condition is as follows:
Case 1: deployed rails to heroku without any changing.
The deploy could be success and there is no problem to run rails app via Web browser. but rails server shows error log (by heroku log --tail )
an error shows "No module named boto"
Case 2: deployed rails to heroku file named requirements.txt on root.
Heroku didn't detect it as Ruby Rails app so that rails server didn't run.
rails server shows error log (by heroku log --tail ) as
heroku[router]: at=error code=H14 desc="No web processes running"
Case 3: deployed rails first as same as case 1. Then, add Python on Buildpacks on Heroku setting, then add requirements.txt, finally deploy again. then it's deployed. but rails server shows error log (by heroku log --tail ) as same as Case3.
if I could run command like pip, it will be easy, but it's impossible.
is there any idea to solve the above?
Instead of trying to install your custom boto on Heroku, just place your custom boto folder in your project's directory (at the same level as your project's apps). Thereafter, you can import the boto folder using the import statement. You can read about importing a module here
Although, the ideal way to do it is to use the Rails SDK for AWS instead of using the Python SDK for AWS and then trying to use it with Rails. All the functionality available with Boto is available with the SDK for Ruby as well.
Check
http://docs.aws.amazon.com/sdk-for-ruby/v2/developer-guide/
I am setting up a new project that is going to use python to build a RESTful back end. I looked at GAE, but choose Falcon Framework, because the application needs to eventually be installed on local servers. GAE has a great development feature, it allows for iterative development by watching the source, and reloading.
You can leave the web server running while you develop your
application. The web server knows to watch for changes in your source
files and reload them if necessary.
How can I set up Falcon to do the same thing?
This may not be the best answer, but I found that there is no simple method that does not require more software installed the way GAE does it, but after you install gunicorn, your can use the --reload switch and the server will auto-reload the source.
$ gunicorn -b 127.0.0.1:8000 -b [::1]:8000 --reload myapp:app
Docs: http://docs.gunicorn.org/en/19.0/settings.html#reload
Auto-reloading is not a feature of the framework (Falcon), but rather of the server. If you do want auto-reloading, the simplest way to do it is run your Falcon code on a gunicorn server, using the --reload switch. For example:
$ gunicorn --reload app:app
Assuming your API is inside app.py and named app.
I'm trying to deploy a python-based scientific application on IBM's bluemix platform. However, while I can launch the cgi services to host the web pages, the python application behind it doesn't currently run. The application currently runs on an apache server on rackspace, but I'm try trying launch a newer version for testing. I tried Heroku, with the same problem that the web pages will be served, but not the python application. But the heroku gist seems to be that Heroku can't serve cgi applications. And there was a suggestion that the Cloud Foundry platform would be able to do so. The application runs fine locally, so I'm trying to find the right tweak to deploy to Bluemix (or Heroku).
We have the requirements file, and the initial thought is that it's the procfile that needs tweaking. Currently it looks like:
web: python -m CGIHTTPServer $PORT
I've tried launching the application via the worker tag.
worker: python weblogo.py
worker: python setup.py
even trying to launch the internal files:
worker: python /weblogolib/_cgi.py
worker: python /weblogolib/__init__.py
Yet none of these methods worked on getting the application behind the web pages to work. Is there another method that we're unaware of?
The application is designed to be served locally with the command.
python ./weblogo --serve
Does this matter when deploying to a cloud platform?
Rewriting the application to Flask or Django isn't really an option now. Any guidance toward the getting the application launched would be much appreciated! Thank you in advance!