Skip to content

Commit 88f8ff7

Browse files
author
Doug Greiman
committed
Merge remote-tracking branch 'origin/master' into dgreiman/builder
2 parents 66a1a2b + 0823e4c commit 88f8ff7

13 files changed

Lines changed: 116 additions & 12 deletions

File tree

.coveragerc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[run]
2+
branch = True
3+
4+
[report]
5+
exclude_lines =
6+
pragma: no cover

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
*.pyc
2+
.cache
3+
.coverage
24
.nox
35
/cloudbuild.yaml_local.sh
46
/cloudbuild_benchmark.yaml_local.sh

build.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ fi
108108

109109
# Use latest released Debian as our base image
110110
export DEBIAN_BASE_IMAGE="gcr.io/google-appengine/debian8:latest"
111-
export FULL_BASE_IMAGE="${DOCKER_NAMESPACE}/python:${TAG}"
112-
echo "Using base image name ${FULL_BASE_IMAGE}"
111+
export STAGING_IMAGE="${DOCKER_NAMESPACE}/python:${TAG}"
112+
echo "Using base image name ${STAGING_IMAGE}"
113113

114114
# Generate Dockerfiles
115115
for outfile in \
@@ -121,7 +121,7 @@ for outfile in \
121121
tests/google-cloud-python-system/Dockerfile \
122122
tests/integration/Dockerfile \
123123
; do
124-
envsubst <"${outfile}".in >"${outfile}" '$DEBIAN_BASE_IMAGE $FULL_BASE_IMAGE $GOOGLE_CLOUD_PROJECT_FOR_TESTS'
124+
envsubst <"${outfile}".in >"${outfile}" '$DEBIAN_BASE_IMAGE $STAGING_IMAGE $GOOGLE_CLOUD_PROJECT_FOR_TESTS'
125125
done
126126

127127
# Make some files available to the runtime builder Docker context

nox.py

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import fnmatch
1616
import os
1717

18+
import nox
19+
1820

1921
def _list_files(folder, pattern):
2022
"""Lists all files below the given folder that match the pattern."""
@@ -24,7 +26,8 @@ def _list_files(folder, pattern):
2426
yield os.path.join(root, filename)
2527

2628

27-
def session_check_requirements(session):
29+
@nox.session
30+
def check_requirements(session):
2831
"""Checks for out of date requirements and optionally updates them."""
2932
session.install('gcp-devrel-py-tools')
3033

@@ -37,3 +40,44 @@ def session_check_requirements(session):
3740

3841
for reqfile in reqfiles:
3942
session.run('gcp-devrel-py-tools', command, reqfile)
43+
44+
45+
@nox.session
46+
def lint(session):
47+
session.install('flake8', 'flake8-import-order')
48+
session.run(
49+
'flake8',
50+
'--import-order-style=google',
51+
'scripts',
52+
'nox.py',
53+
)
54+
55+
56+
@nox.session
57+
@nox.parametrize('version', ['3.4', '3.5', '3.6'])
58+
def tests(session, version):
59+
session.interpreter = 'python' + version
60+
session.install('-r', 'scripts/requirements-test.txt')
61+
session.run(
62+
'py.test',
63+
'--ignore=scripts/testdata',
64+
'--cov=scripts',
65+
'--cov-append',
66+
'--cov-config=.coveragerc',
67+
'--cov-report=', # Report generated below
68+
'scripts',
69+
env={'PYTHONPATH': ''}
70+
)
71+
72+
73+
@nox.session
74+
def cover(session):
75+
"""Run the final coverage report.
76+
77+
This outputs the coverage report aggregating coverage from the unit
78+
test runs (not system test runs), and then erases coverage data.
79+
"""
80+
session.interpreter = 'python3.6'
81+
session.install('coverage', 'pytest-cov')
82+
session.run('coverage', 'report', '--show-missing', '--fail-under=97')
83+
session.run('coverage', 'erase')

scripts/requirements-test.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
flask
2+
pytest
3+
pytest-cov
4+
pyyaml

tests/benchmark/Dockerfile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ${FULL_BASE_IMAGE}
1+
FROM ${STAGING_IMAGE}
22

33
# Install performance
44
RUN pip install performance

tests/benchmark/benchmark_between_releases.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
# Build the benchmark image for release 1 from Dockerfile
44
echo "Building image for release 1"
5-
export FULL_BASE_IMAGE="${DOCKER_NAMESPACE}/python:${TAG1}"
6-
envsubst <"Dockerfile".in >"Dockerfile" '$FULL_BASE_IMAGE'
5+
export STAGING_IMAGE="${DOCKER_NAMESPACE}/python:${TAG1}"
6+
envsubst <"Dockerfile".in >"Dockerfile" '$STAGING_IMAGE'
77
docker build --no-cache -t benchmark_1 .
88
rm Dockerfile
99

1010
# Build the benchmark image for release 2 from Dockerfile
1111
echo "Building image for release 2"
12-
export FULL_BASE_IMAGE="${DOCKER_NAMESPACE}/python:${TAG2}"
13-
envsubst <"Dockerfile".in >"Dockerfile" '$FULL_BASE_IMAGE'
12+
export STAGING_IMAGE="${DOCKER_NAMESPACE}/python:${TAG2}"
13+
envsubst <"Dockerfile".in >"Dockerfile" '$STAGING_IMAGE'
1414
docker build --no-cache -t benchmark_2 .
1515
rm Dockerfile
1616

tests/deploy_check/app.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
runtime: python
2+
env: flex
3+
entrypoint: gunicorn -b :$PORT main:app

tests/deploy_check/main.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
import logging
17+
18+
from flask import Flask
19+
20+
21+
app = Flask(__name__)
22+
23+
24+
@app.route('/')
25+
def hello():
26+
"""Return a friendly HTTP greeting."""
27+
return 'Hello World!'
28+
29+
30+
@app.errorhandler(500)
31+
def server_error(e):
32+
logging.exception('An error occurred during a request.')
33+
return """
34+
An internal error occurred: <pre>{}</pre>
35+
See logs for full stacktrace.
36+
""".format(e), 500
37+
38+
39+
if __name__ == '__main__':
40+
# This is used when running locally. Gunicorn is used to run the
41+
# application on Google App Engine. See entrypoint in app.yaml.
42+
app.run(host='127.0.0.1', port=8080, debug=True)
43+
# [END app]
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Flask==0.12.1
2+
gunicorn==19.7.1

0 commit comments

Comments
 (0)