Skip to content

Commit 1616c63

Browse files
author
Jonathan Wayne Parrott
committed
Merge pull request #125 from GoogleCloudPlatform/managedvms
Adding (temporary) managed VMs samples
2 parents 599496d + 395b0fe commit 1616c63

File tree

11 files changed

+118
-0
lines changed

11 files changed

+118
-0
lines changed

managed_vms/hello_world/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lib

managed_vms/hello_world/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## Google App Engine Managed VMs Python Hello World
2+
3+
This sample demonstrates using [Python on Google App Engine Managed VMs](https://cloud.google.com/appengine/docs/python/managed-vms/hello-world)
4+
5+
### Running & deploying the sample
6+
7+
1. Requirements.txt is not automatically processed by Google App Engine Managed VMs. To install dependencies for this sample, run:
8+
9+
$ pip install -t lib -r requirements.txt
10+
11+
2. Run the sample on your development server:
12+
13+
$ dev_appserver.py .
14+
15+
3. Deploy the sample:
16+
17+
$ appcfg.py update -A your-app-id .

managed_vms/hello_world/app.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: 1
2+
runtime: python27
3+
vm: true
4+
api_version: 1
5+
threadsafe: true
6+
7+
handlers:
8+
- url: .* # This regex directs all routes to main.app
9+
script: main.app
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from google.appengine.ext import vendor
2+
3+
# Add any libraries installed in the "lib" folder.
4+
vendor.add('lib')

managed_vms/hello_world/main.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright 2015 Google Inc. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# [START app]
16+
from flask import Flask
17+
18+
19+
app = Flask(__name__)
20+
21+
22+
@app.route('/')
23+
def hello():
24+
"""Return a friendly HTTP greeting."""
25+
return 'Hello World!'
26+
# [END app]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Flask==0.10.1
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM google/python-runtime
2+
3+
ENTRYPOINT /env/bin/gunicorn -b 0.0.0.0:8080 main:app
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
## Google App Engine Managed VMs Python Custom Runtime Hello World
2+
3+
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.
4+
5+
This sample does not use the standard App Engine python runtime, but instead uses
6+
a custom runtime. The custom runtime ensures that any requirements defined
7+
in `requirements.txt` are automatically installed.
8+
9+
### Running & deploying the sample
10+
11+
To run the sample locally, use a virtualenv:
12+
13+
$ virtualenv env
14+
$ source env/bin/activate.sh
15+
$ pip install -r requirements.txt
16+
$ python main.py
17+
18+
To deploy the sample, use the [Google Cloud SDK](https://cloud.google.com/sdk)
19+
20+
$ gcloud preview app deploy app.yaml
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
runtime: custom
2+
vm: true
3+
api_version: 1
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright 2015 Google Inc. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# [START app]
16+
from flask import Flask
17+
18+
19+
app = Flask(__name__)
20+
21+
22+
@app.route('/')
23+
def hello():
24+
"""Return a friendly HTTP greeting."""
25+
return 'Hello World!'
26+
27+
28+
if __name__ == '__main__':
29+
# This is used when running locally. Gunicorn is used to run the
30+
# application on Google App Engine. See ENTRYPOINT in the Dockerfile.
31+
app.run(host='127.0.0.1', port=8080, debug=True)
32+
# [END app]

0 commit comments

Comments
 (0)