Flask Devops: Release Scalable Applications with Heroku | Jorge Escobar | Skillshare
Drawer
Search

Playback Speed


  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Flask Devops: Release Scalable Applications with Heroku

teacher avatar Jorge Escobar, Technologist, entrepreneur and open source fanatic

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

    • 1.

      Introduction 1.1

      1:45

    • 2.

      Introduction 1.2

      0:58

    • 3.

      Hosting Types

      2:51

    • 4.

      Our Local Dev Environment

      0:34

    • 5.

      The Heroku Architecture

      1:24

    • 6.

      How Heroku Releases Code

      2:20

    • 7.

      Deploying a Simple App to Heroku

      0:56

    • 8.

      Deploy using Git

      4:21

    • 9.

      Deploy using Docker

      2:18

    • 10.

      Databases and Other Services

      1:22

    • 11.

      A Heroku Postgres App

      9:09

    • 12.

      A Heroku MySQL App

      6:20

    • 13.

      Assign a Domain Name to your Heroku Application

      1:56

    • 14.

      Conclusion

      0:31

  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.

152

Students

--

Project

About This Class

This course will teach you how to deploy your Flask applications to one of the most popular Platform as a Service (Paas) providers in the world: Heroku. With Platform as a Service hosting, you don’t need to worry about the small details, like server provisioning or database tuning. You focus on developing your application and you let Heroku worry about the rest.

Flask Devops is a new series of courses which will cover how to effectively deploy your Flask application to audiences across the world using the most popular hosting providers, while also covering topics like code deployment, continuous integration and delivery, monitoring and architecture. You can get the course about the provider you want or get the whole series in one.

The course covers the basic concepts of the Heroku release cycle and architecture, how to use Git or Docker as your development environment, how to use the built-in Postgres Heroku service or the MySQL plugin providers and routing using your own custom domain.

If you already know the basics of Flask and you are interested in how to deploy your applications to a hosting service, this is the course for you.

The course is divided in 4 sections:

  • Heroku concepts which cover the architecture and the release cycles

  • An introduction to the release concepts using a simple Hello World Flask app using both Git and the new Heroku container services which leverages Docker

  • An overview of how to deploy data driven applications including Heroku’s own Postgres service and one of the most popular MySQL plugins

  • How to efficiently assign a domain name to your application

The course has a number of video tutorials as well as the boilerplate Flask application codebase. You can also purchase an eBook with all the material.

The course can take anywhere from 3 to 7 days to complete based on how much material the student completes daily.

Additionally we’re constantly updating the course, adding contents thanks to the feedback of our students.

Join this course and continue your path to becoming a professional backend web developer!

Who is the target audience?

  • Programmers and developers with basic Flask knowledge who want to learn how to deploy their applications on public servers
  • Application architects who want to understand better how to effectively deploy applications
  • Startup CTOs who want to understand how to scale their applications
  • Computer Science Students who want to get exposed to real life hosting concepts

Meet Your Teacher

Teacher Profile Image

Jorge Escobar

Technologist, entrepreneur and open source fanatic

Teacher

From Zero is an educational project created by Jorge Escobar, a technologist, entrepreneur and open source fanatic with more than 15 years of experience in the development of web applications in New York City.

Jorge has worked in well established companies like Yahoo!, Univision and MongoDB and has also been the technical founding member of various successful tech startups that have received multiple rounds of venture capital.

The biggest problem Jorge has experienced during his career is finding well rounded developers and he interviewed hundreds of them for positions in the teams he was leading. A constant pattern (no matter if candidates came from a good university or had a few years of experience) was the lack of practical, real world knowledge.

That's why Jorge... See full profile

Related Skills

Development Web Development
Level: Intermediate

Class Ratings

Expectations Met?
    Exceeded!
  • 0%
  • Yes
  • 0%
  • Somewhat
  • 0%
  • Not really
  • 0%

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.

