googlearchive / appengine-vm-fortunespeak-python

Getting started with Python Managed VMs runtime
Apache License 2.0
17 stars 7 forks source link

status: inactive

This project is no longer actively developed or maintained.

For more information about App Engine, refer to our documentation.

Fortune Speak

Fortune Speak is a Python sample app for Managed VMs that synthesize and display a random fortune sound everytime you load the page.

Demo

It extends a traditional Python App Engine application with new functionalities that are unlocked by Managed VMs

Below is a tutorial that will guide you on how to build, run and deploy this application step by step.

Prerequisites

During this step you will

Create your project

  1. Go to Google Developers Console and create a new project.
  2. Enable billing
  3. Open https://preview.appengine.google.com/settings?&app_id=s~<project>
  4. Click Setup Google APIs project for VM Runtime...

Setup Docker

  1. Install boot2docker
  2. Setup and start boot2docker

    boot2docker init
    boot2docker up

Setup the Cloud SDK

  1. Get and install the SDK preview release
  2. Setup the Managed VMs components:

    gcloud components update appengine-managed-vms
    gcloud auth login
    gcloud set project <project>
    docker pull gcr.io/google_appengine/python-compat

Run the application locally

  1. Get the application code

    git clone https://github.com/GoogleCloudPlatform/appengine-vm-fortunespeak-python
    cd appengine-vm-fortunespeak-python
    git fetch --all
  2. Run the application locally

    gcloud preview app run app.yaml
  3. After seeing a request to /_ah/start in the logs open http://localhost:8080

Deploy the application to your project

  1. Build and deploy the application image

    gcloud preview app deploy app.yaml --server preview.appengine.google.com
  2. After the command complete succesfully open https://<project>.appspot.com

Hello World!

During this step you will:

  1. First switch to step0 branch

    git checkout step0
  2. Create a app.yaml file w/ the default App Engine configuration

  3. Create a main.py file using webapp2 w/ a RequestHandler that print hello: <Country the HTTP request is coming from>

  4. Run locally and deploy it to production.

Solution

Hello Managed VMs

During this step you will:

  1. Modify app.yaml to add vm: true
  2. Modify app.yaml to select a bigger instance class
  3. Run locally
  4. Notice that a Dockerfile has been created in your application directory
  5. Deploy to production

Solution

Escape the sandbox

During this step you will:

  1. Modify main.py to log the greetings to a file called 'messages.txt'
  2. Modify main.py to add a new RequestHandler that display the content of this file.
  3. Run locally and deploy it to production

Solution

Customize the Runtime Environment

During this step you will:

  1. Modify Dockerfile to RUN apt-get install -y fortunes
  2. Modify main.py to launch /usr/games/fortunes with the subprocess module in the main RequestHandler, capture the standard output and display it back in the response.
  3. Run it locally and deploy to production

Solution

Manage Python dependencies

During this step you will:

  1. Create a requirements.txt with Flask listed as a dependency
  2. Modify Dockerfile to RUN pip install -r requirements.txt -t .
  3. Edit main.py to use flask.route instead of webapp2.RequestHandler
  4. Run it locally and deploy to production

Solution

Use Python C extensions

During this step you will:

  1. Modify requirements.txt to list pyttsx as a depdency

  2. Copy the file synth.py from the master branch

    git checkout master synth.py
  3. Call synth.Say from you main request handler and return the wavform data with the audio-x/wav content type

  4. Run it locally and deploy to production

Solution