Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.

Commit f0ccbc5

Browse files
committed
Add a Python HTTP example.
1 parent ffb2031 commit f0ccbc5

File tree

6 files changed

+100
-2
lines changed

6 files changed

+100
-2
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,4 @@ script:
5555
# Second, HTTP.
5656
- ./examples/hellohttp/e2e-test.sh java
5757
- ./examples/hellohttp/e2e-test.sh go
58+
- ./examples/hellohttp/e2e-test.sh py

WORKSPACE

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,24 @@ pip_import(
148148
requirements = "//examples/hellogrpc/py:requirements.txt",
149149
)
150150

151-
load("@examples_helloworld_pip//:requirements.bzl", "pip_install")
151+
load(
152+
"@examples_helloworld_pip//:requirements.bzl",
153+
grpcpip_install = "pip_install",
154+
)
155+
156+
grpcpip_install()
157+
158+
pip_import(
159+
name = "examples_hellohttp_pip",
160+
requirements = "//examples/hellohttp/py:requirements.txt",
161+
)
162+
163+
load(
164+
"@examples_hellohttp_pip//:requirements.bzl",
165+
httppip_install = "pip_install",
166+
)
152167

153-
pip_install()
168+
httppip_install()
154169

155170
# We use py_image to build a sample service
156171
load(

examples/hellohttp/py/BUILD

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright 2017 The Bazel Authors. 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+
package(default_visibility = ["//visibility:public"])
15+
16+
licenses(["notice"]) # Apache 2.0
17+
18+
load("@examples_hellohttp_pip//:requirements.bzl", "all_requirements")
19+
load("@io_bazel_rules_docker//python:image.bzl", "py_image")
20+
21+
py_image(
22+
name = "server",
23+
srcs = ["server.py"],
24+
main = "server.py",
25+
deps = all_requirements,
26+
)
27+
28+
load("@k8s_deploy//:defaults.bzl", "k8s_deploy")
29+
30+
k8s_deploy(
31+
name = "staging",
32+
images = {
33+
"us.gcr.io/not-my-project/hello-http:staging": ":server",
34+
},
35+
template = "//examples/hellohttp:deployment.yaml",
36+
)

examples/hellohttp/py/edit.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash -e
2+
3+
# Copyright 2017 The Bazel Authors. All rights reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
SUFFIX="$1"
18+
19+
sed -i "s/DEMO *[a-z0-9_-]* */DEMO${SUFFIX} /g" ./examples/hellohttp/py/server.py
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Flask==0.12.2
2+
gunicorn==19.4.5

examples/hellohttp/py/server.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright 2017 The Bazel Authors. 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+
"""Demo HTTP application."""
15+
16+
from flask import Flask
17+
18+
app = Flask(__name__)
19+
20+
@app.route('/')
21+
def get():
22+
return 'DEMO '
23+
24+
if __name__ == '__main__':
25+
app.run(host='0.0.0.0', port=8080, debug=True)

0 commit comments

Comments
 (0)