Skip to content

Commit 0710acd

Browse files
committed
Updated docs
1 parent 2f4a836 commit 0710acd

File tree

6 files changed

+129
-40
lines changed

6 files changed

+129
-40
lines changed

docs/configuration.md

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Configuration
22

3+
## Environments variables of PyMS:
4+
5+
**CONFIGMAP_FILE**: The path to the configuration file. By default, PyMS search the configuration file in your
6+
actual folder with the name "config.yml"
7+
**CONFIGMAP_SERVICE**: the name of the keyword that define the block of key-value of [Flask Configuration Handling](http://flask.pocoo.org/docs/1.0/config/)
8+
and your own configuration (see the next section to more info)
9+
310
## Create configuration
411
Each microservice needs a config file in yaml or json format to work with it. This configuration contains
512
the Flask settings of your project and the [Services](services.md). With this way to create configuration files, we
@@ -44,7 +51,6 @@ or in a config.json:
4451

4552
This file could contains this keywords:
4653

47-
4854
## pyms block
4955

5056
```pyms```: all subsets inside this keyword are the settings of this library. Each keyword will be a service of our
@@ -96,6 +102,8 @@ ms1-api:
96102
TESTING: false
97103
```
98104

105+
You can set this keyword with the environment var **CONFIGMAP_SERVICE**.
106+
99107
## Import Configuration
100108
With pyms, all configuration is stored as flask configuration and it can be acceded from:
101109

@@ -142,4 +150,37 @@ API = Api(
142150
```
143151

144152
**IMPORTANT:** If you use this method to get configuration out of context, you must set the `CONFIGMAP_SERVICE` or set
145-
the default key `ms` for your configuration block in your config.yml
153+
the default key `ms` for your configuration block in your config.yml
154+
155+
156+
## Looking for Configuration file with Kubernetes Configmaps
157+
By default, Microservice class search a config.yml in the same path. You can set a different route or set a json file.
158+
To change this path, define a environment variable `CONFIGMAP_FILE`.
159+
160+
This way of looking for the configuration is useful when you work with Docker and Kubernetes. For example, you can integrate
161+
a configmap of Kubernetes, with this microservice and a deployment with:
162+
163+
```yaml
164+
apiVersion: extensions/v1beta1
165+
kind: Deployment
166+
metadata:
167+
name: my-microservice
168+
spec:
169+
replicas: 1
170+
template:
171+
spec:
172+
containers:
173+
- name: my-microservice
174+
image: ...
175+
env:
176+
- name: CONFIGMAP_FILE
177+
value: "/usr/share/microservice/config.yaml"
178+
179+
volumeMounts:
180+
- mountPath: /usr/share/microservice
181+
name: ms-config-volume
182+
volumes:
183+
- name: ms-config-volume
184+
configMap:
185+
name: my-microservice-configmap
186+
```

docs/index.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
# Welcome to PyMS
22

3-
PyMS, Python MicroService, is a collection of libraries, best practices and recommended ways to build
4-
microservices with Python.
3+
PyMS, Python MicroService, is a [Microservice chassis pattern](https://microservices.io/patterns/microservice-chassis.html)
4+
like Spring Boot (Java) or Gizmo (Golang). PyMS is a collection of libraries, best practices and recommended ways to build
5+
microservices with Python which handles cross-cutting concerns:
6+
- Externalized configuration
7+
- Logging
8+
- Health checks
9+
- Metrics (TODO)
10+
- Distributed tracing
11+
12+
PyMS is powered by [Flask](https://flask.palletsprojects.com/en/1.1.x/), [Connexion](https://github.com/zalando/connexion) and [Opentracing](https://opentracing.io/).
13+
14+
Get started with [Installation](installation.md) and then get an overview with the [Quickstart](quickstart.md).
515

616
## Motivation
717

@@ -24,9 +34,11 @@ Nowadays, is not perfect and we have a looong roadmap, but we hope this library
2434

2535

2636
## Index:
27-
* [PyMS structure](structure.md)
37+
* [Installation](installation.md)
38+
* [Quickstart](quickstart.md)
2839
* [Configuration](configuration.md)
2940
* [Services](services.md)
41+
* [PyMS structure](structure.md)
3042
* [Microservice class](ms_class.md)
3143
* [Quick start and examples](examples.md)
3244
* [Structure of a microservice project](structure_project.md)

docs/installation.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Installation
2+
3+
## Python Version
4+
We recommend using the latest version of Python 3. PyMS supports Python 3.6 and newer and PyPy.
5+
6+
```
7+
virtualenv --python=python[3.6|3.7|3.8] venv
8+
source venv/bin/activate
9+
```
10+
11+
## Install PyMS
12+
13+
```
14+
pip install py-ms
15+
```
16+
17+
See [Quickstart](quickstart.md) to continue with this tutorial

docs/ms_class.md

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -58,38 +58,4 @@ print(ms.config.multiplevars.config2)
5858
# >> "test2"
5959
```
6060

61-
62-
63-
# Looking for Configuration file
64-
By default, Microservice class search a config.yml in the same path. You can set a different route or set a json file.
65-
To change this path, define a environment variable `CONFIGMAP_FILE`.
66-
67-
This way of looking for 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-
```
94-
9561
Check more examples in [this Github page](https://github.com/python-microservices/pyms/tree/master/examples)

docs/quickstart.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Quickstart
2+
3+
This page gives a good introduction to PyMS. It assumes you already have PyMS installed. If you do not, head over to the [Installation](installation.md) section.
4+
5+
You need to create 2 files: main.py and config.yml:
6+
7+
main.py
8+
```python
9+
from flask import jsonify
10+
11+
from pyms.flask.app import Microservice
12+
13+
ms = Microservice(path=__file__) # 1.1
14+
app = ms.create_app() # 2.1
15+
16+
17+
@app.route("/") # 3.1
18+
def example():
19+
return jsonify({"main": "hello world"})
20+
21+
22+
if __name__ == '__main__':
23+
app.run()
24+
```
25+
26+
config.yml
27+
```yaml
28+
pyms: # 1.2
29+
requests:
30+
data: {}
31+
ms: # 1.3
32+
DEBUG: true
33+
APP_NAME: business-glossary
34+
APPLICATION_ROOT : ""
35+
SECRET_KEY: "gjr39dkjn344_!67#"
36+
```
37+
38+
So what did that code do?
39+
1. Create a instance of PyMS Microservice class (#1.1). This initialization inject the configuration defined in the
40+
1.3 block and could be accessed through current_app.config. Then, initialize the service defined in the 1.2 block. See [Services](services.md) for more details.
41+
2. Initialize [Flask](https://flask.palletsprojects.com/en/1.1.x/) instance, [Connexion](https://github.com/zalando/connexion)
42+
if it was defined in the pyms configuration block, create a tracer, add health-check blueprint, initialize libs and set the PyMS Microservice in
43+
`ms` attribute and you can access to it with `current_app.ms`. This steps has their each functions and you can easy override it.
44+
3. `create_app` return the flask instance and you can interact with it as a typical flask app
45+
46+
47+
48+
See [Configuration](configuration.md) and [Examples](examples.md) to continue with this tutorial
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
my-minimal-microservice:
2-
APP_NAME: "Python Microservice"
2+
DEBUG: true
3+
TESTING: false
4+
SWAGGER: true
5+
APP_NAME: business-glossary
6+
APPLICATION_ROOT : ""
7+
SECRET_KEY: "gjr39dkjn344_!67#"

0 commit comments

Comments
 (0)