Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #3

Merged
merged 3 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
DATABASE_NAME=DATABASE_NAME
MONGO_URL=mongodb://localhost:27017/
DATABASE_NAME=your_database_name
USERNAME=
PASSWORD=
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#base image
FROM python:3.8.6-slim-buster
FROM python:3.10-slim-buster

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
Expand Down
35 changes: 25 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
## FastAPI MicroService with Docker, Nginx and MongoDB(Motor)
## FastAPI Micro Service with Docker, Nginx, and Asynchronous MongoDB (Motor)

### Create [virtual environment](https://docs.python.org/3/library/venv.html) and install requirements
```sh
pip install -r requirements.txt
```
### Installation Instructions

### Run docker compose
- Make sure [docker](https://docs.docker.com/engine/install) and [docker-compose](https://docs.docker.com/compose/install/) installed
- Create a [virtual environment](https://docs.python.org/3/library/venv.html)
- Install the python Dependencies with `pip install -r requirements.txt`
- Copy the .env.example file as .env
```sh
cp .env.example .env
```
- Ensure that you fill in all the valid environment properties in the .env file.


### Run Locally
To run the service locally, use the following command:
```sh
uvicorn server:app --reload
```

### Run with Docker
To run the service using Docker, use the following command:
```sh
sudo docker-compose up -d --build
```

### Run Docker Compose for Production Build
Ensure that you have [Docker]((https://docs.docker.com/engine/install)) and [Docker Compose](https://docs.docker.com/compose/install/) installed.

### Lets Run
- Docker run `sudo docker-compose up -d --build`
- Locally run `uvicorn src.servers.start:app --reload`
8 changes: 4 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ services:
- servernet

server:
container_name: service
container_name: core_server
build: .
restart: always
command: gunicorn -w 4 -k uvicorn.workers.UvicornWorker src.servers.start:app --bind 0.0.0.0:8000
command: gunicorn -w 4 -k uvicorn.workers.UvicornWorker server:app --bind 0.0.0.0:8000
expose:
- 8000
# env_file:
# - .env
env_file:
- .env
depends_on:
- db
links:
Expand Down
9 changes: 4 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
fastapi==0.66.0
uvicorn==0.14.0
motor==2.4.0
python-dotenv==0.18.0
gunicorn==20.1.0
fastapi==0.104.0
uvicorn==0.23.2
motor==3.3.1
python-dotenv==1.0.0
2 changes: 1 addition & 1 deletion src/servers/start.py → server.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@


if __name__ == "main":
app.run()
app.run(host="0.0.0.0",port=9000)
2 changes: 1 addition & 1 deletion src/config/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def db() -> dict:
"db": {
"url": env("MONGO_URL", "mongodb://localhost:27017/"),
"name": env("DATABASE_NAME", "database_name"),
"user": env("USERNAME_NAME", ""),
"user": env("USERNAME", ""),
"password": env("PASSWORD", "")
}
}
2 changes: 1 addition & 1 deletion src/servers/models/todo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class Todos(Repository):
# async def index(self, add):
# await add([('', "")])
# await add([('_id')])

def collection(self):
return 'todos'
Expand Down
Loading