Deploy the Application
Learn how to successfully deploy your web application on the internet.
We'll cover the following
Deploying an application to Heroku
We now only need to deploy the application and tell it to use a dyno. To deploy it, we use git
to add and commit our latest changes. The new configuration files and Procfile should also be added. Once this is done, we push a copy to Heroku:
$ git push heroku master
Enumerating objects: 35, done.
Counting objects: 100% (35/35), done.
Delta compression using up to 4 threads
Compressing objects: 100% (23/23), done.
Writing objects: 100% (23/23), 156.18 KiB | 3.72 MiB/s, done.
Total 23 (delta 8), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> nginx-buildpack app detected
remote: -----> nginx-buildpack: Installed nginx/1.16.1 to app/bin
remote: -----> nginx-buildpack: Added start-nginx to app/bin
remote: -----> nginx-buildpack: Added start-nginx-solo to app/bin
remote: -----> nginx-buildpack: Default mime.types copied to app/config/
remote: -----> nginx-buildpack: Custom config found in app/config.
remote: -----> Python app detected
remote: -----> Need to update SQLite3, clearing cache
remote: -----> Installing python-3.7.6
remote: -----> Installing pip
remote: -----> Installing dependencies with Pipenv 2018.5.18
remote: Installing dependencies from Pipfile.lock (7dc556)
remote: -----> Installing SQLite3
remote: Sqlite3 successfully installed.
remote: -----> Discovering process types
remote: Procfile declares types -> web
remote:
remote: -----> Compressing...
remote: Done: 76.3M
remote: -----> Launching...
remote: Released v6
remote: https://intense-bayou-52717.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/intense-bayou-52717.git
34a2a2f..d4e4d6b master -> master
We can see that after it pushes the files to Heroku, it builds the source, detects that it’s a Python application and its version, then finds the Pipfile.lock
file and installs the dependencies it requires. It also sets up NGINX and gives a number to the version. Each time it is updated, the number is incremented by one. It also tells us the application’s URL.
Starting the dyno
This gets everything ready, but we still need to start a dyno. We use the ps:scale
command in the Heroku CLI to stand up one web server as follows:
$ heroku ps:scale web=1
Scaling dynos... done, now running web at 1:Free
In this command, ps
manages the dynos, and ps:scale
is the scale
subcommand of the ps
command. We’re then passing it the argument web=1
. The web
variable is the number of dynos that are receiving web, that is, HTTP, traffic. Note that we can set web=0
to shut off our application from the internet. This can be useful if we want to halt changes, for instance when we’re migrating a database.
We can see how the application is scaled by using the Heroku CLI ps
command:
$ heroku ps
Free dyno hours quota remaining this month: 983h 26m (98%)
Free dyno usage for this app: 0h 0m (0%)
For more information on dyno sleeping and how to upgrade, see:
https://devcenter.heroku.com/articles/dyno-sleeping
=== web (Free): bin/start-nginx gunicorn -c config/gunicorn.conf.py
server.app:app (1)
web.1: up 2020/01/25 14:38:46 -0500 (~ 59s ago)
This tells us what tier we’re on and how much usage our application has seen.
We can open the site in our browser using its subdomain address. Alternatively, we can use the CLI.
$ heroku open
This should open the page, as served by Heroku, in our browser.
Live application
We’ll now be able to play Langman on the internet. Here are a few scenes from the game, taken so that we can see the icon next to the tab. First, signing in:
Get hands-on with 1400+ tech skills courses.