Skip to content

Commit 6258e6d

Browse files
committed
Updated docs and tests
1 parent b38d49e commit 6258e6d

File tree

11 files changed

+193
-13
lines changed

11 files changed

+193
-13
lines changed

.travis.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,23 @@ sudo: false
33
cache: false
44
python:
55
- '3.6'
6+
addons:
7+
apt:
8+
sources:
9+
- deadsnakes
10+
packages:
11+
- python3.5
12+
- python3.5-dev
613
install:
7-
- pip install -r requirements-tests.txt
14+
- pip install -U tox coveralls
815

916
script:
1017
- coverage erase
11-
- coverage run -m unittest
18+
- tox
1219
after_success:
1320
- coverage combine
1421
- coveralls
1522

1623
notifications:
1724
email:
18-
- a.vara.1986@gmail.com
25+
- a.vara.1986@gmail.com

app.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from flask import Flask
2+
3+
app = Flask(__name__)
4+
5+
6+
@app.route('/')
7+
def pull_requests():
8+
return 'Hello world'

docs/configuration.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
Configuration
22
=============
33

4+
The project is configured in `project/config.py`. You must set the project name `APP_NAME` and the path prefix
5+
of the project `APPLICATION_ROOT`. This constants is defined in the class Config:
46

7+
.. code-block:: python
58
9+
class Config:
10+
DEBUG = False
11+
TESTING = False
12+
APP_NAME = "Template"
13+
APPLICATION_ROOT = "/template"
14+
15+
Documentation
16+
-------------
17+
The Microservice create a URL to inspect the Swagger documentation of the api in:
18+
19+
.. code-block:: bash
20+
localhost:5000/[APPLICATION_ROOT]/apidocs/
21+
22+
Our API Rest work with `Flasgger <https://github.com/rochacbruno/flasgger>`_. You can see Flasgger docs or the official
23+
`Swagger documentation <https://swagger.io/specification/>`_ to add the syntax to your APIS and create your Swagger docs

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ Content
2424
structure
2525
configuration
2626
codeexample
27+
project

docs/installation.rst

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,74 @@
11
Installation
22
============
33

4+
Clone the project
5+
6+
.. code-block:: bash
7+
git clone https://github.com/python-microservices/microservices-scaffold.git
8+
9+
Configure your project and the path of your MS. See :doc:`configuration </configuration>` section.
10+
11+
Configure your setup.py with your project information
12+
13+
14+
15+
Use MS with Docker
16+
------------------
17+
`Install docker <https://docs.docker.com/install/>`_
18+
19+
20+
Use MS with Kubernetes localy
21+
-----------------------------
22+
Configure your service.yaml (TODO: create docs to configure kubernetes service.yaml)
23+
24+
* Installing Kubernetes...
25+
26+
.. code-block:: bash
27+
28+
curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/v1.9.0/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/
29+
30+
* Installing Minikube...
31+
32+
.. code-block:: bash
33+
34+
curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/
35+
36+
37+
Start minikube and set the environment of docker
38+
39+
.. code-block:: bash
40+
41+
minikube start
42+
eval $(minikube docker-env)
43+
kubectl config use-context minikube
44+
45+
If a shell isn't your friend. You could use kubernetes web panel to see your pods:
46+
47+
.. code-block:: bash
48+
49+
minikube dashboard
50+
51+
Create your image
52+
53+
.. code-block:: bash
54+
55+
docker build -t your-app:v1 .
56+
57+
Deploy your images localy:
58+
59+
.. code-block:: bash
60+
61+
kubectl create -f service.yaml
62+
minikube service your-app
63+
64+
65+
Clean your environment
66+
67+
.. code-block:: bash
68+
69+
kubectl delete service your-app
70+
kubectl delete deployment your-app
71+
docker rmi your-app:v1 -f
72+
minikube stop
73+
eval $(minikube docker-env -u)
74+
minikube delete

docs/project.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Project
2+
=======
3+
4+
.. automodule:: project
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
8+

docs/quickstart.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
Quickstart
22
==========
33

