This project is a FastAPI-based application for managing devices. It provides endpoints for creating, reading, updating, and deleting device information, as well as running tests inside a Docker container.
- CRUD Operations: Create, read, update, and delete device information via API endpoints.
- Validation: Input data is validated using Pydantic models to ensure data integrity.
- Database: Utilizes SQLite for storing device information.
- Testing: Includes pytest tests to ensure the functionality of the API endpoints.
- Linting: Uses pylint for code linting to maintain code quality.
.
├── Dockerfile
├── README.md
├── COMMENTS.md
├── requirements.txt
├── .gitignore
└── app/
├── main.py
├── api/
│ └── routers/
│ └── devices.py
├── database/
│ └── operations/
│ └── devices.py
├── models/
│ ├── coordinate.py
│ └── device.py
└── tests/
└── unit/
└── test_device_api.py
└── images/
├── jwt_authentication.svg
└── oauth2.0_authentication.svg
git clone https://github.com/tpemeja/Edgematrix-PrivateFor the rest of the project, we will assume that you have built the image locally with the name myapp. To obtain the Docker image, you have two options:
You can create the Docker image by executing the following command in the directory containing your Dockerfile:
docker build -t myapp .This command will build the Docker image with the tag myapp.
Alternatively, you can directly download the pre-built image from Docker Hub using the following command:
docker pull tpemeja/edgematrix:main-latestThis command will pull the latest version of the image tagged as main-latest from the Docker Hub repository tpemeja/edgematrix.
To run the Docker container, execute:
docker run -d -p <PORT>:80 -v <DATABASE_PATH>:/data myapp- <PORT> is the port number to map the FastAPI server to. For example, 8000.
- <DATABASE_PATH> is the path to the directory where to store the SQLite database file. For example, /home/user/myproject/database.
Once the Docker container is running, you can access the Swagger UI by navigating to:
http://localhost:<PORT>/docsTo run tests using pytest inside a Docker container, execute:
docker run -v <DATABASE_PATH>:/data myapp pytestOr to run it on an existing container
docker exec <CONTAINER_NAME|CONTAINER_ID> pytestTo perform linting using pylint, run:
docker run myapp pylint /code/appOr to run it on an existing container
docker exec <CONTAINER_NAME|CONTAINER_ID> pylint /code/appFirst, install the required dependencies by running:
pip install -r requirements.txtEnsure you have created a directory for the SQLite database. You can create it using the following command:
mkdir /dataThe database will be stored in /data/devices.db by default unless the value is modified using the variable DATABASE_PATH in the app/database/startup.py file.
To run tests locally using pytest, execute:
pytestTo perform linting using pylint locally, run:
pylint app/To start the FastAPI server locally, execute:
uvicorn app.main:app --host 0.0.0.0 --port <PORT>Once the FastAPI server is running locally, you can access the Swagger UI by navigating to:
http://localhost:<PORT>/docs