Skip to content

Commit 4b2c061

Browse files
author
albertovara
committed
Updated docs
1 parent 6420f4d commit 4b2c061

File tree

5 files changed

+121
-8
lines changed

5 files changed

+121
-8
lines changed

docs/configuration.md

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,58 @@ or in a config.json:
3636
"APPLICATION_ROOT": ""
3737
}
3838
}
39-
```
39+
```
40+
41+
This file could contains this keywords:
42+
43+
44+
## pyms block
45+
46+
```pyms```: all subset inside this keywords is the configuration of this library. Each keyword will be a service of our
47+
[Microservice class](ms_class.md). For example, we declare our microservice class as:
48+
49+
```python
50+
from pyms.flask.app import Microservice
51+
ms = Microservice(service="my-ms", path=__file__)
52+
```
53+
and a `config.yaml` file:
54+
55+
```yaml
56+
pyms:
57+
requests: true
58+
```
59+
60+
our object `ms` has got a attribute `requests` that is a instance of our service [requests](services.md).
61+
62+
## Our microservice block
63+
This part contains all keywords of a [Flask Configuration Handling](http://flask.pocoo.org/docs/1.0/config/) and our
64+
constants of the enviroments (local configuration, staging configuration...). Take care that a Flask configuration needs
65+
the keywords are declared as upper case.
66+
67+
The name of this block is defined when you create the object of [Microservice class](ms_class.md). For example,
68+
69+
### Example 1
70+
```python
71+
from pyms.flask.app import Microservice
72+
ms = Microservice(service="my-personal-microservice", path=__file__)
73+
```
74+
and a `config.yaml` file:
75+
76+
```yaml
77+
my-personal-microservice:
78+
DEBUG: true
79+
TESTING: false
80+
```
81+
82+
### Example 2
83+
```python
84+
from pyms.flask.app import Microservice
85+
ms = Microservice(service="ms1-api", path=__file__)
86+
```
87+
and a `config.yaml` file:
88+
89+
```yaml
90+
ms1-api:
91+
DEBUG: true
92+
TESTING: false
93+
```

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ microservices with Python.
1212
* Structure of a microservice project
1313
* Swagger and connexion
1414
* Tracing requests
15-
* [Services of Py](structure.md)
15+
* [Services of PyMS](structure.md)

docs/ms_class.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,67 @@ And a config file like this config.yml
2929
my-minimal-microservice:
3030
APP_NAME: "Python Microservice"
3131
```
32+
See [Configuration](configuration.md) section to know how create a configuration file.
33+
34+
Each keyworkd in our configuration block, could be accessed in our Microservice object througth the attribute `config`.
35+
36+
```yaml
37+
# Config.yml
38+
example-config:
39+
APP_NAME: "Python Microservice"
40+
foo: "var"
41+
multiplevars:
42+
config1: "test1"
43+
config2: "test2"
44+
45+
```
46+
```python
47+
#app.py
48+
from pyms.flask.app import Microservice
49+
50+
ms = Microservice(service="example-config", path=__file__)
51+
print(ms.config.APP_NAME)
52+
# >> "Python Microservice"
53+
print(ms.config.foo)
54+
# >> "bar"
55+
print(ms.config.multiplevars.config1)
56+
# >> "test1"
57+
print(ms.config.multiplevars.config2)
58+
# >> "test2"
59+
```
60+
61+
62+
63+
# Looking for Configuration file
64+
By default, Microservice class search a config.yml in the same path. You can set a diferent route or set a json file.
65+
To change this path, define a environment variable `CONFIGMAP_FILE`.
66+
67+
This way of search the configuration is useful when you work with Docker and Kubernetes. For example, you can integrate
68+
a configmap of Kubernetes, with this microservice and a deployment with:
69+
70+
```yaml
71+
apiVersion: extensions/v1beta1
72+
kind: Deployment
73+
metadata:
74+
name: my-microservice
75+
spec:
76+
replicas: 1
77+
template:
78+
spec:
79+
containers:
80+
- name: my-microservice
81+
image: ...
82+
env:
83+
- name: CONFIGMAP_FILE
84+
value: "/usr/share/microservice/config.yaml"
85+
86+
volumeMounts:
87+
- mountPath: /usr/share/microservice
88+
name: ms-config-volume
89+
volumes:
90+
- name: ms-config-volume
91+
configMap:
92+
name: my-microservice-configmap
93+
```
3294

3395
See more examples in TODO: add link

docs/services.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Services
22

33
Services are libraries, resources and extensions added to the Microservice in the configuration file.
4-
This services are created as attribute of the [Microservice class](s_class.md) to use in the code.
4+
This services are created as attribute of the [Microservice class](ms_class.md) to use in the code.
55

66
To add a service see the [configuration section](configuration.md).
77

@@ -11,5 +11,5 @@ The actual services are:
1111
Extends the Microservice with [Connexion](https://github.com/zalando/connexion)
1212

1313
## Requests
14-
Extends the [requests library](http://docs.python-requests.org/en/master/) with trace headers
15-
and parsing JSON objects
14+
Extends the [requests library](http://docs.python-requests.org/en/master/) with trace headers and parsing JSON objects.
15+
Encapsulate common rest operations between business services propagating trace headers if configured.

docs/structure.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,5 @@ This views is usually used by Kubernetes, Eureka and other systems to check if o
1313
### pyms/logger
1414
Print logger in JSON format to send to server like Elasticsearch. Inject span traces in logger.
1515

16-
### pyms/rest_template
17-
Encapsulate common rest operations between business services propagating trace headers if configured.
18-
1916
### pyms/tracer
2017
Create an injector `flask_opentracing.FlaskTracer` to use in our projects

0 commit comments

Comments
 (0)