This is a microservice that provides information about social network.
- Swagger documentation:
http://localhost:PORT/docs
. - ReDoc documentation:
http://localhost:PORT/redoc
.
Where PORT
is the port where the microservice is running defined in the env file.
Environment variables are defined in the env.example file.
PORT
: The port number on which the application will run. Example value:8081
.LOGGING_LEVEL
: The logging level for the application. Example values:DEBUG
,INFO
.TZ
: The timezone for the application. Example value:America/Argentina/Buenos_Aires
.
MONGO_URL
: The URL for connecting to the MongoDB database. Example value:mongodb://localhost:27017
.MONGO_PORT
: The port number of the MongoDB server. Example value:27017
.MONGO_INITDB_DATABASE
: The name of the database containing the data. Example value:social_service
.
USERS_SERVICE_URL
: The URL for communicating with the users microservice. Example value:http://users:8082
.
This project uses MongoDB as the database. The script that is executed when initializing the database can be found within ./app/docker/init-mongodb.js. This script creates the collections and inserts the initial data.
This project uses Poetry to manage dependencies.
$ pip install poetry
$ poetry install
$ poetry add <dependency>
$ poetry update
After any change in pyproject.toml file (always execute this before installing):
$ poetry lock
$ docker-compose build
$ docker-compose up
$ docker images
When you run a docker-compose build, it creates a new image, but it doesn't remove the old one, so you can have a lot of images with the same name but different id. Then, you can remove all of them with the following command:
$ docker rmi $(docker images -f dangling=true -q) -f
Warning: This will remove all containers, images, volumes and networks not used by at least one container. Its recommended to run this command before docker-compose up to avoid problems.
$ docker system prune -a --volumes
The repository includes a Makefile that encapsulates various commands used frequently in the project as targets. The targets are executed by invoking:
- make <target>: The essential targets to start and stop the system are docker-compose-up and docker-compose-down, with the remaining targets being useful for debugging and troubleshooting.
Available targets are:
- docker-compose-up: Initializes the development environment (builds docker images for the server and client, initializes the network used by docker, etc.) and starts the containers of the applications that make up the project.
- docker-compose-down: Performs a
docker-compose stop
to stop the containers associated with the compose and then performs adocker-compose down
to destroy all resources associated with the initialized project. It is recommended to execute this command at the end of each run to prevent the host machine's disk from filling up. - docker-compose-logs: Allows viewing the current logs of the project. Use with
grep
to filter messages from a specific application within the compose. - docker-image: Builds the images to be used. This target is used by docker-compose-up, so it can be used to test new changes in the images before starting the project.
After any change in pyproject.toml file (always execute this before installing):
$ poetry lock
Then, install the development dependencies:
$ poetry install -E dev
To run the tests:
$ poetry run pytest app
$ docker build -t test-social -f Dockerfile.test . && docker run test-social && docker rmi test-social -f
Or use the Makefile target:
$ make docker-test