Skip to content

Commit 8090d33

Browse files
committed
docs: TT-301 Improve README documentation
1 parent f75ba5d commit 8090d33

File tree

2 files changed

+226
-48
lines changed

2 files changed

+226
-48
lines changed

README.md

Lines changed: 224 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,60 @@ This is the mono-repository for the backend services and their common codebase
66

77
## Getting started
88

9-
Follow the following instructions to get the project ready to use ASAP.
9+
Follow the next instructions to get the project ready to use ASAP.
1010

11-
### Requirements
11+
Currently, there are two ways to run the project, the production mode using a virtual environment and installing all the necessary libraries
12+
there and the other way is using the development mode with Docker and docker-compose. It is recommended to use the development mode and in special cases the production mode.
1213

13-
Be sure you have installed in your system:
14+
## Requirements:
15+
16+
For both modes it is necessary to have the following requirements installed:
1417

1518
- [Python version 3](https://www.python.org/download/releases/3.0/) (recommended 3.8 or less) in your path. It will install
1619
automatically [pip](https://pip.pypa.io/en/stable/) as well.
1720
- A virtual environment, namely [.venv](https://docs.python.org/3/library/venv.html).
1821
- Optionally for running Azure functions locally: [Azure functions core tool](https://docs.microsoft.com/en-us/azure/azure-functions/functions-run-local?tabs=macos%2Ccsharp%2Cbash).
1922

23+
## Settings for each mode
24+
25+
Before proceeding to the configuration for each of the modes,
26+
it is important to perform the following step regardless of the mode to be used.
27+
28+
### Create a virtual environment
29+
30+
Execute the next command at the root of the project:
31+
32+
```shell
33+
python -m venv .venv
34+
```
35+
36+
> **Note:** We can replace python for python3 or python3.8 according to the version you have installed,
37+
> but do not forget the initial requirements.
38+
39+
**Activate the environment**
40+
41+
Windows:
42+
```shell
43+
.venv\Scripts\activate.bat
44+
```
45+
46+
In Unix based operative systems:
47+
48+
```shell
49+
source .venv/bin/activate
50+
```
51+
52+
### Setup for each mode
53+
54+
The configuration required for each of the modes is as follows:
55+
56+
<details>
57+
<summary><b>Development Mode</b></summary>
58+
59+
### Requirements:
60+
61+
In addition to the initial requirements, it is necessary to have the following requirements installed:
62+
2063
- Docker
2164

2265
You can follow the instructions below to install on each of the following operating systems:
@@ -28,7 +71,7 @@ Be sure you have installed in your system:
2871

2972
To install Docker Compose, please choose the operating system you use and follow the steps [here](https://docs.docker.com/compose/install/).
3073

31-
### Setup
74+
### Setup
3275

3376
Once installed Docker and Docker Compose we must create a `.env` file in the root of our project where we will put the following environment variables.
3477

@@ -56,7 +99,7 @@ Once all the project configuration is done, we are going to execute the followin
5699
docker-compose up --build
57100
```
58101

59-
This command will build all images with the necessary configurations for each one, aslo
102+
This command will build all images with the necessary configurations for each one, also
60103
raises the cosmos emulator in combination with the backend, now you can open in the browser:
61104

62105
- `http://127.0.0.1:5000/` open backend API.
@@ -66,126 +109,259 @@ raises the cosmos emulator in combination with the backend, now you can open in
66109
> it is not necessary to execute it again, instead it should be executed like this:
67110
> `docker-compose up`
68111
69-
> It is also important to clarify that if packages or any extra configuration is added to the images construction,
112+
> It is also important to clarify that if packages or any extra configuration is added to the image's construction,
70113
> you need to run again `docker-compose up --build`, you can see more information about this flag [here](https://docs.docker.com/compose/reference/up/)
71114
72-
## Development
115+
### Development
73116

74-
### Generate Fake Data
117+
#### Generate Fake Data
75118

76119
In order to generate fake data to test functionalities or correct errors,
77120
we have built a CLI, called 'Time Tracker CLI', which is in charge of generating
78121
the fake information inside the Cosmos emulator.
79122

80123
To learn how this CLI works, you can see the instructions [here](https://github.com/ioet/time-tracker-backend/tree/master/cosmosdb_emulator)
81124

82-
### Git hooks
125+
> It is important to clarify that Time Tracker CLI only works in development mode.
83126
84-
We use [pre-commit](https://github.com/pre-commit/pre-commit) library to manage local git hooks,
85-
as developers we just need to run in our virtual environment.
127+
### Test
86128

87-
This library allows you to execute code right before the commit, for example:
88-
- Check if the commit contains the correct formatting.
89-
- Format modified files based on a Style Guide such as PEP 8, etc.
129+
We are using [Pytest](https://docs.pytest.org/en/latest/index.html) for tests. The tests are located in the package
130+
`tests` and use the [conventions for python test discovery](https://docs.pytest.org/en/latest/goodpractices.html#test-discovery).
90131

91-
To install and use `pre-commit` we have to perform the following steps:
132+
> Remember to run any available test command we have to have the containers up (`docker-compose up`).
92133
93-
**Create the environment**
134+
This command run all tests:
94135

95-
Execute the next command at the root of the project:
136+
```shell
137+
./time-tracker.sh pytest -v
138+
```
139+
140+
Run a single test:
96141

97142
```shell
98-
python -m venv .venv
143+
./time-tracker.sh pytest -v -k name-test
99144
```
100145

101-
> **Note:** We can replace python for python3 or python3.8 according to the version you have installed,
102-
> but do not forget the initial requirements.
146+
#### Coverage
103147

104-
**Activate the environment**
148+
To check the coverage of the tests execute:
105149

106-
Windows:
107150
```shell
108-
.venv\Scripts\activate.bat
151+
./time-tracker.sh coverage run -m pytest -v
109152
```
110153

111-
In Unix based operative systems:
154+
To get a report table:
112155

113156
```shell
114-
source .venv/bin/activate
157+
./time-tracker.sh coverage report
115158
```
116159

117-
Once the environment has been created and activated we have to run:
160+
To get a full report in html:
161+
118162
```shell
119-
python3 -m pip install pre-commit
163+
./time-tracker.sh coverage html
120164
```
165+
Then check in the [htmlcov/index.html](./htmlcov/index.html) to see it.
121166

122-
Once `pre-commit` library is installed, we are going to execute the following command:
167+
If you want that previously collected coverage data is erased, you can execute:
123168

124169
```shell
125-
pre-commit install -t pre-commit -t commit-msg
170+
./time-tracker.sh coverage erase
126171
```
127-
For more details, see section Development > Git hooks.
128172

129-
With this command the library will take configuration from `.pre-commit-config.yaml` and will set up the hooks by us.
173+
</details>
130174

131-
### Commit message style
175+
<hr>
132176

133-
Use the following commit message style. e.g:
177+
<details>
178+
<summary><b>Production Mode</b></summary>
134179

135-
```shell
136-
'feat: TT-123 Applying some changes'
137-
'fix: TT-321 Fixing something broken'
138-
'feat(config): TT-00 Fix something in config files'
180+
### Setup
181+
182+
#### Install the requirements:
183+
184+
```
185+
python3 -m pip install -r requirements/<app>/<stage>.txt
139186
```
140187

141-
The value `TT-###` refers to the Jira issue that is being solved. Use TT-00 if the commit does not refer to any issue.
188+
If you use Windows, you will use this command:
142189

143-
### Branch names format
190+
```
191+
python -m pip install -r requirements/<app>/<stage>.txt
192+
```
144193

145-
For example if your task in Jira is **TT-48 implement semantic versioning** your branch name is:
194+
Where `<app>` is one of the executable app namespace, e.g. `time_tracker_api` or `time_tracker_events` (**Note:** Currently, only `time_tracker_api` is used.). The `stage` can be
195+
196+
- `dev`: Used for working locally
197+
- `prod`: For anything deployed
198+
199+
Bear in mind that the requirements for `time_tracker_events`, must be located on its local requirements.txt, by
200+
[convention](https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-python#folder-structure).
201+
202+
### Set environment variables
203+
204+
When you use Bash or GitBash you should create a .env file and add the next variables:
205+
206+
```
207+
export MS_AUTHORITY=XXX
208+
export MS_CLIENT_ID=XXX
209+
export MS_SCOPE=XXX
210+
export MS_SECRET=XXX
211+
export MS_ENDPOINT=XXX
212+
export DATABASE_ACCOUNT_URI=XXX
213+
export DATABASE_MASTER_KEY=XXX
214+
export DATABASE_NAME=XXX
215+
export FLASK_APP=XXX
216+
export AZURE_APP_CONFIGURATION_CONNECTION_STRING=XXX
217+
export FLASK_DEBUG=True
218+
```
219+
220+
If you use PowerShell, you should create a .env.bat file and add the next variables:
221+
222+
```
223+
$env:MS_AUTHORITY="XXX"
224+
$env:MS_CLIENT_ID="XXX"
225+
$env:MS_SCOPE="XXX"
226+
$env:MS_SECRET="XXX"
227+
$env:MS_ENDPOINT="XXX"
228+
$env:DATABASE_ACCOUNT_URI="XXX"
229+
$env:DATABASE_MASTER_KEY="XXX"
230+
$env:DATABASE_NAME="XXX"
231+
$env:FLASK_APP="XXX"
232+
$env:AZURE_APP_CONFIGURATION_CONNECTION_STRING="XXX"
233+
$env:FLASK_DEBUG="True"
234+
```
235+
236+
If you use Command Prompt, you should create a .env.ps1 file and add the next variables:
237+
238+
```
239+
set "MS_AUTHORITY=XXX"
240+
set "MS_CLIENT_ID=XXX"
241+
set "MS_SCOPE=XXX"
242+
set "MS_SECRET=XXX"
243+
set "MS_ENDPOINT=XXX"
244+
set "DATABASE_ACCOUNT_URI=XXX"
245+
set "DATABASE_MASTER_KEY=XXX"
246+
set "DATABASE_NAME=XXX"
247+
set "FLASK_APP=XXX"
248+
set "AZURE_APP_CONFIGURATION_CONNECTION_STRING=XXX"
249+
set "FLASK_DEBUG=True"
250+
```
251+
252+
> **Important:** Ask the development team for the values of the environment variables, also
253+
> you should set the environment variables each time the application is run.
254+
255+
### Run application
256+
257+
- Start the app:
146258

147259
```shell
148-
TT-48-implement-semantic-versioning
260+
flask run
149261
```
150262

263+
- Open `http://127.0.0.1:5000/` in a browser. You will find in the presented UI
264+
a link to the swagger.json with the definition of the api.
265+
151266
### Test
152267

153268
We are using [Pytest](https://docs.pytest.org/en/latest/index.html) for tests. The tests are located in the package
154269
`tests` and use the [conventions for python test discovery](https://docs.pytest.org/en/latest/goodpractices.html#test-discovery).
155270

156-
> Remember To run any available test command we have to have the containers up (`docker-compose up`).
157-
158271
This command run all tests:
159272

160273
```shell
161-
./time-tracker.sh pytest -v
274+
pytest -v
275+
```
276+
277+
> **Note:** If you get the error "No module named azure.functions", execute the command `pip install azure-functions`:
278+
279+
To run a single test:
280+
281+
```shell
282+
pytest -v -k name-test
162283
```
163284

164285
#### Coverage
165286

166287
To check the coverage of the tests execute:
167288

168289
```shell
169-
./time-tracker.sh coverage run -m pytest -v
290+
coverage run -m pytest -v
170291
```
171292

172293
To get a report table:
173294

174295
```shell
175-
./time-tracker.sh coverage report
296+
coverage report
176297
```
177298

178299
To get a full report in html:
179300

180301
```shell
181-
./time-tracker.sh coverage html
302+
coverage html
182303
```
183304
Then check in the [htmlcov/index.html](./htmlcov/index.html) to see it.
184305

185306
If you want that previously collected coverage data is erased, you can execute:
186307

187308
```shell
188-
./time-tracker.sh coverage erase
309+
coverage erase
310+
```
311+
312+
</details>
313+
314+
<hr/>
315+
316+
### Git hooks
317+
We use [pre-commit](https://github.com/pre-commit/pre-commit) library to manage local git hooks,
318+
as developers we just need to run in our virtual environment.
319+
320+
<hr>
321+
<details>
322+
<summary><b>Open if you use Development mode</b></summary>
323+
324+
To install and use `pre-commit` in development mode we have to perform the next command:
325+
326+
```shell
327+
python3 -m pip install pre-commit
328+
```
329+
> Remember to execute this command with the virtual environment active.
330+
331+
Once `pre-commit` library is installed, we can continue with the guide
332+
</details>
333+
334+
<hr>
335+
This library allows you to execute code right before the commit, for example:
336+
- Check if the commit contains the correct formatting.
337+
- Format modified files based on a Style Guide such as PEP 8, etc.
338+
339+
As developers, we just need to run in our virtual environment:
340+
```shell
341+
pre-commit install -t pre-commit -t commit-msg
342+
```
343+
For more details, see section Development > Git hooks.
344+
345+
With this command the library will take configuration from `.pre-commit-config.yaml` and will set up the hooks by us.
346+
347+
### Commit message style
348+
349+
Use the following commit message style. e.g:
350+
351+
```shell
352+
'feat: TT-123 Applying some changes'
353+
'fix: TT-321 Fixing something broken'
354+
'feat(config): TT-00 Fix something in config files'
355+
```
356+
357+
The value `TT-###` refers to the Jira issue that is being solved. Use TT-00 if the commit does not refer to any issue.
358+
359+
### Branch names format
360+
361+
For example if your task in Jira is **TT-48 implement semantic versioning** your branch name is:
362+
363+
```shell
364+
TT-48-implement-semantic-versioning
189365
```
190366

191367
### Handling Cosmos DB triggers for creating events with time_tracker_events

cosmosdb_emulator/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Here you can find all the source code of the Time Tracker CLI.
44
This is responsible for automatically generating fake data for the Cosmos emulator,
55
in order to have information when testing new features or correcting bugs.
66

7+
> This feature is only available in development mode.
8+
79
## Prerequisites
810

911
- Backend and cosmos emulator containers up.

0 commit comments

Comments
 (0)