Prompt for Sept. 7

Today we're going to look at how to deploy applications to the web so that others can view them. The goal here is not to create a production-ready system. While we'll incorporate some libraries that are highly performant, we won't be following the absolute best practices for industry use so that we can instead make things a bit easier to prototype.

Requirements: Python 3 | Flask | WhiteNoise | Heroku account | GitHub account (recommended)
(you can use pip to install "flask" and "whitenoise")

A number of cloud "platform as a service" tools exist for hosting web-based projects efficiently. In short, they allow you to upload web server code to a cloud backend which then does the hard part of making them web-accessible. While today we will make use of Heroku, there are many different providers. These include (in no particular order) Microsoft Azure, AWS, Google App Engine, and Digital Ocean. I encourage you to examine each and figure out which set of features and end-user agreement works best for you. For the purposes of this class, you should not need a paid account.

Our system will involve the following components:

At the conclusion of the class, you'll be able to find the files we used here. You can access the Heroku site we created here.

Commands used in the lecture:

      # Make a project directory
      mkdir <PROJECT NAME, e.g. jmr395-info4310-hw1>
      cd <PROJECT NAME>

      # Initialize an empty git repository (make sure Git is installed)
      git init

      # Initial login to Heroku (only do once, make sure Heroku is installed)
      heroku login
      # optional: run "heroku autocomplete" and add the command it echoes to your .bashrc

      # Make a new Heroku project
      heroku create <PROJECT NAME, e.g. jmr395-info4310-hw1>

      # See how Heroku added a new remote repository
      git remote

      # Make a Flask app (make sure Python 3, Flask, and WhiteNoise are installed)
      #  Use a text editor of your choice. I use Atom, which can run from the command line
      # See the demo files for what we added to

      # At this point we also made a static directory and put some files in it for Whitenoise to serve

      # Test Flask server to see if it works (command may just be python for your machine)
      # Heroku needs a requirements file
      atom requirements.txt

      # It includes:
      #   gunicorn - library that runs our code, must include
      #   flask - imported in our .py
      #   whitenoise - imported in our .py

      # Heroku needs a Procfile telling it how to start the app
      atom Procfile

      # It includes
      #   web: gunicorn app:app    - "Host a web site using gunicorn and running

      # Commit the changes to your local git repository
      git status
      git add
      git add requirements.txt
      # etc. to add all changed/added files

      # Now commit the changes
      git commit -m "first commit"

      # send all recent changes to the "master" branch the "heroku" remote repository
      git push remote heroku master    

      # Heroku will now install the libraries and boot up

      # recommended command
      heroku ps:scale web=1

      # Open the Heroku site in your web browser
      heroku open

      # For ease, we also connected our local repository to Github
      # go to Github, make a repo, copy the .git web address, push our local changes

      git remote add github https: ...blah... .git
      git push remote github master