From a67daa2e8fed579dae653f31e76ff3e020bfcea2 Mon Sep 17 00:00:00 2001 From: laugonzalezo Date: Wed, 11 Jun 2025 11:45:24 -0500 Subject: [PATCH 1/2] rrr --- .dockerignore | 3 +++ Dockerfile | 15 +++++++++++++++ gunicorn.conf.py | 12 ++++++++++++ requirements.txt | 1 + 4 files changed, 31 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 gunicorn.conf.py diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..ea7f2ce --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +.git* +**/*.pyc +.venv/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e3fbed3 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +# syntax=docker/dockerfile:1 + +FROM python:3.11 + +WORKDIR /code + +COPY requirements.txt . + +RUN pip install --no-cache-dir --upgrade -r requirements.txt + +COPY . . + +EXPOSE 3100 + +CMD ["gunicorn", "--bind", "0.0.0.0:3100", "main:app", "--worker-class", "uvicorn.workers.UvicornWorker"] \ No newline at end of file diff --git a/gunicorn.conf.py b/gunicorn.conf.py new file mode 100644 index 0000000..ed0c96c --- /dev/null +++ b/gunicorn.conf.py @@ -0,0 +1,12 @@ +# Gunicorn configuration file +import multiprocessing + +max_requests = 1000 +max_requests_jitter = 50 + +log_file = "-" + +bind = "0.0.0.0:3100" + +worker_class = "uvicorn.workers.UvicornWorker" +workers = (multiprocessing.cpu_count() * 2) + 1 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 990070a..d35d20d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ fastapi uvicorn jinja2 python-multipart +gunicorn From 1c5c94f812df533c54aa34f7524fc04487b9ab57 Mon Sep 17 00:00:00 2001 From: laugonzalezo Date: Wed, 18 Jun 2025 08:34:34 -0500 Subject: [PATCH 2/2] add new structure and code to backend --- app/database.py | 10 ++++++++++ app/main.py | 22 ++++++++++++++++++++++ app/models.py | 8 ++++++++ app/schemas.py | 4 ++++ data.db | Bin 0 -> 16384 bytes main.py | 34 ---------------------------------- requirements.txt | 1 + 7 files changed, 45 insertions(+), 34 deletions(-) create mode 100644 app/database.py create mode 100644 app/main.py create mode 100644 app/models.py create mode 100644 app/schemas.py create mode 100644 data.db delete mode 100644 main.py diff --git a/app/database.py b/app/database.py new file mode 100644 index 0000000..33a305c --- /dev/null +++ b/app/database.py @@ -0,0 +1,10 @@ +from sqlalchemy import create_engine +from sqlalchemy.ext.declarative import declarative_base +from sqlalchemy.orm import sessionmaker + +DATABASE_URL = "sqlite:///./data.db" # Cambia por tu URL del PostgreSQL + +engine = create_engine(DATABASE_URL, connect_args={"check_same_thread": False}) +SessionLocal = sessionmaker(bind=engine, autoflush=False, autocommit=False) + +Base = declarative_base() \ No newline at end of file diff --git a/app/main.py b/app/main.py new file mode 100644 index 0000000..51a5e44 --- /dev/null +++ b/app/main.py @@ -0,0 +1,22 @@ +from fastapi import FastAPI, Depends, HTTPException +from sqlalchemy.orm import Session +from . import models, schemas, database + +app = FastAPI() + +models.Base.metadata.create_all(bind=database.engine) + +def get_db(): + db = database.SessionLocal() + try: + yield db + finally: + db.close() + +@app.post("/registro") +def crear_registro(registro: schemas.RegistroCreate, db: Session = Depends(get_db)): + db_registro = models.Registro(name=registro.name) + db.add(db_registro) + db.commit() + db.refresh(db_registro) + return {"mensaje": f"Registro guardado para {registro.name}"} diff --git a/app/models.py b/app/models.py new file mode 100644 index 0000000..89062c4 --- /dev/null +++ b/app/models.py @@ -0,0 +1,8 @@ +from sqlalchemy import Column, Integer, String +from .database import Base + +class Registro(Base): + __tablename__ = "registros" + + id = Column(Integer, primary_key=True, index=True) + name = Column(String, index=True) \ No newline at end of file diff --git a/app/schemas.py b/app/schemas.py new file mode 100644 index 0000000..fa55a7c --- /dev/null +++ b/app/schemas.py @@ -0,0 +1,4 @@ +from pydantic import BaseModel + +class RegistroCreate(BaseModel): + name: str \ No newline at end of file diff --git a/data.db b/data.db new file mode 100644 index 0000000000000000000000000000000000000000..d1038a35201e0d7b4c670294538afba2a45ad030 GIT binary patch literal 16384 zcmeI#K~KUk6u|M85e!QdZyeX7M5Bp(0Vg&>oI~q0a3biYX(ABE4qUza8T~A7M5e*$ z$rJfEX}WGNZ+*Y*@@}pJnoIQtbC@7{L?^xKb2dzaen+rpKGJSex$