Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding (temporary) managed VMs samples #125

Merged
merged 1 commit into from
Oct 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions managed_vms/hello_world/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lib
17 changes: 17 additions & 0 deletions managed_vms/hello_world/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## Google App Engine Managed VMs Python Hello World

This sample demonstrates using [Python on Google App Engine Managed VMs](https://cloud.google.com/appengine/docs/python/managed-vms/hello-world)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

broken link?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'll be fixed when the docs are published.


### Running & deploying the sample

1. Requirements.txt is not automatically processed by Google App Engine Managed VMs. To install dependencies for this sample, run:

$ pip install -t lib -r requirements.txt

2. Run the sample on your development server:

$ dev_appserver.py .

3. Deploy the sample:

$ appcfg.py update -A your-app-id .
9 changes: 9 additions & 0 deletions managed_vms/hello_world/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: 1
runtime: python27
vm: true
api_version: 1
threadsafe: true

handlers:
- url: .* # This regex directs all routes to main.app
script: main.app
4 changes: 4 additions & 0 deletions managed_vms/hello_world/appengine_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from google.appengine.ext import vendor

# Add any libraries installed in the "lib" folder.
vendor.add('lib')
26 changes: 26 additions & 0 deletions managed_vms/hello_world/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2015 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# [START app]
from flask import Flask


app = Flask(__name__)


@app.route('/')
def hello():
"""Return a friendly HTTP greeting."""
return 'Hello World!'
# [END app]
1 change: 1 addition & 0 deletions managed_vms/hello_world/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Flask==0.10.1
3 changes: 3 additions & 0 deletions managed_vms/hello_world_custom/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM google/python-runtime

ENTRYPOINT /env/bin/gunicorn -b 0.0.0.0:8080 main:app
20 changes: 20 additions & 0 deletions managed_vms/hello_world_custom/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## Google App Engine Managed VMs Python Custom Runtime Hello World

This sample demonstrates using [Python on Google App Engine Managed VMs](https://cloud.google.com/appengine/docs/python/managed-vms/hello-world) with a custom runtime.

This sample does not use the standard App Engine python runtime, but instead uses
a custom runtime. The custom runtime ensures that any requirements defined
in `requirements.txt` are automatically installed.

### Running & deploying the sample

To run the sample locally, use a virtualenv:

$ virtualenv env
$ source env/bin/activate.sh
$ pip install -r requirements.txt
$ python main.py

To deploy the sample, use the [Google Cloud SDK](https://cloud.google.com/sdk)

$ gcloud preview app deploy app.yaml
3 changes: 3 additions & 0 deletions managed_vms/hello_world_custom/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
runtime: custom
vm: true
api_version: 1
32 changes: 32 additions & 0 deletions managed_vms/hello_world_custom/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright 2015 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# [START app]
from flask import Flask


app = Flask(__name__)


@app.route('/')
def hello():
"""Return a friendly HTTP greeting."""
return 'Hello World!'


if __name__ == '__main__':
# This is used when running locally. Gunicorn is used to run the
# application on Google App Engine. See ENTRYPOINT in the Dockerfile.
app.run(host='127.0.0.1', port=8080, debug=True)
# [END app]
2 changes: 2 additions & 0 deletions managed_vms/hello_world_custom/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Flask==0.10.1
gunicorn==19.3.0