Skip to content

Commit 50c99c8

Browse files
committed
Dockerize the app, added License and Build
1 parent 5badb8c commit 50c99c8

7 files changed

Lines changed: 79 additions & 4 deletions

File tree

Project/.dockerignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
database.db
2+
3+
.venv
4+
5+
__pycache__
6+
7+
.dockerignore
8+
9+
.gitignore
10+
11+
LICENSE
12+
13+
build.sh
14+
15+
.github

Project/.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
venv
1+
.venv
2+
3+
__pycache__
4+
5+
database.db

Project/Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM python:3.13-slim
2+
3+
WORKDIR /app
4+
5+
COPY requirements.txt requirements.txt
6+
7+
RUN pip install --no-cache-dir -r requirements.txt
8+
9+
COPY . .
10+
11+
EXPOSE 8000
12+
13+
CMD [ "fastapi", "dev", "app/main.py", "--port", "8000", "--host", "0.0.0.0" ]

Project/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Digpal Singh Rathore
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Project/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ A simple FastAPI-based Todo application with SQLite + Docker support.
2626
## 🛠️ Setup Locally
2727

2828
```bash
29-
git clone https://github.com/YOUR_USERNAME/fastapi-todo.git
29+
git clone https://github.com/dsrathore1/fastapi-todo.git
3030
cd fastapi-todo
3131
python -m venv venv
3232
source venv/bin/activate
33-
pip install -r requirements.txt
34-
uvicorn app.main:app --reload
33+
pip install -r requirements.txt

Project/app/main.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ async def lifespan(app: FastAPI):
2323

2424
app = FastAPI(lifespan=lifespan)
2525

26+
#! Root path
27+
@app.get("/")
28+
def root_page():
29+
return {"message": "Hello Genius"}
2630

2731
#! Create Todo list
2832
@app.post("/todo/", response_model=Todo)

Project/build.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
#? Optional : Clear previous Docker build cache
4+
docker builder prune -f
5+
6+
#? Remove if there any image exists by same name
7+
docker rmi fastapi_app:latest
8+
9+
#? Build Docker image
10+
docker build -t fastapi_app:latest .
11+
12+
#? Optional : Clean up again after build
13+
docker builder prune -f
14+
15+
#? Remove if there any container exists by same name
16+
docker rm myapp
17+
18+
#? Activate the container
19+
docker run --name myapp -d -p 8000:8000 fastapi_app:latest

0 commit comments

Comments
 (0)