This service offers endpoints for
- `/add_bet` - registering a new lotto bet
- `/show_results` - request to take a look at the current status of your bet
The endpoints and their documentation via a Swagger UI is reacheable on the /docs
endpoint once the application is running.
The service needs the following environment variables at runtime:
```
RABBIT_PORT= {host of the RabbitMQ instance}
RABBIT_HOST= {port of the RabbitMQ instance}
QUEUE_DRAWING_EVENT= {name of the queue to publish to on the RabbitMQ instance}
DRAW_MESSAGE_EXCHANGE= {exchange key on the RabbitMQ instance}
MONGO_INITDB_ROOT_USERNAME= {username to authenticat against a database on MongoDB instance}
MONGO_INITDB_ROOT_PASSWORD= {password to authenticat against a database on MongoDB instance}
MONGO_PORT= {port of MongoDB instance}
MONGO_HOST= {host of MongoDB instance}}
CUSTOMER_COLLECTION_NAME= {collection name on MongoDB instance}
CUSTOMER_DATABASE_NAME= {database name on MongoDB instance}
DEFAULT_INTERNAL_SERVICE_PORT= {default port where the application should run (only for docker)}
```
This can be achieved by manually setting them or putting them into an .env
file. This file can be conveniently used for docker execution as well.
- Install the dependencies
pip install -r src/requirements.txt
- Make sure a RabbitMQ instance is running and has been configured via the environment variables to be reached by the publisher
- Start the service by excuting the following command
uvicorn src.customer.application.app:api --host 127.0.0.1 --port 8080
Dockerfile - The dockerfile is the instruction on how to create the image which on execution becomes an instance or usually refered to as a container. In the adjacent dockerfile the following steps are performed:
- Select the base image to built upon
- Set all the environment variables which will be present upon runtime for the application
- Install the dependencies for python
- Copy the source code into the image
- Copy the start script and make it executeable
- Set Workdirectory and document the port on which the application will run
- Supply a default command for starting the application
Execution
- Build the docker container with a desired name and tag
cd .\customer_service\ docker network create lotto_local docker build -t customer_service:0.2.0 .
- Run it
docker run --rm --env-file ../.env --network=lotto_local --name customer_service -p 8085:8080 customer_service:0.2.0