Transcripts

1. Introduction 1.1: In this day and age, every developer needs to at least have an idea on how to set up and maintain the servers that power their applications. This is known in the industry as Debs. Hi, My name is Jorge Escobar, and I'm really excited to teach you everything I know about the exciting world off develops as a back and developer. You cannot just depend on other developers how to release your coat to the world. It is essential that you know the basics of how to properly launch your application to the servers that will ultimately reach your users. This is what this course is about. You will learn from trash and without any previous knowledge how professional startups released their applications for their audiences. You will learn about load balancers, cold deployment, monitoring and testing your application using their most popular providers like Roku A, W S and the Little Ocean. The's first section of the course will focus on Hiroko. I will be adding new courses on a monthly basis so that you learn specifically the hosting provider you need or learn all of them. Listen, there might be all their forces or videos out there now teaching beats and bass is off What you will learn with me. And thanks to my experience with some of the leading companies in the world, I will guarantee you learn the top level practices by the course now and start your journey into the world off them ups. 2. Introduction 1.2: welcome toe. Flask them up. Seiroku, The purpose of this course is to introduce you to the world of one of the most exciting types of hosting platform. As a service using one of its leaders, Hiroko Hiroko allows you to focus on developing your application on they take care of the rest. You don't have to worry about server infrastructure, scaling or deployment. All you need to do is do a simple get push on your application is available to the world. I will teach you step by step, how to deploy your application using Hiroko both using the git for flow as well as her new docker deployment workflow. So if you already use Docker, it's really simple to deploy toe heroically. We will also go over how to properly set up their Adams. And finally, we will take a look at how we can use our own domain name for the APP. Let's get started 3. Hosting Types: In order for your application to be available to the world, you need to set up a server that's connected to a high speed Internet connection, and it's powered on 24 hours off the day. There are many ways to accomplish this. Let's review the most common ways to host our application. Bare metal hosting means that you actually buy your servers and either rent on Internet connected Cabinet on a data center or you build your own data center in your premises. Some companies choose to go this way if they have special security requirements, or they want to control every aspect off the whole thing system like Google or Facebook, the second type of hosting available thanks to decoration off virtualization software East Virtualized servers. The process here is that a bare metal server is divided in a handful off sub servers that have their own file system, CPU and hard drive re sources, which are monitored by the virtualization application. You would then rent on a monthly basis, this piece off the server. One of the providers I used back then and it's still around is Lee Node, which offer servers a steep as $5 per month. They also offer customer support 24 7 and I highly recommend them as an option. Ah, huge shift occurred in 2000 and six, when Amazon announced they would be offering their server infrastructure for developers to rent on the whole infrastructure as a service industry was born with AWS. The difference between ES and ritual I servers is that he s servers can run for fractions off time. You can speed up a server for one hour and charge just for that hour. There's also a large range of servers from least powerful, very powerful. Other companies have spawned since then, including Rackspace and Digital Ocean. Typically, the low end servers cost around $15 per month, but at this time, A W S also offers a free tier, but it's limited to 12 months. A new wave off server hosting came about with the creation off platform. As a service, hosting these providers allow you to concentrate on just writing your application, and they take care of the rest, including server provisioning, scaling and database Hosting. Some of the most popular ones are Roku, Google Cloud Platform, Red Hat Open Shift and Microsoft Usher one of the benefits that passed providers give you is the ability to try out their services for free. In this course, you will learn how to deploy your application in one of the most popular past providers, Hiroko. 4. Our Local Dev Environment: in order for us to play with Hiroko, it's necessary for you to have a local Dev environment set up. You can either have your applications set up using virtual M and local software installed like my sequel or mongo DB or you can also be using Docker together following videos on how to set up a local Dev environment using homebrew on the Mac or Shackle Lady on Windows. Hiroko also works well with Docker. If you want to learn more about Docker, tick out my doctor course. 5. The Heroku Architecture: Hiroko's power lies in how it can scale your application without you having to worry about the infrastructure underneath. Let's look at a very high level architecture off a simple Hiroko application When you says , Visit your site there. Forwarded to Hiroko's load balancer, I load balancer managers incoming connections and then route it toe any available server. Heracles Cloud servers are called Dino's. One very important thing to note is that diners don't keep any data in them. They're constantly being created and destroyed. To store data, you need to connect to an external data layer. Often this will be Hiroko's own post Chris that of a service or using an add on for older that a basis like my sequel or mongo db. So what happens when you get a lot of traffic? Not to worry, he just increased the number of Dino's on the load. Balancer will automatically distribute the load evenly among the dinos. Hiroko even offers auto scaling, which means that no matter what time of the day, a sudden increase of traffic occurs, your application can handle the load without any problem. Notice that the data base layer also scales up automatically. You don't have to worry about anything 6. How Heroku Releases Code: at the beginning. It's a little hard to understand the flow to publish your application to the Hiroko servers , but I'll walk you through it visually first, so that you have a good understanding off the process before we do it in the terminal. First you would create or fork your application. Engage hub. This is going to be your origin repository. As you work on your application, you would use this repository as your backup. The next thing you do is create a Hiroko application. Think of the application as the blueprint from where you will generate the actual servers that will get spawned to support your application when you deployed. When you create this application, your local give repository will be modified to reflect a new remote endpoint called Hiroko . So from this point on, you can post to your original repository, or you can push tow the heroic a repository. The difference is that when you push through the heroic a repository, the blueprint is modified for any new servers. So when you do a gate push Hiroko, you will be updating the blueprint on. You can then generate the servers. From there, the command to spawned the new servers is called Hiroko PS That scale and then the process name and the number of servers. The Web servers are assigned to the Service Web, which is a special type of server that receives requests made to your applications. Huaral. So in this graph, we're doing heroic o. P s dot scale. Web equals one to spawn just one Web server. If you are using docker, the process doesn't involve get anymore. You would still have your origin give repository, but on the Hiroko side, you would logging toe their container servers and push changes using Hiroko Container that push Web or the name of the service. After that, the process to spawn new Dino's is the same as before. We just need to type Roku ps dot scale Web equals one 7. Deploying a Simple App to Heroku: for our first project, we're going to deploy a simple hello world flask application on her own. First, create a free Hiroko account by visiting their sign up page, making sure you select the python language, create the account and store the details somewhere safe. Now we need to install the heroic A command line interface or CLI. This application allows it to interact with her local from your terminal in Windows Toe Shoko, install Hiroko cli and then Mac do Brewing Stone Hiroko looking to Hiroko using her Roku logging. 8. Deploy using Git: we will first check out how to do the process using Get If you are using Docker, we will review the process later in this section. First go ahead and forth in my simple flat app repository found under from Syria. Give hope account. I have put a link in the description off the video, then CD to the directory where you develop your obligations and clone it locally. Make sure you see the toe the new repository. Now we naval virtual f petroleum dash be python three ve and be activated Source ven being activated Then people stole their requirements Peeping stole that our requirements txt and then run the unicorn server Unicorn app, colon app That's be serious 00 5000. Check that the application is running So why do we use gonna corn and not the flask server ? Because the flats server or the manage me why we've used is not multi threaded And so it's not scalable Toby used on any production environment. Now we start working with their local side of things. First we need to tell Hiroko what version of Python will be using for these. We create a wrong time dot Txt file. And at the Python three version your system has check it by doing Python three, Dusty. Next, we need to create the profile, which is a text file to tell Hiroko how to boot up our application. We will just copy and paste the unicorn command here as if we were on the terminal. Now at all the code to the report gate, add doctor committed Did commit an initial. Commit and push it. Get Bush Dash. Ooh, Origin Master, We are now going to test the application locally. But using the Hiroko Command do Roku local weap. If you go to the local host 5000 on your browser, you should see your application running. Now we're going to create the Hiroko application with Hiroko Create here. We can see a Ural was randomly generated for the application. And also a Hiroko specific give repository was created as well. This git repository was also added as a remote endpoint for you to push through. If you navigate toe the euro, you'll see a place holder page. Now we want to push the report to the special Hiroko git repository. Just type. Get Bush her local master. You should see the application being installed remotely, and when it's done, your application will be deployed toe Hiroko. Now we need to actually start a virtual server, which Hiroko calls Dino's. So run the following command. Hiroko ps Colon scale Web equals one. This tells Hiroko toe Assign one dino to your web process. Now, if you visit the Ural, you should see the hello world app running. You can also automatically open by typing Hiroko open on the console. You can check the status of your diners by doing heroic O. P s. And you can also read the logs If you have any errors by typing Hiroko locks finally, you can shut down the up by doing heroic O P s Colin scale Web equals zero. Bear in mind that the free tier gives you limited time on the diners being up 9. Deploy using Docker: If you're using Docker as your development environment, let's check out how to use it with Hiroko. First installed a container registry. Plug in by running Hiroko plug ins. Colon Install Hiroko dash container. That's registry. Before the next step, make sure to open your docker client looking toe the container service her local container . Colin, log in. If you haven't done so, go ahead and forth. They My simple flat scab, gave repository found on the from zero Get have account. I have put a link in the description of the video, Then CD to the directory where you develop your applications and clone it locally. Make sure you see the to the new repository. The report has a docker file and some instructions on how to run locally. As you can see on the docker file were using an environment viable called port, which is set when we run the application locally with a docker cmd command. This is because Hiroko will assign a dynamic port that we don't know beforehand. Now we're ready to create a new hero. Clap her local create you will see then you Hiroko up being created. Now we build a image and pushed to the Hiroko container Herro Cool container colon push wept. Now we need to actually start a virtual server, which Hiroko calls Dino's. So run the following command. Heracles PS Colon scale Web equals one. Now, if you visit the Ural, you should see the hello world up running. You can also automatically open by typing Hiroko open on the console and you can also read the logs. If you have any errors by typing Hiroko logs finally you can shut down the up by doing Hiroko PS Colin Scale Web Equals zero 10. Databases and Other Services: One thing you need to realize is that any data services on platform as a service providers are completely separate. It is a good practice in any application, as a matter of fact, to treat the data services off your application as a separate resource and to not expected Toby, a server running in the same box. So, for example, if you have an application that relies on a sequel database, you will typically develop your app with those services locally available. But when you push to Hiroko, you need to use their version of these services, which are usually offered ask plug ins. This makes total sense as they don't want you to worry about scaling or operating these separate data services. We will start first with the Hiroko Boss CREss sequel, that of a service, which is the only database type Hiroko offers natively. If you haven't used prosperous yet, don't worry. The concepts are very similar to my sequel commands and said after that we will be deploying a Hiroko. My sequel App, using Docker for both exercises, will be using a flask boilerplate application that is essentially a counter that starts the number of times you've reloaded the page and stores it in the database 11. A Heroku Postgres App: Let's go ahead and create a Hiroko up using the Hiroko Post Christ out of a service. The benefit of using Hiroko's own database service are many, but two important ones come to mind. First, scaling is managed by Hiroko, so you don't have to worry about high traffic bursts. Hiroko will scale up and down the database for you. Second, we can use a free tier without providing a kurta card. The steer is called the Hobby Deva Tear. To start the process, you can fork the code from this repository and then clone it locally. Now we enable virtual and petroleum does be python three ve envy activated source. Ben being activated, then peeping stole the requirements. Baby install, dash our requirements Txt Here we will experience one of the tricky things to manage when you are deploying your application from your computer toe. Other servers. The main issue is that each environment ie your laptop. A test server. The production servers has different credentials for things like databases or other services. I've tried many options, but the best one I found is to set your environment variables locally using your local operating system and then passed those toe the settings B y file using Python's OS dot environment. Then when you publish the code to remote servers, you would have to remote environment virals set up in those servers to set environment variables on the MAC, you used the export key. For example, Export your application. Underscore setting equals test value while on windows you use, said Ax. For example, said X, your application underscore setting test value. So what you want to do is to track this environment variables in your code base in an n virus file without the actual values, and then set the real values in your local environment. In the repository just cloned, there is a file called end bars, which has all the required environment variables for this project. So let's set the environment. Virals in windows do the following said X db User name, Country user. FedEx Devi password Counter Password said X db Host local host said X database name counter Restart the power shell toe Get the viable is reflected to list all the environment variables. Do get dash child item E N V semi colon check. The divi rubbles are there to set the environment variables on Mac OS you would to export. They be used. Her name equals counter user export. DB Password equals counter password export. TV host equals local host and export database. Name equal counter to list all the environment variables. Do print em, However, please note that these variables will be the leader when you exit the terminal in my quest to make them permanent, edit the dot bass profile in your home directory and at them there. Now let's create the database. Start the prosperous server on your local environment and then looking toe prosperous with be sequel. Post grass. Now create the user and password that will be connecting to the database. We will use the same ones we have in n virus file. Create role counter user with logging password, counter password and then give it database creation. Permissions. Alter roll country user created TV now exit using control. Now looking using this user peace equal post crest that you counter user, create the database. Create that a vase counter next door. The database initialization with bison managed to be I mean it and then create the migration with python managed B y db my great and then apply the changes with Typhon. Manage me. Why db off? Great. Check that the app is good By running a Rachael local web. I'm checking on local host 5000 notice. Create our Hiroko up. Make sure you are logged in tow. Hiroko, on the command line note that we're going to pass a name for the application which Roku will assign to you if it's available. Hiroko, create PG Counter. This will create the PG counter up on Hiroko. Next, we will install the Postal Service from Hiroko Hiroko, Arun's create Caracal Dash Post Chris Dash Hobby that, Steph that stash up pg counter here were telling Hiroko we want to use an at own, which is Hiroko's version off a plugging in this case, it's the Hiroko Post, Chris Aronne and we're attaching it toe RPG counter app The whole be that version is a free tier off post crest offer by Hiroko. After you press enter, you will see some information regarding the database host on a confirmation that it was created. You can check the conflict variables information off your Hiroko up by typing Roku conflict . If you look at the data base, your l you will see it has a user name, password host and database name within it. They used her name in the string after post grace on before the semicolon. The password is after the semi colon and before the at sign. The host is between the outside and the forward slash. Under that, I base is after the forward slash. We need to set these as environment variables within our app so that they get transferred in our settings file after the Hiroko app runs. We do that by using the config, Colon said. Command double check that the conflict fires are correct with Hiroko can fake, we're ready to deploy. First, get at and commit and push your changes to your own get report. Get push origin Master. This will have the Migrations folder to your repository, which is fine. That means we can then move forward the Hiroko database. But just doing DB upgrade, but will say that in a moment. Now push toe Hiroko's git repository. This will create the applications blueprint. Harakah calls this blueprints. Slugs. Get Bush her local master at the end. You should see it's DPS PG counter Hiroko app dot com Deployed to Iraq If you visit the your L, you will get an internal server error. If you look at the logs, you'll see why relation counter does not exist. We need to do the migration on our Harakah Posters database. We can spawn a temporary dino and run the command by doing Hiroko, Run python. Manage. Stop, Ey, they be upgrade now. Reload the page. You should see the counter running. Congratulations. You have your first database driven Hiroko application. 12. A Heroku MySQL App: Let's take a look at how we could to on my sequel database driven flask application with Hiroko. I will be using Docker for this example, but he can also do it with Roku. Get or Flow. There are a handful of my sequel plug ins for her local. In this case, I'll be using Jost E B. My secret. Please note that to be able to use dis plugging, you need to provide your credit card number to her local to verify your account. You won't be charged anything, but it's an extra layer of user verification. Should you abuse the system somehow? First, you need to fork the code from this repository and then clone it locally. I will be using Docker for this example, but it can also use, we're told him as we saw before. Now let's create our Hiroko up. Make sure that you're logged in tow. Hiroko on the command line Baroque will create next we need to install the just Eby at on Hiroko Arun's Colon. Create jobs, Stevie. This will create on my sequel. Instance. After it's done, you can check the connection parameters by doing Hiroko Come fake colon, get just to be underscore euro. This will print out your my sickle connection euro. You can check out the connection parameters by doing her local Adams colon Open jaws TB. Since our connection parameters vary between our local environment on the Hiroko just TV environment, we're going to leverage the conflict bars functionality off Roku. Basically, we can create configuration Bibles that will be available when the application is run, which would be different from the ones we have in our local environment. Next we will add the same configuration marvels using their values we got from just to be using the Hiroko cli you can check all the environment variables with Hiroko config. Now we build the image and pushed to the Hiroko Docker container Arocha Container colon Push Web Let's run the virtual server. Her local P s golden scale web equals one and now opened by typing Roku open on the consult , we get internal several air. Why? First thing we do is look at the lock files Roku logs. And as you can see, it says that the table doesn't exist to fix this. When he took great their migrations folder on our docker container. What we need toe build it first. There's a docker compose Yamil file that can help us with that. So do docker compose build. This will build the containers to get them up and running. Type docker compose up. Next, we open a new tab on our terminal and type Dr Ex SEC counter up my sequel on the score. Web underscore one. Bison managed B Y Baby in it, then DR Except Counter Up My sequel Underscore Web on the school one. Dyson managed the wide DB Migrate and finally Dr Except Counter Up my sequel. Underscore Web Underscore one. Typhon Manage me. Why DB Operate. This will create the Migrations folder that we can use for our Roku container. Before we do that, let's just add it to our own repository. Get at duct, get commit dash M created migrations and get push origin. Master. Since we changed our code base, we need to push this changes to the container do Roku container calling Push Web. Now we can finally do the migration on a remote my sequel database. We can spawn a temporary dino and run the command by doing her Roco run Bison managed B y DB upgrade Now, if you reload the page, you will see the counter up and running. And if you refresh the page, you should see the counter increment. 13. Assign a Domain Name to your Heroku Application: one of the main things we want to do is to add a custom mural for application In this lesson will check how to do that with Hiroko, we can check any domains associated with our APS by doing Hiroko domains on the command line. As you can see, I don't have any yet. I have a domain name on Gold Daddy that I'm actually not using, titled Horace dot CEO, and would make for a great personal site. So I'll associate that domain name to my app. To do that will do. Hiroko Domains ad www dot Horace dot seal Hiroko tells me that I should point my DNS provider Toe the sub domain. Www dot Horace dot ceo Hiroko DNS dot com Let me do that on Go Daddy. It can be a few hours, while DNS propagation complete, you can check if the domain has been set by doing host www dot Horace dot ceo. You should see the Haruko DNS eyepiece in there when it's complete. Now turn on your application. Her local P s called on scale where equals one and check with your new costs. A mural www dot Horace dot c o you can also use SSL. If you have an SSL certificate for your domain, you can use her, Roque asserts for that. 14. Conclusion: Morocco is definitely an amazing platform for developing your applications and for publishing them to your audience. If you don't want to worry about the infrastructure piece or hiring, develops engineers to maintain your code up and running. Hiroko brings the power off scalability, toe everyone and makes launching new instances as easy as writing an instruction on your terminal window. Thanks for watching and see you in the next course.