AhmadYarAI commited on
Commit
6410f4f
·
1 Parent(s): 886a6a9

feat: add invoice creation logic with SQLAlchemy

Browse files
Files changed (3) hide show
  1. Dockerfile +15 -3
  2. README.md +1 -0
  3. main.py +15 -1
Dockerfile CHANGED
@@ -1,20 +1,32 @@
1
  FROM python:3.10-slim
2
 
3
  USER root
 
4
  RUN apt-get update && apt-get install -y libpq-dev gcc && rm -rf /var/lib/apt/lists/*
5
 
 
6
  RUN useradd -m -u 1000 user
7
  USER user
8
  ENV HOME=/home/user \
9
  PATH=/home/user/.local/bin:$PATH
10
 
 
11
  WORKDIR $HOME/app
12
 
13
- # Copy requirements file first to force a re-install if it changed
14
  COPY --chown=user:user requirements.txt .
15
  RUN pip install --no-cache-dir --upgrade -r requirements.txt
16
 
17
- # Copy the rest of the code
18
- COPY --chown=user:user . .
19
 
 
 
 
 
 
 
 
 
 
20
  CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
 
1
  FROM python:3.10-slim
2
 
3
  USER root
4
+ # Install system dependencies for Postgres and building extensions
5
  RUN apt-get update && apt-get install -y libpq-dev gcc && rm -rf /var/lib/apt/lists/*
6
 
7
+ # Setup user
8
  RUN useradd -m -u 1000 user
9
  USER user
10
  ENV HOME=/home/user \
11
  PATH=/home/user/.local/bin:$PATH
12
 
13
+ # We set the app root
14
  WORKDIR $HOME/app
15
 
16
+ # 1. Copy requirements from the backend folder
17
  COPY --chown=user:user requirements.txt .
18
  RUN pip install --no-cache-dir --upgrade -r requirements.txt
19
 
20
+ # 2. Copy everything from the backend folder into the 'backend' subfolder
21
+ COPY --chown=user:user . ./backend
22
 
23
+ # 3. IMPORTANT: Hugging Face builds from the root of your repo.
24
+ # If 'frontend' is next to 'backend', we ensure both are accessible.
25
+ # If you are pushing from the root, use:
26
+ COPY --chown=user:user ../frontend ./frontend
27
+
28
+ # 4. Set the working directory to where main.py lives
29
+ WORKDIR $HOME/app/backend
30
+
31
+ # 5. Run the app
32
  CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
README.md CHANGED
@@ -6,4 +6,5 @@ colorTo: indigo
6
  sdk: docker
7
  pinned: false
8
  app_port: 7860
 
9
  ---
 
6
  sdk: docker
7
  pinned: false
8
  app_port: 7860
9
+ docker_path: backend/Dockerfile
10
  ---
main.py CHANGED
@@ -1,5 +1,7 @@
 
1
  from fastapi import FastAPI
2
- from fastapi.middleware.cors import CORSMiddleware
 
3
  from core.database import engine, Base
4
  from api.invoices import router as invoice_router
5
 
@@ -8,6 +10,7 @@ Base.metadata.create_all(bind=engine)
8
 
9
  app = FastAPI(title="SmiloCAD Invoice API")
10
 
 
11
  app.add_middleware(
12
  CORSMiddleware,
13
  allow_origins=["*"],
@@ -15,6 +18,17 @@ app.add_middleware(
15
  allow_headers=["*"],
16
  )
17
 
 
 
 
 
 
 
 
 
 
 
 
18
  # Include the routes from the api folder
19
  app.include_router(invoice_router)
20
 
 
1
+ import os
2
  from fastapi import FastAPI
3
+ from fastapi.staticfiles import StaticFiles
4
+ from fastapi.responses import FileResponse
5
  from core.database import engine, Base
6
  from api.invoices import router as invoice_router
7
 
 
10
 
11
  app = FastAPI(title="SmiloCAD Invoice API")
12
 
13
+
14
  app.add_middleware(
15
  CORSMiddleware,
16
  allow_origins=["*"],
 
18
  allow_headers=["*"],
19
  )
20
 
21
+ # 1. Route to serve the index.html
22
+ @app.get("/")
23
+ async def read_index():
24
+ # Looks for frontend/index.html
25
+ return FileResponse("../frontend/index.html")
26
+
27
+ # 2. Mount the CSS and JS folders so the HTML can find them
28
+ # This matches your folder names: frontend/css and frontend/js
29
+ app.mount("/css", StaticFiles(directory="../frontend/css"), name="css")
30
+ app.mount("/js", StaticFiles(directory="../frontend/js"), name="js")
31
+
32
  # Include the routes from the api folder
33
  app.include_router(invoice_router)
34