Skip to content

Commit 03bb343

Browse files
author
will
committed
feat: add service-python code and Dockerfile
1 parent 903c55f commit 03bb343

9 files changed

Lines changed: 414 additions & 0 deletions

File tree

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
# Created by https://www.gitignore.io/api/visualstudiocode
3+
# Edit at https://www.gitignore.io/?templates=visualstudiocode
4+
5+
### VisualStudioCode ###
6+
.vscode/*
7+
8+
### VisualStudioCode Patch ###
9+
# Ignore all local history of files
10+
.history
11+
12+
# End of https://www.gitignore.io/api/visualstudiocode

service/python/v1/.gitignore

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# Created by https://www.gitignore.io/api/python
2+
# Edit at https://www.gitignore.io/?templates=python
3+
4+
### Python ###
5+
# Byte-compiled / optimized / DLL files
6+
__pycache__/
7+
*.py[cod]
8+
*$py.class
9+
10+
# C extensions
11+
*.so
12+
13+
# Distribution / packaging
14+
.Python
15+
build/
16+
develop-eggs/
17+
dist/
18+
downloads/
19+
eggs/
20+
.eggs/
21+
lib/
22+
lib64/
23+
parts/
24+
sdist/
25+
var/
26+
wheels/
27+
*.egg-info/
28+
.installed.cfg
29+
*.egg
30+
MANIFEST
31+
32+
# PyInstaller
33+
# Usually these files are written by a python script from a template
34+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
35+
*.manifest
36+
*.spec
37+
38+
# Installer logs
39+
pip-log.txt
40+
pip-delete-this-directory.txt
41+
42+
# Unit test / coverage reports
43+
htmlcov/
44+
.tox/
45+
.nox/
46+
.coverage
47+
.coverage.*
48+
.cache
49+
nosetests.xml
50+
coverage.xml
51+
*.cover
52+
.hypothesis/
53+
.pytest_cache/
54+
55+
# Translations
56+
*.mo
57+
*.pot
58+
59+
# Django stuff:
60+
*.log
61+
local_settings.py
62+
db.sqlite3
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
target/
76+
77+
# Jupyter Notebook
78+
.ipynb_checkpoints
79+
80+
# IPython
81+
profile_default/
82+
ipython_config.py
83+
84+
# pyenv
85+
.python-version
86+
87+
# celery beat schedule file
88+
celerybeat-schedule
89+
90+
# SageMath parsed files
91+
*.sage.py
92+
93+
# Environments
94+
.env
95+
.venv
96+
env/
97+
venv/
98+
ENV/
99+
env.bak/
100+
venv.bak/
101+
102+
# Spyder project settings
103+
.spyderproject
104+
.spyproject
105+
106+
# Rope project settings
107+
.ropeproject
108+
109+
# mkdocs documentation
110+
/site
111+
112+
# mypy
113+
.mypy_cache/
114+
.dmypy.json
115+
dmypy.json
116+
117+
# Pyre type checker
118+
.pyre/
119+
120+
### Python Patch ###
121+
.venv/
122+
123+
### Python.VirtualEnv Stack ###
124+
# Virtualenv
125+
# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/
126+
[Bb]in
127+
[Ii]nclude
128+
[Ll]ib
129+
[Ll]ib64
130+
[Ll]ocal
131+
[Ss]cripts
132+
pyvenv.cfg
133+
pip-selfcheck.json
134+
135+
# End of https://www.gitignore.io/api/python

service/python/v1/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM python:2-alpine
2+
LABEL maintainer="will835559313@163.com"
3+
COPY . /app
4+
WORKDIR /app
5+
RUN pip install -r requirements.txt
6+
CMD [ "python", "main.py" ]

service/python/v1/main.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
from flask import Flask, jsonify, g, request
2+
import platform
3+
import requests
4+
import logging
5+
6+
app = Flask(__name__)
7+
logging.basicConfig(level=logging.DEBUG)
8+
9+
10+
def getForwardHeaders(request):
11+
headers = {}
12+
incoming_headers = [
13+
'x-request-id',
14+
'x-b3-traceid',
15+
'x-b3-spanid',
16+
'x-b3-parentspanid',
17+
'x-b3-sampled',
18+
'x-b3-flags',
19+
'x-ot-span-context'
20+
]
21+
22+
for ihdr in incoming_headers:
23+
val = request.headers.get(ihdr)
24+
if val is not None:
25+
headers[ihdr] = val
26+
# print("incoming: "+ihdr+":"+val)
27+
28+
return headers
29+
30+
31+
@app.before_request
32+
def before_request():
33+
g.forwardHeaders = getForwardHeaders(request)
34+
35+
36+
@app.route("/env")
37+
def env():
38+
service_lua_url = 'http://' + 'service-lua' + '/env'
39+
resp = requests.get(service_lua_url, headers=g.forwardHeaders)
40+
data_lua = resp.json()
41+
42+
service_node_url = 'http://' + 'service-node' + '/env'
43+
resp = requests.get(service_node_url, headers=g.forwardHeaders)
44+
data_node = resp.json()
45+
46+
return jsonify({
47+
"message": 'Python' + platform.python_version(),
48+
"upstream": [data_lua, data_node]
49+
})
50+
51+
52+
@app.route("/status")
53+
def status():
54+
return "ok"
55+
56+
57+
if __name__ == '__main__':
58+
app.run(host='0.0.0.0', port=80)

service/python/v1/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
flask
2+
requests

service/python/v2/.gitignore

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# Created by https://www.gitignore.io/api/python
2+
# Edit at https://www.gitignore.io/?templates=python
3+
4+
### Python ###
5+
# Byte-compiled / optimized / DLL files
6+
__pycache__/
7+
*.py[cod]
8+
*$py.class
9+
10+
# C extensions
11+
*.so
12+
13+
# Distribution / packaging
14+
.Python
15+
build/
16+
develop-eggs/
17+
dist/
18+
downloads/
19+
eggs/
20+
.eggs/
21+
lib/
22+
lib64/
23+
parts/
24+
sdist/
25+
var/
26+
wheels/
27+
*.egg-info/
28+
.installed.cfg
29+
*.egg
30+
MANIFEST
31+
32+
# PyInstaller
33+
# Usually these files are written by a python script from a template
34+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
35+
*.manifest
36+
*.spec
37+
38+
# Installer logs
39+
pip-log.txt
40+
pip-delete-this-directory.txt
41+
42+
# Unit test / coverage reports
43+
htmlcov/
44+
.tox/
45+
.nox/
46+
.coverage
47+
.coverage.*
48+
.cache
49+
nosetests.xml
50+
coverage.xml
51+
*.cover
52+
.hypothesis/
53+
.pytest_cache/
54+
55+
# Translations
56+
*.mo
57+
*.pot
58+
59+
# Django stuff:
60+
*.log
61+
local_settings.py
62+
db.sqlite3
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
target/
76+
77+
# Jupyter Notebook
78+
.ipynb_checkpoints
79+
80+
# IPython
81+
profile_default/
82+
ipython_config.py
83+
84+
# pyenv
85+
.python-version
86+
87+
# celery beat schedule file
88+
celerybeat-schedule
89+
90+
# SageMath parsed files
91+
*.sage.py
92+
93+
# Environments
94+
.env
95+
.venv
96+
env/
97+
venv/
98+
ENV/
99+
env.bak/
100+
venv.bak/
101+
102+
# Spyder project settings
103+
.spyderproject
104+
.spyproject
105+
106+
# Rope project settings
107+
.ropeproject
108+
109+
# mkdocs documentation
110+
/site
111+
112+
# mypy
113+
.mypy_cache/
114+
.dmypy.json
115+
dmypy.json
116+
117+
# Pyre type checker
118+
.pyre/
119+
120+
### Python Patch ###
121+
.venv/
122+
123+
### Python.VirtualEnv Stack ###
124+
# Virtualenv
125+
# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/
126+
[Bb]in
127+
[Ii]nclude
128+
[Ll]ib
129+
[Ll]ib64
130+
[Ll]ocal
131+
[Ss]cripts
132+
pyvenv.cfg
133+
pip-selfcheck.json
134+
135+
# End of https://www.gitignore.io/api/python

service/python/v2/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM python:3-alpine
2+
LABEL maintainer="will835559313@163.com"
3+
COPY . /app
4+
WORKDIR /app
5+
RUN pip install -r requirements.txt
6+
CMD [ "python", "main.py" ]

0 commit comments

Comments
 (0)