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 a sample for extending the compat runtime. #207

Merged
merged 1 commit into from
Feb 29, 2016
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
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
9 changes: 9 additions & 0 deletions managed_vms/extending_runtime_compat/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Extend the Managed VMs python-compat runtime.
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
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 extending runtime python-compat

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 2016 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]
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI if you omit specifying a region_tag, and do specify exclude_regexp="^#", you should be able to include the entire file sans top-level comments.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems hacky. I'd rather the region tag.

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 2016 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