Building data-driven web apps with Pyramid and SQLAlchemy Transcripts
Lecture: Deployment overview and topology
0:00 Now that we've built our web app
0:01 it's time to share it with the world, right?
0:04 It's great to have a little app that we built
0:06 but it's basically useless
0:07 if we don't put it on the internet.
0:09 It is a web app after all.
0:11 At least put it on a internet
0:12 for your internal company, right?
0:14 So, that's what this chapter's all about.
0:16 We're going to see how to deploy our web application
0:20 onto a standard Linux server in the cloud.
0:23 I want to be clear that this is not the only option
0:26 there's certainly other ways to put our web app out there.
0:29 We could go use something like, Heroku
0:31 and just configure Heroku to grab our stuff
0:35 out of our GitHub repository
0:36 and launch it into their system.
0:38 Those to me seem easier
0:40 they're less flexible and often more expensive.
0:42 But they're easier.
0:44 So what I want to do is show you how to deploy
0:46 to a standard Linux server
0:48 run it in some cloud VM somewhere
0:50 and you can adapt that from DigitalOcean, Linode
0:53 AWS, Azure, where ever you want to run it.
0:56 So, we're going to do that in this chapter.
0:59 And that brings us to our overall architecture and topology.
1:03 One of the things we're not going to focus on here is
1:06 setting up and configuring a database server.
1:09 I consider that a little bit outside of the scope
1:11 of this course, and you can pick the database server
1:13 that you want and then configure it
1:15 so you'll have to fold that in here
1:17 right now, we're just using SQLite, which means
1:20 as long as the file comes along we have our database.
1:22 So, with that caveat, here's how it's going to work.
1:25 We're going to go get a box in the cloud
1:27 which is going to be an Ubuntu server
1:30 probably 18.04, that's what that little icon
1:33 on the bottom left means.
1:34 On here we're going to install Nginx.
1:37 Nginx is the thing that people will actually talk to.
1:41 This listens on port 80 and on port 443
1:44 and for regular HTTP and on 443 for HTTPS encrypted traffic.
1:50 A request is going to come in here
1:52 but this does not run our Python code.
1:55 It serves up static files and it delegates to the thing
1:58 that actually runs our Python code.
2:00 That thing is called uWSGI
2:04 uWSGI, I guess it should be.
2:06 Now uWSGI when we run it
2:08 will handle our Python request.
2:11 However, we don't want to just run one of them.
2:14 Remember, you may or may not be aware that Python
2:16 has this thing called the GIL, Global Interpreter Lock
2:19 which inhibits parallelism within a single process.
2:23 And a lot of the ways people get parallelism in Python
2:26 is to actually create multiple processes.
2:29 This also has great benefits for fail over
2:31 or if something goes wrong with some process
2:33 running one of our requests we can kill it
2:35 and have other processes deal with it.
2:37 It's not the only way to get parallelism
2:39 but it's one really nice way.
2:40 So we're going to do that and have uWSGI
2:42 spin off a whole bunch of itself.
2:46 This will actually run our Python code.
2:48 I'm just going to host the Python runtime
2:51 and it's going to launch and initiate a bunch of copies
2:54 of our website running in parallel.
2:56 Here we have it configured to run six worker processes.
3:00 So, here's what's going to happen.
3:02 Request is going to come in
3:03 hopefully over HTTPS, right, you want to set up
3:06 some sort of encrypted layer here
3:07 right, that's the way the web's going these days.
3:11 And once we're inside the server
3:13 we no longer need encryption
3:14 so we'll just do a regular HTTP request
3:16 over to UWSGI itself.
3:18 UWSGI will decide which of it's worker processes
3:21 is ready to handle it. This time that one is.
3:23 Maybe next time this one's free or maybe that one.
3:26 It will find one that's not busy or less busy
3:29 and then pass that request off
3:31 and then return the response back through Nginx
3:34 back out over HTTPS, to the client.
3:37 So this is what we're going to set up.
3:39 An Ubuntu server, with these things along with Python 3
3:43 and our web app ready to roll.