Skip to content

Web Server

Bryan Runck edited this page Nov 10, 2019 · 1 revision

Overview

The web servers for the bootcamp are deployed on Google Cloud Platform's Compute Engine.

Virtual Machine Setup (GCP Compute Engine)

The following describe how to set up a virtual machine on GCP. Step 2 describes the specific details used.

  1. Tutorial on how to setup a linux instance
  2. To match the bootcamp instance use:
  • Machine Type: f1-micro (1vCPU, 614mb ram)
  • Image: Ubuntu 16.04 LTS
  • Firewall: Allow HTTP and HTTPS traffic
  1. Set up static IP address for web server (VPC Network > External IP addresses > type > static)
  2. Set up firewall rules (VPC Network > Firewall rules > Create firewall rule > name: flask > targets: All instances in network > source ip ranges: 0.0.0.0/0 > protocols and ports, tcp: 5000 > create)
  3. At GCP Compute Engine > Virtual Machines > click "SSH". A terminal will open.

Then, in the terminal, clone the git repo onto the web server

$ git clone https://github.com/runck014/gems_iot_bootcamp.git

Web Server Hello World

  1. Run web_server_setup.sh script
$ bash gems_iot_bootcamp/web_server/web_server_setup.sh

Note: At this point, your web server should be up and running. You should see:

 * Serving Flask app "XXXXXXXXX FLASK APP NAME"
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
  1. To access your web server from the internet, find the IP address at GCP > compute engine > vm instances > external IP > *copy and paste the IP address with the firewall port into a web browser, e.g. x.x.x.x:5000. You should see a "hello world" response if it worked correctly.

Remote SSH into GCE Virtual Machine

  1. Change SSH configuration settings

  2. Set user name and passwords

Restarting a web server

To start the web server, there are two steps.

  1. Kill the webserver
<ctrl> c
  1. Start the flask server
python NAME_OF_YOUR_APP.py

Work on files with web server running

Often, you may want to edit files or navigate your file system while your flask app runs. TMUX is a tool that allows this. It provides tabs for a terminal environment. To start tmux:

  1. Start tmux tmux attach
  2. Create new tab <cmd> c
  3. See cheat sheet on tmux for more details

Learning, Debugging, and Testing REST API's

Insomnia and Postman are two common platforms to help interactively develop REST API's. They allow you to interact with a REST API via HTTP methods using a desktop application. Combined with print statements on a remote server, they are useful for learning and debugging.