Hacker News new | ask | show | jobs
by thanksgiving 3209 days ago
I have a small flask application which basically is a rest get post API server. I'm struggling to make deployment easy. With PHP, i just push to the application server and rsync that folder into var www html for Apache httpd but what would I do for flask python 3?
7 comments

Use a webserver that proxies requests to a wsgi server. We tend to put Caddy in front of Gunicorn which works really well. Also, look into running Gunicorn under supervisord.
Oh, and also use Fabric - http://docs.fabfile.org/en/latest/
Thank you. I'll look this things up. Haven't had to do deployment stuff in my previous life
As with most things, there is more than one way to do it. Push to the application server and hook it to your flask application using [uWSGI](http://flask.pocoo.org/docs/0.12/deploying/uwsgi/), for example.

[Here's](https://www.digitalocean.com/community/tutorials/how-to-serv...) an old guide for running Flask with uWSGI and nginx on Ubuntu. There are several more recent, detailed instructions online.

Personally, I have an AWS instance running a Node.JS server on (blocked) port 8000, a Django uWSGI app on 8001, and a static resume site, all being reverse-proxy served by nginx. So I don't really see the advantages of Nginx Unit yet.

the answer to this is usually "use docker". If you want to deploy your nginx as well, then you need docker-compose.yml and use "docker stack deploy".

If you are only looking to deploy your python code (and nginx/apache is constantly running on the server), then follow these steps

1. install docker on server 2. create an account on https://hub.docker.com/ 3. https://docs.docker.com/engine/swarm/stack-deploy/#deploy-th...

your docker workflow in the future looks like this: 1. test the application on your laptop inside a docker container 2. push container to docker hub 3. "docker update" your stack

Here will go their REST config api to force reloads.

BTW, it is a good idea to always do API versioning on production runs. That will eliminate the possibility that different API versions (files stuck in the cache, or simply people who kept browser open for a long time) use the same endpoint

Yes, I have a baseurl/v0/... in the naming scheme for now. (:
You can run gunicorn (that loads your flask app) as a service using systemd on e.g. port 9000 and then have nginx (also run as a systemd service) proxy port 80 traffic to that port and handle static files etc.
Ansible? Puppet? A five line bash script?
rsync && ssh target -t 'cd ~/app/; ...' and it's a one-liner.
All too hard. Use "bottle" (I think it's much the same as flask) - you just call 'run' and it does it's thing.

https://bottlepy.org/docs/dev/

I think that's more intended as demo server to get you started quickly while you're developing.

You'll probably want to switch to uwsgi or gunicorn before you actually deploy anything.

I haven't actually used Bottle, but with Flask the development web server seems to fall over if a client cancels ones of its HTTP requests, for example. It's really just a simple, light thing for mucking around with.