Skip to content

Commit 998de15

Browse files
authored
fix(doc): miscellaneous fixes for deployment docs (#463)
1 parent cf8ff62 commit 998de15

File tree

8 files changed

+123
-113
lines changed

8 files changed

+123
-113
lines changed

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ run:
4545
run-py:
4646
python boaviztapi/main.py
4747

48+
run-doc:
49+
cd docs && poetry run mkdocs serve
50+
4851
$(SEMVERS):
4952
poetry version $@
5053
$(MAKE) npm_version
@@ -72,3 +75,9 @@ docker-build-development:
7275

7376
docker-run-development:
7477
docker run -p 5000:5000 boavizta/boaviztapi:${TIMESTAMP}
78+
79+
compose-build:
80+
docker compose build
81+
82+
compose-up:
83+
docker compose up --build

README.md

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,6 @@ $ docker run -p 5000:5000 ghcr.io/boavizta/boaviztapi:latest
4646

4747
Access the API at http://localhost:5000.
4848

49-
### Install using pip package
50-
51-
```bash
52-
$ pip3 install boaviztapi
53-
```
54-
55-
Run the server locally with:
56-
57-
```bash
58-
$ uvicorn boaviztapi.main:app --host=localhost --port 5000
59-
```
60-
6149
## :computer: Development
6250

6351
### Prerequisite
@@ -97,34 +85,16 @@ You can run the tests with `pytest` via:
9785

9886
### Create your own docker image and run it
9987

100-
Build application package:
101-
102-
```sh
103-
make install
104-
```
105-
10688
Build Docker image:
10789

10890
```sh
109-
# using the makefile (recommended)
110-
make docker-build
111-
112-
# manual build (requires to set version)
113-
docker build .
114-
```
115-
116-
Run Docker image:
117-
118-
```sh
119-
docker run -p 5000:5000/tcp boavizta/boaviztapi:`poetry version -s`
120-
```
121-
122-
#### Alternative (if you don't have Python or Poetry)
123-
124-
```sh
91+
# Using the makefile (recommended)
12592
make docker-build-development
126-
12793
make docker-run-development
94+
95+
# Manual build
96+
docker build . -t boavizta-test
97+
docker run -p 5000:5000 boavizta-test
12898
```
12999

130100
### Deploy to AWS as serverless application

compose-prod.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
services:
2+
boaviztapi:
3+
image: ghcr.io/boavizta/boaviztapi:latest
4+
ports:
5+
- "5000:5000"
6+
7+
boaviztapi-doc:
8+
image: ghcr.io/boavizta/boaviztapi-doc:latest
9+
ports:
10+
- "8080:8080"

compose.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
services:
2+
api:
3+
build:
4+
context: .
5+
ports:
6+
- "5000:5000"
7+
8+
docs:
9+
build:
10+
context: docs
11+
ports:
12+
- "8080:8080"

docs/Dockerfile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
FROM python:3.7-slim-buster
1+
ARG PY_VERSION=3.13
2+
FROM python:$PY_VERSION-slim
23

34
WORKDIR /docs
45

5-
RUN pip install mkdocs
6-
RUN pip install mkdocs-render-swagger-plugin
7-
RUN pip install mkdocs-material
6+
RUN pip install mkdocs \
7+
mkdocs-render-swagger-plugin \
8+
mkdocs-macros-plugin \
9+
mkdocs-material
810

911
COPY . .
1012

11-
1213
EXPOSE 8080
1314

1415
ENTRYPOINT ["mkdocs", "serve"]

docs/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ See the "getting started" docs for [mkdocs](https://www.mkdocs.org/getting-start
3333

3434
```bash
3535
# If mkdocs is installed via poetry (preferred)
36-
# from the root of the cloned repository
37-
cd docs
38-
poetry run mkdocs serve
36+
make run-doc
3937
```
4038

4139
```bash

docs/docs/config.md

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,62 @@
11
# Configuration
22

3-
The config file located at data/config.json is used to set default values for the following parameters.
3+
The API can be configured to use different defaults for locations and hardware specs, as well as different levels of precision.
4+
5+
The full list of configuration parameters and their defaults can be found in [`boaviztapi/utils/config.py`](https://github.com/Boavizta/boaviztapi/blob/main/boaviztapi/utils/config.py).
6+
7+
## Overriding default values
8+
9+
Each variable can be overridden using an environment variable of the same name, prefixed with `BOAVIZTA_`.
10+
11+
For example, the `default_server` parameter can be overridden with the environment variable, `BOAVIZTA_DEFAULT_SERVER`.
12+
13+
## CORS
14+
15+
By default, all origins are allowed, but can be changed with the `BOAVIZTA_ALLOWED_ORIGINS` environment variable with the following format:
16+
17+
```
18+
BOAVIZTA_ALLOWED_ORIGINS = '["url1", "url2", ...]'
19+
```
20+
21+
For example: `BOAVIZTA_ALLOWED_ORIGINS='["https://datavizta.boavizta.org","https://boavizta.org"]'`.
22+
23+
## Special message
24+
25+
You can customize the home page with a special message by setting the environment variable `BOAVIZTA_SPECIAL_MESSAGE` in HTML format.
26+
27+
For example: `BOAVIZTA_SPECIAL_MESSAGE="<p>my welcome message in HTML format</p>"`
428

529
## Default location
630

7-
The default location will be used if the user does not specify a ```usage_location``` in the request.
8-
The parameter is used to complete the impact of electricity.
31+
The default location will be used if the user does not specify a `usage_location` in the request. The parameter is used to complete the impact of electricity.
932

1033
```
1134
default_location: "EEE"
1235
```
1336

37+
This can be overridden with the `BOAVIZTA_DEFAULT_LOCATION` environment variable.
38+
1439
## Default archetype
1540

16-
The default archetype will be used if the user does not specify an ```archetype``` in the request.
17-
Note that it must match an existing archetype ID in the archetype files.
41+
The default archetype will be used if the user does not specify an `archetype` in the request. Note that it must match an existing archetype ID in the archetype files.
1842

1943
```
2044
default_cpu: "DEFAULT"
2145
default_server: "compute_medium"
2246
```
2347

24-
## Default_criteria
48+
These can be overridden with the `BOAVIZTA_DEFAULT_CPU` and `BOAVIZTA_DEFAULT_SERVER` environment variables.
2549

26-
The default criteria will be used if the user does not specify the ```criteria``` in the request.
50+
## Default criteria
51+
52+
The default criteria will be used if the user does not specify the `criteria` in the request.
2753

2854
```
2955
default_criteria: ["gwp", "adp", "pe"]
3056
```
3157

58+
This can be overridden with the `BOAVIZTA_DEFAULT_CRITERIA` environment variable.
59+
3260
## Minimal significant figures
3361

3462
The minimal number of significant figures will be employed if classical rounding yields a result containing more significant figures than the minimal allowed.
@@ -39,16 +67,20 @@ min_sig_fig: 1
3967

4068
*If set to 1, the results will be rounded at least to 1 significant figures.*
4169

70+
This can be overridden with the `BOAVIZTA_MIN_SIG_FIG` environment variable.
4271

4372
## Maximal significant figures
4473

4574
The maximum number of significant figures will be employed if classical rounding yields a result containing more significant figures than the maximum allowed.
75+
4676
```
4777
max_sig_fig: 5
4878
```
4979

5080
*If set to 5, the results will be rounded to a maximum of 5 significant figures.*
5181

82+
This can be overridden with the `BOAVIZTA_MAX_SIG_FIG` environment variable.
83+
5284
## Uncertainty percentage
5385

5486
Uncertainty percentage is used to adapt the intensity of the rounding. The lower the uncertainty percentage, the lower aggressive the rounding.
@@ -59,10 +91,14 @@ uncertainty: 10
5991

6092
*If set to 10, the rounding aggressiveness will be set to 10%.*
6193

94+
This can be overridden with the `BOAVIZTA_UNCERTAINTY` environment variable.
95+
6296
## CPU name fuzzymatch threshold
6397

6498
The CPU name fuzzymatch threshold will determine the minimum similarity between the CPU name in the request and the CPU name in the database. If the similarity is lower than the threshold, the API will not use the match.
6599

66100
```
67101
cpu_name_fuzzymatch_threshold: 62
68-
```
102+
```
103+
104+
This can be overridden with the `BOAVIZTA_CPU_NAME_FUZZYMATCH_THRESHOLD` environment variable.

docs/docs/deploy.md

Lines changed: 36 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,70 @@
11
# Deploy the API
22

3-
## Deploy
4-
5-
### with docker
3+
## Docker
64

75
```bash
8-
$ docker run -p 5000:5000 ghcr.io/boavizta/boaviztapi:latest
9-
```
10-
11-
Then access api at <http://localhost:5000>
12-
13-
### with docker-compose
14-
15-
```yaml
16-
version: "3.9"
17-
services:
18-
boaviztapi:
19-
image: ghcr.io/boavizta/boaviztapi:latest
20-
environment:
21-
- SPECIAL_MESSAGE="<p>my welcome message in HTML format</p>"
22-
ports:
23-
- "5000:5000"
24-
boaviztapi-doc:
25-
image: ghcr.io/boavizta/boaviztapi-doc:latest
26-
environment:
27-
- API_URL=http://boaviztapi_url.com
28-
ports:
29-
- "8080:8080"
6+
$ docker run -p 5000:5000 ghcr.io/boavizta/boaviztapi:latest
307
```
318

32-
### with pip
9+
Exposes the API at <http://localhost:5000>.
3310

34-
boaviztapi pip package : [https://pypi.org/project/boaviztapi/](https://pypi.org/project/boaviztapi/)
11+
## Docker Compose
3512

3613
```bash
37-
$ pip3 install boaviztapi
14+
# Using Docker images from GCR
15+
docker compose -f compose-prod.yaml up
16+
17+
# Building images from source
18+
docker compose up
3819
```
3920

40-
### from source
21+
Exposes the API at <http://localhost:5000>, and the docs at <http://localhost:8080>.
4122

42-
#### Prerequisite
23+
## AWS Lambda
4324

44-
Python 3 mandatory, python >=3.9 recommended, poetry recommended
25+
### Prerequisites
4526

46-
#### clone the repo
27+
- [AWS](https://aws.amazon.com/) and [Serverless Framework](https://www.serverless.com/) accounts
28+
- [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html)
29+
- [Serverless Framework CLI](https://www.serverless.com/framework/docs/getting-started)
4730

48-
```bash
49-
$ git clone https://github.com/Boavizta/boaviztapi.git
31+
### Deployment
32+
33+
```sh
34+
serverless deploy
5035
```
5136

52-
#### Setup poetry
37+
When the deploy succeeds, it will show you the URLs for the deployed function, and you can call the API as normal. You can query these URLs at any time with `serverless info`.
38+
39+
## From source
40+
41+
### Prerequisites
5342

54-
Install poetry.
43+
- Python >=3.12
44+
- [Poetry](https://python-poetry.org/)
45+
- `make`
46+
47+
### Clone the repo
5548

5649
```bash
57-
$ pip3 install poetry
50+
$ git clone https://github.com/Boavizta/boaviztapi.git
5851
```
5952

60-
Install dependencies and create a python virtual environment.
53+
### Install
6154

6255
```bash
6356
$ make install
64-
$ poetry shell
6557
```
6658

67-
#### Launch a development server
68-
69-
**Once in the poetry environment**
70-
71-
Development server uses [uvicorn](https://www.uvicorn.org/) and [fastapi](https://fastapi.tiangolo.com/), you can launch development server with the `uvicorn` CLI.
59+
### Launch the server
7260

7361
```bash
74-
$ uvicorn boaviztapi.main:app --host=localhost --port 5000
62+
$ make run
7563
```
7664

77-
You can run the tests with `pytest`.
78-
79-
### CORS
80-
81-
By default, all origin are allowed. If you need to limit them set env value ```ALLOWED_ORIGINS``` with the following format : ```ALLOWED_ORIGINS = '["url1", "url2", ...]'```
82-
83-
Example : ```ALLOWED_ORIGINS='["https://datavizta.boavizta.org","https://boavizta.org"]'```
84-
85-
### Special message
86-
87-
You can customize the home page with a special message by setting the env value ```SPECIAL_MESSAGE`` in HTML format.
88-
89-
Example : ```SPECIAL_MESSAGE="<p>my welcome message in HTML format</p>"```
90-
91-
9265
## SDK
9366

94-
**python-sdk** : [https://pypi.org/project/boaviztapi-sdk/](https://pypi.org/project/boaviztapi-sdk/)
67+
You can also use BoaviztaAPI directly in code with the SDKs:
9568

96-
**rust-sdk** : [https://github.com/Boavizta/boaviztapi-sdk-rust](https://github.com/Boavizta/boaviztapi-sdk-rust)
69+
- **python-sdk** : [https://pypi.org/project/boaviztapi-sdk/](https://pypi.org/project/boaviztapi-sdk/)
70+
- **rust-sdk** : [https://github.com/Boavizta/boaviztapi-sdk-rust](https://github.com/Boavizta/boaviztapi-sdk-rust)

0 commit comments

Comments
 (0)