Skip to content

Commit

Permalink
Adding a sample for extending the compat runtime.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Wayne Parrott committed Feb 26, 2016
1 parent b094eae commit c77d284
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 3 deletions.
5 changes: 5 additions & 0 deletions managed_vms/extending_runtime_compat/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.dockerignore
Dockerfile
.git
.hg
.svn
10 changes: 10 additions & 0 deletions managed_vms/extending_runtime_compat/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# [START dockerfile]
FROM gcr.io/google_appengine/python-compat-multicore

# Install the fortunes binary from the debian repositories.
RUN apt-get update && apt-get install -y fortunes

ADD . /app/

RUN if [ -s requirements.txt ]; then pip install -r requirements.txt; fi
# [END dockerfile]
17 changes: 17 additions & 0 deletions managed_vms/extending_runtime_compat/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## Google App Engine Managed VMs python-compat Hello World

This sample demonstrates how to extend the [python-compat](https://cloud.google.com/appengine/docs/managed-vms/python/migrating-an-existing-app) runtime 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 automatically installed by the runtime when deploying, however, to run the sample locally you will need to install dependencies:

$ pip install -r requirements.txt

2. Run the sample on your development server:

$ dev_appserver.py --runtime python-compat .

3. Deploy the sample:

$ gcloud preview app deploy
8 changes: 8 additions & 0 deletions managed_vms/extending_runtime_compat/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
runtime: custom
vm: true
threadsafe: true
api_version: 1

handlers:
- url: .* # This regex directs all routes to main.app
script: main.app
30 changes: 30 additions & 0 deletions managed_vms/extending_runtime_compat/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# 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]
import subprocess

from flask import Flask


app = Flask(__name__)


# [START example]
@app.route('/')
def fortune():
output = subprocess.check_output('/usr/games/fortune')
return output, 200, {'Content-Type': 'text/plain; charset=utf-8'}
# [END example]
# [END app]
30 changes: 30 additions & 0 deletions managed_vms/extending_runtime_compat/main_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# 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.

import os

import main
import pytest


@pytest.mark.skipif(
not os.path.exists('/usr/games/fortune'),
reason='Fortune executable is not installed.')
def test_index():
main.app.testing = True
client = main.app.test_client()

r = client.get('/')
assert r.status_code == 200
assert len(r.data)
1 change: 1 addition & 0 deletions managed_vms/extending_runtime_compat/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Flask==0.10.1
6 changes: 3 additions & 3 deletions managed_vms/hello_world_compat/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
## Google App Engine Managed VMs Python Hello World
## Google App Engine Managed VMs python-compat Hello World

This sample demonstrates using [Python on Google App Engine Managed VMs](https://cloud.google.com/appengine/docs/python/managed-vms/hello-world)
This sample demonstrates using the [python-compat](https://cloud.google.com/appengine/docs/managed-vms/python/migrating-an-existing-app) runtime 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 automatically installed by the runtime when deploying, however, to run the sample locally you will need to install dependencies:

$ pip install -t lib -r requirements.txt
$ pip install -r requirements.txt

2. Run the sample on your development server:

Expand Down
1 change: 1 addition & 0 deletions managed_vms/hello_world_compat/app.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
runtime: python-compat
vm: true
threadsafe: true
api_version: 1

handlers:
- url: .* # This regex directs all routes to main.app
Expand Down

0 comments on commit c77d284

Please sign in to comment.