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
app.yaml
(view sources)fortune
executable (view sources)fortune
package with apt-get
(view sources)pyttsx
and flask
from requirements.txt
with pip
(view sources)_speak
pyttsx
driver (view sources)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
https://preview.appengine.google.com/settings?&app_id=s~<project>
Setup Google APIs project for VM Runtime...
Setup and start boot2docker
boot2docker init
boot2docker up
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/start
in 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:
First switch to step0
branch
git checkout step0
Create a app.yaml
file w/ the default App Engine configuration
Create a main.py
file using webapp2
w/ a RequestHandler
that print hello: <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:
app.yaml
to add vm: true
app.yaml
to select a bigger instance classReview 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:
main.py
to log the greetings to a file called 'messages.txt'main.py
to add a new RequestHandler
that display the content of this file.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:
apt-get
Dockerfile
to RUN apt-get install -y fortunes
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.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:
pip
and requirements.txt
Flask
requirements.txt
with Flask
listed as a dependencyDockerfile
to RUN pip install -r requirements.txt -t .
main.py
to use flask.route
instead of webapp2.RequestHandler
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:
pyttsx
C extensions as a dependency of your applicationModify requirements.txt
to list pyttsx
as a depdency
Copy the file synth.py
from the master branch
git checkout master synth.py
Call synth.Say
from you main request handler and return the wavform data with the audio-x/wav
content 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