The main repository is hosted in gitlab.com/intellidrone/api_new but it is automaticaly mirrored to github.com and to gitlab.com/intellidrone/apis/latest. If you are in the Github page it may occur that is not updated to the last version.
- Default branch when pull is DEVELOP.
- Master branch is protected and it is not possible to push. Create a merge request instead.
- MASTER BRANCH: it creates a docker image with node with the tag intellidrone/api:latest and it applies node server in webagro production server.
- DEVELOP BRANCH: it creates a docker image with node with the tag intellidrone/api:develop and it applies node server in webagro development server.
There is a script called init.service which creates everything to start the api. The parameters are:
- Stage (development or production).
- Folder. It is where the assets are going to be created. The path is from the script folder.
To use it just run it as following:
./scripts/init_service.sh d deploy/qa
To upload code in production, you must have a gitlab user credentials and server public key in base64 format. Then, executes the following code:
./upload_to_node_server.sh production USER PASSWORD
To upload code in development, use the following:
./upload_to_node_server.sh development USER PASSWORD
The image name is: intellidrone/api. Available TAGs:
- latest: from master branch.
- develop: from develop branch.
To use the api as a containerized service there is also a script called run_docker_compose.sh. There is only one parameter:
- Stage (development or production).
To use it just run it as following:
./scripts/init_service.sh d
The image has the following environments. You can overwrite them by adding an .env file:
- PORT_APP: default 3000.
- PORT_DB: default 27017.
- PORT_APP_DEBUG: default 9229.
- SWAGGER_HOST: url where the service will be available. Default localhost:${PORT}
- SWAGGER_BASE_PATH: path inside host. Default /api/
- DB_MAIN_CLIENT: db configuration for the main (and unique) db. Default docker
- DATABASE_FILE: where database credentials are stored. Default ./assets/database.json
- JWT_FILE: file with a key to encrypt password and tokens. Default ./assets/key.b64.pub
- APP_TOKENS_FILE: where app tokens are stored. Default ./app_tokens.json
- DATA_DB: where data is saved. Default ./data/db
If the development stage is selected, the app will be attach to a debugger listening on port 9229 and the source code in the host will be the same as in the container.
In order to use the api, a token must be generated and add it to app_tokens.json. Use this page to calculate the SHA-256 of the password. That file must be filled as:
[
{
"name": "APP NAME",
"token": "TOKEN GENERATED BY SHA-256",
"password": "Phrase to be encrypted"
},
{
"name": "APP NAME 2",
"token": "TOKEN GENERATED BY SHA-256",
"password": "Phrase to be encrypted"
}
]
In order to connect the api with a database, there are 3 thing to consider:
- A definition must me placed in .env file called DB_MAIN_CLIENT.
- To use a database inside a docker container, place the definition DATABASE_LOCAL=1 inside .env file.
- A file called database.json must be created following the next prototype:
{
"MAIN_DB":{
"development":{
"client": "mongo",
"connection": {
"host" : "127.0.0.1",
"user" : "root",
"password" : "PassWord",
"database" : "vacas",
"charset" : "utf8"
}
},
"docker":{
"client": "mongo",
"connection": {
"host" : "database",
"user" : "root",
"password" : "DockerPassWORD",
"database" : "vacas",
"charset" : "utf8"
}
},
"production":{
"client": "mongo",
"connection": {
"host" : "127.0.0.1",
"user" : "",
"password" : "",
"database" : "vacas",
"charset" : "utf8"
}
}
}
}
© Singleton, Argentina, 2018.