4-
4+
.. code-block:: bash
5+
git clone https://github.com/python-microservices/microservices-scaffold.git
6+
cd microservices-scaffold
7+
python manage.py runserver

docs/structure.rst

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,40 @@ You have a project with this structure:
1111
├ config.py
1212
├ views
1313
│ ├ __init__.py
14-
│ └ views.py
14+
│ ├ views.py
15+
│ └ healthcheck.py
1516
├ models
1617
│ ├ __init__.py
1718
│ └ models.py
18-
└ models
19-
└ test_views.py
19+
└ tests
20+
└ test_views.py
21+
22+
manager.py
23+
----------
24+
25+
A Django style command line. Use this to start the application like:
26+
27+
.. code-block:: bash
28+
python manage.py runserver
29+
30+
You can set the host and the port with:
31+
32+
.. code-block:: bash
33+
python manage.py runserver -h 0.0.0.0 -p 8080
34+
35+
project/__init__.py
36+
-------------------
37+
This file init the project with the funcion `create_app`. Initialize the Flask app, register `blueprints <http://flask.pocoo.org/docs/0.12/blueprints/>`_
38+
and intialize all libraries like Swagger, database, the trace system...
39+
40+
project/config.py
41+
-----------------
42+
See :doc:`configuration </configuration>` section
43+
44+
project/views
45+
-------------
46+
use views.py or create your file. You must add after register the view blueprint in `project/views/__init__.py`.
47+
48+
project/views/healthcheck.py
49+
----------------------------
50+
This views is usually used by Kubernetes, Eureka and other systems to check if our application is up and running

project/__init__.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,23 @@
4848

4949

5050
def init_jaeger_tracer(service_name='your-app-name'):
51+
"""This scaffold is configured whith `Jeager <https://github.com/jaegertracing/jaeger>`_ but you can use
52+
one of the `opentracing tracers <http://opentracing.io/documentation/pages/supported-tracers.html>`_
53+
:param service_name: the name of your application to register in the tracer
54+
:return: opentracing.Tracer
55+
"""
5156
config = Config(config={
5257
'sampler': {'type': 'const', 'param': 1}
5358
}, service_name=service_name)
5459
return config.initialize_tracer()
5560

5661

5762
class PrefixMiddleware(object):
58-
63+
"""Set a prefix path to all routes. This action is needed if you have a stack of microservices and each of them
64+
exist in the same domain but different path. Por example:
65+
* mydomain.com/ms1/
66+
* mydomain.com/ms2/
67+
"""
5968
def __init__(self, app, prefix=''):
6069
self.app = app
6170
self.prefix = prefix
@@ -73,6 +82,10 @@ def __call__(self, environ, start_response):
7382

7483

7584
def create_app():
85+
"""Initialize the Flask app, register blueprints and intialize all libraries like Swagger, database, the trace system...
86+
return the app and the database objects.
87+
:return:
88+
"""
7689
from project.models import db
7790
from project.views import views_bp as views_blueprint
7891
from project.views import views_hc as views_hc_blueprint
@@ -87,6 +100,7 @@ def create_app():
87100

88101
db.init_app(app)
89102

103+
# Initialize Swagger
90104
SWAGGER_CONFIG["specs"][0]["route"] = SWAGGER_CONFIG["specs"][0]["route"].format(
91105
application_root=app.config["APPLICATION_ROOT"]
92106
)
@@ -101,6 +115,7 @@ def create_app():
101115
)
102116
Swagger(app, config=SWAGGER_CONFIG)
103117

118+
# Initialize Blueprints
104119
app.register_blueprint(views_blueprint)
105120
app.register_blueprint(views_hc_blueprint)
106121
with app.test_request_context():

tests.sh

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
#!/bin/sh
2-
pip install -r requirements-tests.txt
32
coverage erase
4-
coverage run -m unittest
3+
tox
54
coverage combine
65
coverage report -m
7-
coverage xml -i
8-
coverage html -i
9-
# --rcfile=pylintrc
6+
coverage html
107
pylint project/* > pylintReport.txt

0 commit comments

Comments
 (0)