Skip to content

Commit b4ad035

Browse files
authored
Merge pull request #45 from OpenDash-Team/feature/docker_deployment
Feature: Docker Deployment
2 parents 39d5ffc + cb600c0 commit b4ad035

22 files changed

Lines changed: 269 additions & 111 deletions

‎.dockerignore‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Backend
2+
**/__pycache__/
3+
**/*.pyc
4+
5+
# Frontend
6+
frontend/logs
7+
frontend/*.log
8+
frontend/npm-debug.log*
9+
frontend/yarn-debug.log*
10+
frontend/yarn-error.log*
11+
frontend/pnpm-debug.log*
12+
frontend/lerna-debug.log*
13+
frontend/node_modules
14+
frontend/dist
15+
frontend/dist-ssr
16+
frontend/*.local
17+
18+
# Environment variables and secrets
19+
**/.env
20+
**/.env.*
21+
**/*.pem
22+
**/*.key
23+
24+
# Git
25+
.git/
26+
27+
# Editor directories and files
28+
.vscode/*
29+
!.vscode/extensions.json
30+
.idea
31+
.DS_Store
32+
*.suo
33+
*.ntvs*
34+
*.njsproj
35+
*.sln
36+
*.sw?

‎Dockerfile‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Stage 1: Build the frontend
2+
3+
FROM node:22-alpine AS frontend-build
4+
5+
WORKDIR /frontend
6+
7+
# Copy the files required for installing packages
8+
COPY frontend/package.json frontend/package-lock.json ./
9+
10+
# Install packages
11+
RUN npm ci
12+
13+
# Copy the source code
14+
COPY frontend/ ./
15+
16+
# Compile the frontend
17+
RUN npm run build
18+
19+
20+
# Stage 2: Prepare the backend + docker container
21+
22+
FROM python:3.12-slim
23+
24+
WORKDIR /app
25+
26+
# Copy the requirements file
27+
COPY backend/requirements.txt ./
28+
29+
# Install the dependencies
30+
RUN pip install --no-cache-dir -r requirements.txt
31+
32+
# Copy the source code
33+
COPY backend/app/ ./backend/
34+
35+
# Copy the compiled frontend files
36+
COPY --from=frontend-build /frontend/dist ./frontend/
37+
38+
# Port of the webserver
39+
EXPOSE 8000
40+
41+
# Start the FastAPI application
42+
CMD ["uvicorn", "backend.main:main", "--host", "0.0.0.0", "--port", "8000"]

‎README.md‎

Lines changed: 69 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,54 +21,56 @@ git clone https://github.com/RealUltra/OpenEats
2121
cd OpenEats
2222
```
2323

24-
## Virtual Environment
24+
## Development
25+
26+
### Virtual Environment
2527

2628
Create a virtual environment:
2729

28-
### Linux / macOS
30+
#### Linux / macOS
2931

3032
```bash
3133
python3 -m venv backend/.venv
3234
source backend/.venv/bin/activate
3335
```
3436

35-
### Windows
37+
#### Windows
3638

3739
```powershell
3840
python -m venv backend\.venv
3941
backend\.venv\Scripts\Activate.ps1
4042
```
4143

42-
## Install Dependencies
44+
### Install Dependencies
4345

4446
Install the required dependencies:
4547

4648
```bash
4749
pip install -r backend/requirements.txt
4850
```
4951

50-
## Sample Data
52+
### Sample Data (Optional, First Run Only)
5153

5254
To use the sample data, rename `backend/sample-data` to `backend/data`.
5355

54-
### Linux / macOS
56+
#### Linux / macOS
5557

5658
```bash
5759
mv backend/sample-data backend/data
5860
```
5961

60-
### Windows
62+
#### Windows
6163

6264
```powershell
6365
Rename-Item backend/sample-data backend/data
6466
```
6567

66-
## Running the API
68+
### Running the API
6769

6870
Start the application with:
6971

7072
```bash
71-
uv run fastapi dev --entrypoint backend.app.main:main
73+
fastapi dev --entrypoint backend.app.main:main
7274
```
7375

7476
The application will be available at:
@@ -77,13 +79,13 @@ The application will be available at:
7779
http://127.0.0.1:8000
7880
```
7981

80-
## Running the Web UI
82+
### Running the Web UI
8183

82-
### Prerequisites
84+
#### Prerequisites
8385

8486
Install Node.js and npm.
8587

86-
### Start the development server
88+
#### Start the development server
8789

8890
From the repository root, go into the frontend directory:
8991

@@ -105,41 +107,81 @@ npm run dev
105107

106108
Open the URL printed by Vite (normally `http://localhost:5173/`).
107109

108-
### Using the UI
110+
## Production
109111

110-
On the startup screen, choose **Customer** to browse restaurants or **Restaurant** to select an existing restaurant or create a new one. The restaurant view has tabs for general details and menu items.
112+
### Prerequisites
113+
114+
Install Docker with Docker Compose.
115+
116+
### Sample Data (Optional, First Run Only)
117+
118+
To start with the sample restaurants, move `backend/sample-data` to `data` in the repository root before starting the application.
119+
120+
#### Linux / macOS
121+
122+
```bash
123+
mv backend/sample-data ./data
124+
```
125+
126+
#### Windows
127+
128+
```powershell
129+
Move-Item backend/sample-data data
130+
```
111131

112-
### Build
132+
### Start the Application
113133

114-
From the `frontend` directory, create a production build with:
134+
From the repository root, run:
115135

116136
```bash
117-
npm run build
137+
docker compose up --build -d
118138
```
119139

140+
If there have been no changes since you last built the image, you may run:
141+
142+
```bash
143+
docker compose up -d
144+
```
145+
146+
### Open the Application
147+
148+
```text
149+
http://127.0.0.1:8000/
150+
```
151+
152+
### Stop the Application
153+
154+
```bash
155+
docker compose down
156+
```
157+
158+
## Using the UI
159+
160+
On the startup screen, choose **Customer** to browse restaurants or **Restaurant** to select an existing restaurant or create a new one. The restaurant view has tabs for general details and menu items.
161+
120162
## API Endpoints
121163

122164
The API provides the following endpoints:
123165

124166
| Method | Path | Description |
125167
|---|---|---|
126-
| GET | `/health` | `Checks if the API is running.` |
127-
| GET | `/restaurants` | `Lists all the restaurants.` |
128-
| GET | `/restaurants?{query}` | `Lists all the restaurants that match searching query: name=...&hasMenu=...&sort_by=...&sort_desc=...` |
129-
| GET | `/restaurants/{restaurant_id}` | `Retrieves a specific restaurant by its ID.` |
130-
| POST | `/restaurants` | `Creates a restaurant. Returns 201, 409 if the same name and address already exist, 422 for invalid input.` |
131-
| PATCH | `/restaurants/{restaurant_id}` | `Updates only the fields sent. Returns 200, 404 for an unknown ID, 409 for a duplicate, 422 for invalid input.` |
132-
| POST | `/restaurants/{restaurant_id}/menu-items` | `Creates a new menu item. Returns 201, 404 if the restaurant is not found, 422 for invalid input.` |
133-
| PATCH | `/restaurants/{restaurant_id}/menu-items/{menu_item_id}` | `Updates a menu item's fields. Returns 200, 404 if the item or restaurant is not found, 422 for invalid input.` |
134-
| DELETE | `/restaurants/{restaurant_id}/menu-items/{menu_item_id}` | `Deletes a specific menu item. Returns 204 on success, 404 if not found.` |
168+
| GET | `/api/v1/health` | `Checks if the API is running.` |
169+
| GET | `/api/v1/restaurants` | `Lists all the restaurants.` |
170+
| GET | `/api/v1/restaurants?{query}` | `Lists all the restaurants that match searching query: name=...&hasMenu=...&sort_by=...&sort_desc=...` |
171+
| GET | `/api/v1/restaurants/{restaurant_id}` | `Retrieves a specific restaurant by its ID.` |
172+
| POST | `/api/v1/restaurants` | `Creates a restaurant. Returns 201, 409 if the same name and address already exist, 422 for invalid input.` |
173+
| PATCH | `/api/v1/restaurants/{restaurant_id}` | `Updates only the fields sent. Returns 200, 404 for an unknown ID, 409 for a duplicate, 422 for invalid input.` |
174+
| POST | `/api/v1/restaurants/{restaurant_id}/menu-items` | `Creates a new menu item. Returns 201, 404 if the restaurant is not found, 422 for invalid input.` |
175+
| PATCH | `/api/v1/restaurants/{restaurant_id}/menu-items/{menu_item_id}` | `Updates a menu item's fields. Returns 200, 404 if the item or restaurant is not found, 422 for invalid input.` |
176+
| DELETE | `/api/v1/restaurants/{restaurant_id}/menu-items/{menu_item_id}` | `Deletes a specific menu item. Returns 204 on success, 404 if not found.` |
135177

136178

137179
## API Documentation
138180

139181
API documentation is available at:
140182

141183
```text
142-
http://127.0.0.1:8000/docs
184+
http://127.0.0.1:8000/api/v1/docs
143185
```
144186

145187
## Running Tests

‎backend/app/api/routes.py‎

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
from fastapi import FastAPI, HTTPException, Depends
1+
from fastapi import FastAPI, HTTPException, Depends, APIRouter
22
from json import JSONDecodeError
33

4-
from backend.app.core.dependencies import get_restaurant_service
5-
from backend.app.schemas.restaurant import Restaurant
6-
from backend.app.schemas.restaurant_query import RestaurantQuery
7-
from backend.app.services.restaurant_service import RestaurantService
8-
from backend.app.schemas.menu_item import MenuItem
9-
from backend.app.schemas.menu_item_request import MenuItemCreate, MenuItemUpdate
10-
from backend.app.schemas.restaurant_request import RestaurantCreate, RestaurantUpdate
11-
from backend.app.core.exceptions import DuplicateRestaurantError, RestaurantNotFoundError
12-
13-
def create_routes(app: FastAPI):
14-
@app.get("/health")
4+
from ..core.dependencies import get_restaurant_service
5+
from ..schemas.restaurant import Restaurant
6+
from ..schemas.restaurant_query import RestaurantQuery
7+
from ..services.restaurant_service import RestaurantService
8+
from ..schemas.menu_item import MenuItem
9+
from ..schemas.menu_item_request import MenuItemCreate, MenuItemUpdate
10+
from ..schemas.restaurant_request import RestaurantCreate, RestaurantUpdate
11+
from ..core.exceptions import DuplicateRestaurantError, RestaurantNotFoundError
12+
13+
def create_routes(api: FastAPI | APIRouter):
14+
@api.get("/health")
1515
async def health():
1616
return {"status": "ok"}
1717

18-
@app.get("/restaurants", response_model=list[Restaurant])
18+
@api.get("/restaurants", response_model=list[Restaurant])
1919
def list_restaurants(params: RestaurantQuery = Depends()):
2020
restaurant_service = get_restaurant_service()
2121

@@ -34,7 +34,7 @@ def list_restaurants(params: RestaurantQuery = Depends()):
3434
raise HTTPException(status_code=400, detail=str(e))
3535
raise HTTPException(status_code=500, detail="Restaurant data failed to follow correct list[Restaurant] schema")
3636

37-
@app.post("/restaurants/{restaurant_id}/menu-items", response_model=MenuItem, status_code=201)
37+
@api.post("/restaurants/{restaurant_id}/menu-items", response_model=MenuItem, status_code=201)
3838
def create_menu_item(restaurant_id: str, request: MenuItemCreate):
3939
restaurant_service = get_restaurant_service()
4040

@@ -44,7 +44,7 @@ def create_menu_item(restaurant_id: str, request: MenuItemCreate):
4444
except ValueError as e:
4545
raise HTTPException(status_code=404, detail=str(e))
4646

47-
@app.patch("/restaurants/{restaurant_id}/menu-items/{menu_item_id}", response_model=MenuItem)
47+
@api.patch("/restaurants/{restaurant_id}/menu-items/{menu_item_id}", response_model=MenuItem)
4848
def update_menu_item(restaurant_id: str, menu_item_id: str, request: MenuItemUpdate):
4949
restaurant_service = get_restaurant_service()
5050

@@ -55,7 +55,7 @@ def update_menu_item(restaurant_id: str, menu_item_id: str, request: MenuItemUpd
5555
raise HTTPException(status_code=404,detail=str(e))
5656

5757

58-
@app.delete("/restaurants/{restaurant_id}/menu-items/{menu_item_id}", status_code=204)
58+
@api.delete("/restaurants/{restaurant_id}/menu-items/{menu_item_id}", status_code=204)
5959
def delete_menu_item(restaurant_id: str, menu_item_id: str):
6060
restaurant_service = get_restaurant_service()
6161

@@ -67,7 +67,7 @@ def delete_menu_item(restaurant_id: str, menu_item_id: str):
6767
except ValueError as e:
6868
raise HTTPException(status_code=404, detail=str(e))
6969

70-
@app.get("/restaurants/{restaurant_id}", response_model=Restaurant)
70+
@api.get("/restaurants/{restaurant_id}", response_model=Restaurant)
7171
def get_restaurant(restaurant_id: str):
7272
restaurant_service = get_restaurant_service()
7373

@@ -80,7 +80,7 @@ def get_restaurant(restaurant_id: str):
8080
raise HTTPException(status_code=500, detail="Invalid JSON data")
8181

8282

83-
@app.post(
83+
@api.post(
8484
"/restaurants",
8585
response_model=Restaurant,
8686
status_code=201,
@@ -98,7 +98,7 @@ def create_restaurant(request: RestaurantCreate):
9898
raise HTTPException(status_code=409, detail=str(e))
9999

100100

101-
@app.patch(
101+
@api.patch(
102102
"/restaurants/{restaurant_id}",
103103
response_model=Restaurant,
104104
summary="Update a restaurant's information",
@@ -119,3 +119,9 @@ def update_restaurant(restaurant_id: str, request: RestaurantUpdate):
119119

120120
except DuplicateRestaurantError as e:
121121
raise HTTPException(status_code=409, detail=str(e))
122+
123+
124+
@api.get("/", include_in_schema=False)
125+
@api.get("/{path:path}", include_in_schema=False)
126+
def api_not_found(path: str):
127+
raise HTTPException(status_code=404, detail="Not Found")

‎backend/app/core/dependencies.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from pathlib import Path
22

3-
from backend.app.services.restaurant_service import RestaurantService
4-
from backend.app.repositories.restaurant_repository import RestaurantRepository
3+
from ..services.restaurant_service import RestaurantService
4+
from ..repositories.restaurant_repository import RestaurantRepository
55

66
def get_data_dir() -> Path:
77
data_dir = Path(__file__).resolve().parents[2] / "data"

0 commit comments

Comments
 (0)