diff --git a/managed_vms/hello_world/.gitignore b/managed_vms/hello_world/.gitignore new file mode 100644 index 00000000000..a65b41774ad --- /dev/null +++ b/managed_vms/hello_world/.gitignore @@ -0,0 +1 @@ +lib diff --git a/managed_vms/hello_world/README.md b/managed_vms/hello_world/README.md new file mode 100644 index 00000000000..debe68e135b --- /dev/null +++ b/managed_vms/hello_world/README.md @@ -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) + +### 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 . diff --git a/managed_vms/hello_world/app.yaml b/managed_vms/hello_world/app.yaml new file mode 100644 index 00000000000..70f6bcf43ee --- /dev/null +++ b/managed_vms/hello_world/app.yaml @@ -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 diff --git a/managed_vms/hello_world/appengine_config.py b/managed_vms/hello_world/appengine_config.py new file mode 100644 index 00000000000..4fdc5d2b60f --- /dev/null +++ b/managed_vms/hello_world/appengine_config.py @@ -0,0 +1,4 @@ +from google.appengine.ext import vendor + +# Add any libraries installed in the "lib" folder. +vendor.add('lib') diff --git a/managed_vms/hello_world/main.py b/managed_vms/hello_world/main.py new file mode 100644 index 00000000000..28e73368add --- /dev/null +++ b/managed_vms/hello_world/main.py @@ -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] diff --git a/managed_vms/hello_world/requirements.txt b/managed_vms/hello_world/requirements.txt new file mode 100644 index 00000000000..632a1efabce --- /dev/null +++ b/managed_vms/hello_world/requirements.txt @@ -0,0 +1 @@ +Flask==0.10.1 diff --git a/managed_vms/hello_world_custom/Dockerfile b/managed_vms/hello_world_custom/Dockerfile new file mode 100644 index 00000000000..3928b108f81 --- /dev/null +++ b/managed_vms/hello_world_custom/Dockerfile @@ -0,0 +1,3 @@ +FROM google/python-runtime + +ENTRYPOINT /env/bin/gunicorn -b 0.0.0.0:8080 main:app diff --git a/managed_vms/hello_world_custom/README.md b/managed_vms/hello_world_custom/README.md new file mode 100644 index 00000000000..aa649c556ea --- /dev/null +++ b/managed_vms/hello_world_custom/README.md @@ -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 diff --git a/managed_vms/hello_world_custom/app.yaml b/managed_vms/hello_world_custom/app.yaml new file mode 100644 index 00000000000..a55f406cf63 --- /dev/null +++ b/managed_vms/hello_world_custom/app.yaml @@ -0,0 +1,3 @@ +runtime: custom +vm: true +api_version: 1 diff --git a/managed_vms/hello_world_custom/main.py b/managed_vms/hello_world_custom/main.py new file mode 100644 index 00000000000..bd4ea38ff5d --- /dev/null +++ b/managed_vms/hello_world_custom/main.py @@ -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] diff --git a/managed_vms/hello_world_custom/requirements.txt b/managed_vms/hello_world_custom/requirements.txt new file mode 100644 index 00000000000..074b390e620 --- /dev/null +++ b/managed_vms/hello_world_custom/requirements.txt @@ -0,0 +1,2 @@ +Flask==0.10.1 +gunicorn==19.3.0