This project is no longer actively developed or maintained.
For more information about App Engine, refer to our documentation.
Fortune Speak is a Python sample app for Managed VMs that synthesize and display a random fortune sound everytime you load the page.
It extends a traditional Python App Engine application with new functionalities that are unlocked by Managed VMs
- Get more CPU and RAM by running your App Engine module on Google Compute Engine VMs
- set GCE machine type in
app.yaml(view sources)
- set GCE machine type in
- Escape the sandbox by writing to files and launching subprocess
- cache wave file to local disk (view sources)
- launch the
fortuneexecutable (view sources)
- Customize your runtime by installing third party packages
- install the
fortunepackage withapt-get(view sources) - install
pyttsxandflaskfromrequirements.txtwithpip(view sources)
- install the
- Call into native Python C extensions
- import and call
_speakpyttsxdriver (view sources)
- import and call
Below is a tutorial that will guide you on how to build, run and deploy this application step by step.
During this step you will
- create a new Managed VMs project
- provision your local development environments
- run the final application locally and deploy it to production
- Go to Google Developers Console and create a new project.
- Enable billing
- Open
https://preview.appengine.google.com/settings?&app_id=s~<project> - Click
Setup Google APIs project for VM Runtime...
-
Install boot2docker
-
Setup and start boot2docker
boot2docker init boot2docker up
-
Get and install the SDK preview release
-
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
-
Get the application code
git clone https://github.com/GoogleCloudPlatform/appengine-vm-fortunespeak-python cd appengine-vm-fortunespeak-python git fetch --all -
Run the application locally
gcloud preview app run app.yaml -
After seeing a request to
/_ah/startin the logs open http://localhost:8080
-
Build and deploy the application image
gcloud preview app deploy app.yaml --server preview.appengine.google.com -
After the command complete succesfully open
https://<project>.appspot.com
During this step you will:
- create a simple Python hello world application
-
First switch to
step0branchgit checkout step0 -
Create a
app.yamlfile w/ the default App Engine configuration -
Create a
main.pyfile usingwebapp2w/ aRequestHandlerthat printhello: <Country the HTTP request is coming from> -
Run locally and deploy it to production.
-
Review the solution
-
Compare with your working directory
git diff step1 -R -
If stuck, stash your working directory and switch to the solution branch
git stash git checkout step1
During this step you will:
- enable Managed VMs in your application configuration
- select a bigger instance class
- Modify
app.yamlto addvm: true - Modify
app.yamlto select a bigger instance class - Run locally
- Notice that a Dockerfile has been created in your application directory
- Deploy to production
-
Review the solution
-
Compare with your working directory
git diff step2 -R -
If stuck, stash your working directory and switch to the solution branch
git stash git checkout step2
During this step you will:
- perform system operation: write to the local filesystem
- Modify
main.pyto log the greetings to a file called 'messages.txt' - Modify
main.pyto add a newRequestHandlerthat display the content of this file. - Run locally and deploy it to production
-
Review the solution
-
Compare with your working directory
git diff step3 -R -
If stuck, stash your working directory and switch to the solution branch
git stash git checkout step3
During this step you will:
- add native dependencies to your application with
apt-get - perform system operattion: launch an external process
- Modify
DockerfiletoRUN apt-get install -y fortunes - Modify
main.pyto launch/usr/games/fortuneswith thesubprocessmodule in the mainRequestHandler, capture the standard output and display it back in the response. - Run it locally and deploy to production
-
Review the solution
-
Compare with your working directory
git diff step4 -R -
If stuck, stash your working directory and switch to the solution branch
git stash git checkout step4
During this step you will:
- managed your application dependencies with
pipandrequirements.txt - rewrite your web application handler using a modern python framework
Flask
- Create a
requirements.txtwithFlasklisted as a dependency - Modify
DockerfiletoRUN pip install -r requirements.txt -t . - Edit
main.pyto useflask.routeinstead ofwebapp2.RequestHandler - Run it locally and deploy to production
-
Review the solution
-
Compare with your working directory
git diff step5 -R -
If stuck, stash your working directory and switch to the solution branch
git stash git checkout step5
During this step you will:
- add
pyttsxC extensions as a dependency of your application - call into native code to perform text to speech.
-
Modify
requirements.txtto listpyttsxas a depdency -
Copy the file
synth.pyfrom the master branchgit checkout master synth.py -
Call
synth.Sayfrom you main request handler and return the wavform data with theaudio-x/wavcontent type -
Run it locally and deploy to production
-
Review the solution
-
Compare with your working directory
git diff step6 -R -
If stuck, stash your working directory and switch to the solution branch
git stash git checkout step6