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