From e818a6a552317abaaa736ad6c4979e6addd08549 Mon Sep 17 00:00:00 2001 From: ValGrace Date: Sun, 5 Jul 2026 21:45:47 +0300 Subject: [PATCH] feat: containerize application and setup with make --- .dockerignore | 2 ++ Dockerfile | 12 ++++++++++++ Makefile | 13 +++++++++++++ README.md | 44 ++++++++++++++++++++++++++++++++++++++++++++ docker-compose.yaml | 38 ++++++++++++++++++++++++++++++++++++++ requirements.txt | 3 +++ 6 files changed, 112 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 Makefile create mode 100644 docker-compose.yaml create mode 100644 requirements.txt diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..932765a --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +__pycache__/ +venv diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4ff0903 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM python:3.11-slim + +WORKDIR /app + +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +COPY . . + +EXPOSE 8000 + +CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..34e70b5 --- /dev/null +++ b/Makefile @@ -0,0 +1,13 @@ +ENVIRONMENT_VARS_FILE := .env + +up: + docker compose up + +down: + docker compose down + +logs: + docker-compose logs -f + +clean: + docker compose down --rmi all -v \ No newline at end of file diff --git a/README.md b/README.md index 829d4c5..92a508b 100644 --- a/README.md +++ b/README.md @@ -301,6 +301,50 @@ Good next steps once you are comfortable with this project: --- +## Quick Setup Guide + +Follow these quick steps to get the project running using the provided `Makefile` (Docker-based). + +Prerequisites: + +- Install Docker and Docker Compose for your platform. +- Install make using chocolatey + +```bash +choco install make +``` +Create `.env` file then add these variables + +```bash +DB_USER= +DB_PASS= +DB_NAME= +``` + +Start the app (Docker): + +```bash +make up +``` + +Stop the app: + +```bash +make down +``` + +View container logs: + +```bash +make logs +``` + +Remove containers, images and volumes (clean): + +```bash +make clean +``` + ## License MIT - free to use, modify, and share. \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..245ba64 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,38 @@ +name: task_manager +services: + app: + container_name: task_manager_app + build: . + depends_on: + - db + ports: + - "8000:8000" + environment: + DATABASE_URL: "postgres://${DB_USER}:${DB_PASS}@postgres:5432/${DB_NAME}" + env_file: + - .env + develop: + watch: + - path: . + include: "*.py" + action: rebuild + + db: + image: postgres:16 + container_name: task_manager_db + environment: + POSTGRES_USER: ${DB_USER} + POSTGRES_PASSWORD: ${DB_PASS} + env_file: + - .env + ports: + - "5432:5432" + volumes: + - postgres-db:/var/lib/postgresql/data + +volumes: + postgres-db: + driver: local + + + diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..fee0189 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +fastapi +sqlalchemy +uvicorn \ No newline at end of file