Building Data-Driven Web Apps with Pyramid and SQLAlchemy Transcripts
Chapter: Deployment
Lecture: Concepts: Deployment

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Let's review some of the concepts we saw during deployment. Now, we deployed to Ubuntu and DigitalOcean. But you don't have to go to DigitalOcean.
0:10 What you saw would work almost exactly the same in places like AWS, or Azure, or Linode, or whatever. You do have to be aware on AWS
0:18 there's also a cloud-controlled firewall that happens to be blocking things so you have to unblock the HTTP ports in a couple places.
0:26 That's AWS. It's kind of super complicated. And if you're doing basic things that anyway, that's a whole different discussion.
0:32 Let's talk about the concepts. We started by having a production.ini. And there's a couple settings that I didn't point out there that are important.
0:41 I did point out the uWSGI section. So here you have the localhost port it's going to listen on, this is where Nginx speaks to it
0:50 you don't expose this on the internet directly. Master mode means we're going to run five processes for parallelism.
0:57 Five actually can handle quite a bit. Threads amplifies that further. And then the hari kari thing is if they don't respond in a certain amount of time
1:04 they'll get killed off. And finally, you want logging in your app so you can figure out what's happening.
1:09 The production.ini settings I did not show you were there's a difference between the development.ini and production.ini, where for example
1:17 the templates don't auto-reload. You have to restart the process if you change the templates. The debug toolbar thankfully is not there in production.
1:25 That would be bad, you don't want it there. So things like that, you can check the differences. They're not major but there's a few other differences
1:31 that Pyramid itself puts into those two files, plus this. Once we have our production.ini ready to go
1:40 we want to create a system daemon, using the systemd that's going to run uWSGI anytime the server is on.
1:47 It's going to auto-start it and keep it running. So here is the settings we used. Here, we just say execstart use that virtual environment to uWSGI
1:56 and use our production.ini to do it, so really simple. I just noticed I didn't have a forward slash in the runtime directory in the end.
2:04 uWSGI claims that the directory is invalid if you don't explicitly put that trailing slash so make sure you put that there, if you care.
2:12 Alright, so you have basically this file in the files I'm giving you as well. So this would be uWSGI running as a system daemon
2:19 and you're going to need to copy that from wherever it is over to etc/systemd/system. Finally we want to set up the outer shell
2:28 the thing that listens on the actual internet the thing that serves the static files and then also delegates the Python request
2:34 back to uWSGI and that's Nginx. So here's how we can configure that. You can listen on more than one port.
2:41 You can listen on 80 and do a redirect to 443. There's a lot of configuration stuff you can do but here's a super basic one.
2:47 Listen on 80 for fake_pypi.com as the domain name that we registered. You know, registered by typing it into our host file. My serve up static files
2:57 point at the static directory and set some expiration date. And this one you want to copy over to etc/nginx/sites-enabled.
3:07 Now finally we also have in our Nginx files telling it to go, if you don't go to /static just go to / or anything below that, except static.
3:16 Just go and do a request over to your application which forwards over to our configuration in uWSGI.
3:24 Be really careful that that port 8999 is the same one as you have back in your production.ini's configuration for uWSGI. They have to match, of course
3:33 so that they can find each other. Or use a system socket. That takes a little more setup so I'm just using the localhost HTTP.
3:41 And that's it. I gave you the script of all the pieces you need to run. These are the details of the configuration files you have to set up.
3:47 And hopefully you come away feeling like setting up that Linux server wasn't too much work. Did talk a lot about it, but if I just put my head down
3:54 and focused, and went after it we could probably do it in 10 minutes And most of that time is waiting on installs you know, apt this, pip that, right?
4:02 Just waiting for those things to happen. So not a lot of work once you have the scripts and everything put together for you.


Talk Python's Mastodon Michael Kennedy's Mastodon