Python for Entrepreneurs Transcripts
Chapter: Deploying to the cloud
Lecture: Deployment map
Login or
purchase this course
to watch this video and the rest of the course contents.
0:01
We've gone through a lot of hands on work with Ansible and we're getting a lot closer to finishing our deployment
0:07
and getting or application up and running. This is a good time to take a break from writing the code and think about the bigger picture,
0:12
what we're actually accomplishing when we do a deployment. After you've done a bunch of deployments you can start to visualize a map in your head
0:18
of how all the different pieces fit together, and that's what I want to present here
0:22
with some visuals to help you tie together all these disparate Ansible tasks and the yaml files, and all the commands that we are running
0:30
through Ansible to get all the pieces up and running. It all starts with you working on your application, on your local development environment
0:36
in most cases, that is going to be on your desktop or on your laptop and chances are it's going to be self contained on your own system;
0:42
and then you have prospective customers that are out there with their web browsers, their iPhones, their Android tablets,
0:48
they would love to use your application, become customers of your business but there is no way for them to access
0:54
what you're running locally on your development environment. First off, it's not secure in order to run a business like that,
1:00
and second, your business would shut down every time you shut down your laptop or your computer, that doesn't really make any sense.
1:05
We need to deploy it on a remote server, and that's what we've be doing so far
1:08
one of the first steps in this chapter was to go to the digital ocean website, sign up for an account, and then provision a server.
1:14
The server provides the foundation for the rest of what we are doing in the deployment.
1:19
When we provision the server, we didn't just get a bare bones box we also installed an operating system on it,
1:24
that operating system Ubuntu Linux allowed us to connect from our local development environment to that remote machine over ssh;
1:32
then when we ran any of our Ansible commands, they went through an ssh connection. That connection from our local development environment
1:41
to the remote machine allowed us to then install the web server, which is nginx in our case, and we also went to the Namecheap website
1:49
to configure a domain name; the domain name was then configured through DNS which are the domain name servers, that pretty much keep a look up table
1:58
between the easy to type in and remember URLs like Pythondeploymentexample.com and the IP address of our server.
2:06
We also had our server contact the Let's Encrypt service to grab a free SSL certificate this SSL certificate allows us to serve each https connections
2:15
so that we're having a secure conversation between any of the customers that are going to eventually come to our web service,
2:21
and the server that is providing that service. That's pretty much where we are right now, we've done a lot of work so far,
2:27
and we've got the baseline for what we need to finish this deployment.
2:31
And we also have our Ansible playbooks that are the foundation for the next few steps that were going to take, in the remainder of this chapter.
2:38
So what are those next few steps? We need to get our source code from github onto our server
2:43
and our source code includes not only the Python application but also the css, the JavaScript, images, the static assets that our application needs
2:52
in order to properly serve our customers, it's stored on github, and we're going to pull that down from the server.
2:57
Our local environment is going to keep that connection with the server but the server itself is going to contact github and use git
3:05
to pull down the source code and the static assets that we have. Once we have the source code, we can stand up our Python environment
3:12
using a virtual env, just like we do on our local development environment,
3:15
install our dependencies that are stored in our requirements.txt file or a setup.py file
3:20
and use pip to go out to PyPi to pull down our dependencies, like Pyramid; and then we have a web server gateway interface server,
3:28
this is the Python web application server that runs our Python code and the virtual env isolates those application dependencies
3:35
just like it does on our local development environment. And again, our server is going to go and contact PyPi, download those dependencies,
3:41
they don't come from our local development environment they come from the central hosted service PyPi.
3:48
Now once a deployment is finished, we can get some notifications oftentimes, when you have a sufficiently large application
3:53
a deployment can take 5, 10, 15 minutes to complete so it's nice to walk away from your deployment, go grab a cup of coffee
3:59
and just get a text message when the whole thing is completed. So we'll see an example of that, where I will show how to use Twilio
4:05
just to send yourself some notifications right from your Ansible playbook. You can also have other notifications such as email or a Slack message
4:11
you can take the same exact principle and put notifications wherever you need to
4:15
this is particularly handy if you have other people working on the application and doing the deployments and you just want to be notified
4:21
every time the application is updated, when we get that notification that the deployment is done,
4:26
that's where the real work that our application is doing comes in. Customers on their web browsers, their iPhones, tablets,
4:33
they can go type in your domain name, the domain name servers will give them the IP address that they should look up
4:39
and then all of the communication happens between their devices and the web server that you have running on your server, hosted on Digital Ocean.
4:46
The web server passes some requests on to our Python code so it functions as a reverse proxy and other requests it's simply serving up files
4:53
so it's doing what web servers are traditionally doing which is serving up static assets such as the css and the JavaScript.
5:00
All of the communication that happens between a customer's device and your application, happens through the web server.
5:07
And that's how your application will be up and running, finish with the deployment when you want to update your application,
5:13
you simply run through this process again, and the steps that have already been completed, for example,
5:18
system packages that need to be installed, Ansible will check to make sure that those system packages are still installed
5:24
but skip over those steps, and simply pull down the latest version of the code and restart the web server, the wsgi server,
5:30
and the latest version of your application will be running and continue to serve customers. So, that's the big picture of how our deployment works
5:36
we're getting really close to being finished with your application's deployment. So next up, we're going to finish setting up the web server,
5:42
and we'll grab our source code, set up all our application dependencies,
5:45
get the wsgi server up and running, add the few final touches to our Ansible playbook such as getting notifications when the deployment is done,
5:52
and then your app will be up and running ready to serve customers.