Skip to content

Commit

Permalink
Merge pull request #3 from akmamun/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
akmamun committed Oct 26, 2023
2 parents 364d152 + 3fcd592 commit b3fc679
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 24 deletions.
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

0 comments on commit b3fc679

Please sign in to comment.