Building Data-Driven Web Apps with Flask and SQLAlchemy Transcripts
0:00 Now, the first thing we need to do
0:01 to get started with our deployment
0:02 is have somewhere to deploy it to.
0:05 We could deploy to Heroku, or Azure, or AWS
0:09 or some other Platform-as-a-Service thing
0:12 but what I want to show you
0:13 is how to deploy to Linux.
0:15 'Cause if you know how to deploy to Linux
0:17 all those other things, maybe skip some steps
0:19 and are just easier.
0:20 But this gives you the most flexibility
0:22 to run your code, your web app, wherever you need
0:25 and with the most configuration options available.
0:28 We're going to use Digital Ocean for our host.
0:31 If you use something like AWS, EC2
0:33 or Lightsail, or Linode
0:36 once we finish going through
0:37 the process in this cloud portal
0:39 it's going to be, basically, all the same.
0:41 So those are all recommended places
0:43 you might check it out, you might try this
0:44 but I'm most familiar with Digital Ocean
0:46 so I'm going to do that one here.
0:47 So let's go and get started by creating a droplet.
0:51 We go to the market place and pick prebuilt machines
0:54 like, I want to run a Disqus server on 18.04, and so on.
0:58 But I'm going to just focus right here on this.
1:00 Now the default is the latest longterm support, Ubuntu.
1:04 Alright, this is the latest.
1:05 But this is the latest longterm support
1:06 and I recommend you keep a longterm support version.
1:10 It's still pretty new.
1:11 So, let's go down and then choose our plan.
1:13 These numbers might look big
1:14 but if you just scroll over
1:16 we have some pretty sweet ones.
1:18 We could choose the $5 or the $10 a month one
1:20 and we'll just go with $5.
1:23 With this server, we can handle several million
1:25 data-driven, Python-backed requests per month.
1:29 No problem, for $5.
1:30 And if you need more, you know
1:31 go crazy, spend 10 dollars.
1:32 But this is the one we're going to do.
1:34 We're going to not add backups
1:36 block storage is like an external drive that you can have
1:39 that's independent of the lifecycle of your server.
1:42 Like, you could destroy your server
1:43 and still have this drive around, we don't need that.
1:45 I'm going to choose San Francisco, 'cause it's near me
1:48 so it'll be nice and quick.
1:49 If this was a real deployment
1:50 I would choose New York, probably.
1:52 Because most of my customers would be
1:54 either in the U.S. or Europe.
1:55 And the east coast of the U.S.
1:57 is a pretty good compromise, say
1:59 for people in California and people in Germany.
2:02 Alright? We don't need extra stuff
2:05 you might turn on monitoring here.
2:08 I'm going to check off a couple of the SSH keys
2:10 that I have around. So a lot of SSH in
2:13 and disable log in with the password
2:16 so it'll be, basically, impossible to brute force attack
2:20 trying to log in.
2:21 Let's give it a name like pypi-server
2:24 maybe with a dash, something like that.
2:27 And, I think we're ready to go.
2:29 Let's just click create and see what happens.
2:31 Alright, the server is created.
2:33 I think it's just now starting to start up.
2:36 So it might take a moment.
2:37 We can click here, and click copy the IP address.
2:40 And put this away and now what we're going to is
2:42 let's just try to login.
2:44 So we come over here, we want to SSH as the root user
2:48 over to that IP address.
2:50 Now on MacOS and Linux, SSH has been around for a long time
2:54 this should work in the terminal no problem.
2:56 On Windows, it's just recently been added
2:58 to the command prompt, I believe.
3:00 And I think it might have been a part of PowerShell before
3:02 so you should be able to run it there.
3:04 Let's try to SSH into it.
3:06 It says, The first time, you've never seen this machine
3:09 and are you sure you want to exchange your keys with it?
3:11 Yes, I do. And, it takes a moment
3:14 we should be logged in. There we go, perfect!
3:17 Our machine is up and ready
3:18 and we can do amazing things like
3:20 ask what files are here
3:21 or what directory we're in, things like that.
3:23 However, note there's a small little problem.
3:27 Our server has come to life with 19 security updates
3:31 and 41 updates.
3:33 Very first thing you should do, right away
3:35 like immediately when you create this server
3:38 is make sure you get the latest software patches
3:40 and install it.
3:41 You do not want to run something on the internet
3:43 that has security vulnerabilities.
3:45 You want to minimize that.
3:46 So let's go do that now. We'll say apt update.
3:49 That, okay, that's the latest software versions
3:51 and it'll say apt upgrade to actually apply them.
3:56 So it's okay, we're going to do all this stuff here.
3:58 And we're going to install
4:00 when you see something like this
4:01 we're going to install 18.104.22.168
4:05 the new kernel for Linux, so that's kind of a big upgrade
4:08 and there's a bunch of other stuff going on here as well.
4:13 There you have it. It took maybe a minute and a half
4:16 but, due to time shifting
4:17 I was able to make that seem really short.
4:19 So everything's installed
4:20 and if we log out, we can come over here and log back in
4:24 and you'll see we have zero security updates
4:27 but now a reboot, a system restart is required.
4:30 So don't forget to this step.
4:32 We'll come over here and do a reboot.
4:33 Notice right now we're running on
4:36 what version? 22.214.171.124.
4:39 And when we come back, we should be on version 51
4:41 along with a ton of other updates.
4:44 Now, because this is a full kernel update
4:45 it might take a few seconds longer
4:47 but, you know, ten to fifteen seconds
4:49 is what you should expect for, you know
4:51 the upper bound of how long this takes.
4:54 Yes, perfect! Here we are, we have a brand new server
5:00 a brand new server running on 51
5:03 zero updates, no reboot required
5:06 and we're ready to go.
5:07 So our server is up and running.
5:08 Now it's up to us to configure it to be a web server
5:12 and to deliver our cool PyPI app.