Python for Entrepreneurs Transcripts
Chapter: Deploying to the cloud
Lecture: Hosting

Login or purchase this course to watch this video and the rest of the course contents.
0:01 We'll start a deployment by setting up for an account on Digital Ocean, and getting it all set up with a droplet,
0:08 which is the equivalent of a virtual private server that we can log into and deploy our application to.
0:14 Head over to digitalocean.com in your web browser and click the sign up button, and if you already have an account, go ahead and log in,
0:21 but I'm going to walk through this with a brand new account. After you've entered your email and a password
0:26 it's going to ask you to confirm, just go to your email inbox and click on the link that will confirm your account. Once you've confirmed your account,
0:35 you're going to have to enter some billing information to verify that you are a legitimate user. Now the great part is that there is a promo code
0:41 for every single student for 50 dollars to get started with Digital Ocean, but you will still need to enter your credit card information
0:46 or connect your PayPal account to get started. So, enter your billing information, then scroll down, select the link that says I have a promo code,
0:55 and when this modal box pops up, go to training.talkpython.fm sign into your account and then click account at the top navbar, go into student offers
1:03 and you'll see Digital Ocean credit which you can claim for free. Now, this is my code, it won't work anymore I've already used it sorry,
1:10 but you'll copy and paste this and then enter that into the promo code field. Once you've entered your payment information
1:18 and applied your promo code, you get to the third screen in Digital Ocean's onboarding flow, which is to create a new droplet,
1:24 click the create a new droplet button, and this is how we're going to provision our first server. First we are going to choose an image,
1:31 this is the distribution that we're going to deploy for our server. Take the default one of Ubuntu and you're going to want to be
1:37 on 16.04 which means April 2016, now this is an LTS release long term support, so even if it's a year or two out of date, that doesn't matter
1:46 because they're still applying updates and security fixes for the next five years from the initial release of this operating system.
1:54 So Ubuntu 16.04 should be your choice for distribution. Scroll down a little bit and you get to choose a size,
2:00 now I recommend you go with a ten dollar a month plan, just for getting started, you can always resize up and down your server,
2:07 but this will give you five months of runway with just the Digital Ocean credit that you got. If you feel like the application that you are building
2:15 is more compute intensive or needs more memory, feel free to choose a different option. I often use ten dollar a month
2:19 servers for Python applications and they work great. Keep scrolling down to the data center region, and pick the one that's closest to your customers,
2:27 in my case I'll just choose San Francisco since I am based in San Francisco and of course if you're in Europe you're going to want to
2:34 choose something in Europe, if you're in Asia Pacific region, probably worth choosing a server there,
2:39 that way your server is as close as possible to your customers. Keep scrolling down and for now, we'll just leave the additional options
2:44 unchecked but backups can be extremely useful, monitoring can be very useful, so these are options that you want to take a look at later on.
2:51 Now we need to add an ssh key. So click new ssh key, and then there's two ways we can handle this,
2:57 one- you can use the ssh key that we created earlier in the git chapter, or we can create a new ssh key, just in case you've forgotten,
3:04 I'm going to create one right now on the command line. I've shifted over into Ubuntu 16.04, this is the same operating system release
3:11 as what we are going to deploy to, so in this chapter I'm just going to use Ubuntu 16.04,
3:16 that way we can mimic the environment that we're working with locally and the environment we're going to deploy to.
3:23 You've already got your development environment set up, so don't worry if you're not using Ubuntu for development,
3:28 if you're using Mac or Windows that's totally fine, just know that ultimately your application is going to be running on Linux,
3:33 the Ubuntu distribution. Alright, let's create that ssh key. So we use the ssh keygen command, and we're going to give it
3:40 the type of an RSA key with 2048 bits, if any of this is confusing, feel free to jump back to the git chapter where we go
3:48 through creating all the ssh keys for working with our git repositories.
3:51 All right in this case I'm just going to save this file under my home directory, I called it do deploy. I create two files, one is the private key,
4:00 this one that we've named here, and there will be a public key that we can share that has the .public extension at the end.
4:06 We're not going to want to use a pass phrase because we're going to use this key in order to automate our deployments.
4:11 Alright now this is generated, we're going to take a look at the contents of the public version of this key.
4:21 Now copy and paste this bit, the entire thing, and we'll paste it over into here, and then give it a name that you're going to remember.
4:37 So my case blue yellow jackets prod ssh key. Click add ssh key, now we're going to be able to use our private key
4:46 in order to connect as soon as this server starts up, just create a single droplet and if you want you can choose
4:52 a specific host name and then click the create button. Now you'll have to wait just a few minutes,
4:58 server is being provisioned, and then eventually it'll start up. Sweet, now our server is ready to go and we can copy this IP address,
5:05 and now let's just make sure that we can connect to the server, we're going to use the ssh command, and the -i argument,
5:13 i is used to specify a particular private key rather than your default private key which is stored in the .ssh directory
5:21 for your user account, in this case we're going to point it to the one that we just created, because it is the private key version
5:27 that will allow us to authenticate against the public key that we used when we created the server.
5:33 So this is home matt do deploy, and then we're going to say root, so the root user is the one that we're going to use to initially connect,
5:42 and then we paste the IP address, the Digital Ocean gave to us. We'll get prompted, are you sure you want to connect to the server- say yes,
5:52 and now we've connected to a remote server as root. So now we've got our server ready to go,
5:59 and now over the next few videos, we'll start configuring the server so that they can run our application and it will also be locked down
6:05 and secure against unauthorized access attempts.


Talk Python's Mastodon Michael Kennedy's Mastodon