-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from MutilatedPeripherals/deploy
Deploy
- Loading branch information
Showing
59 changed files
with
526 additions
and
365 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
.pytest_cache | ||
__pycache__ | ||
.idea | ||
../.idea | ||
.env | ||
files | ||
tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Backend Dockerfile | ||
FROM python:3.11-slim | ||
|
||
# Set the working directory | ||
WORKDIR /app | ||
|
||
# Install dependencies | ||
COPY requirements.txt . | ||
RUN pip install --no-cache-dir -r requirements.txt | ||
|
||
# Ensure the /data directory exists for the volume | ||
RUN mkdir -p /data | ||
|
||
# Copy the app code | ||
COPY . . | ||
|
||
# Expose the application port | ||
EXPOSE 8000 | ||
|
||
# Run the app | ||
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"] |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import os | ||
from pathlib import Path | ||
|
||
# Determine the base directory of the project | ||
BASE_DIR = Path(__file__).resolve().parent | ||
|
||
# Directory for storing files (e.g., uploads or local database) in local development | ||
UPLOAD_DIR = BASE_DIR / "files" | ||
UPLOAD_DIR.mkdir(parents=True, exist_ok=True) # Ensure the directory exists locally | ||
|
||
# Set database URL based on the environment | ||
if os.getenv("RAILWAY_ENVIRONMENT_NAME") == "production": # Check if running in production | ||
# Use PostgreSQL DATABASE_URL for production | ||
DATABASE_URL = os.getenv("DATABASE_URL") | ||
if not DATABASE_URL: | ||
raise ValueError("DATABASE_URL is not set in the Railway environment.") | ||
else: | ||
# In local development, use SQLite | ||
DATABASE_FILE = UPLOAD_DIR / "database.db" | ||
DATABASE_URL = f"sqlite:///{DATABASE_FILE}" | ||
|
||
# Construct the SQLAlchemy database URL | ||
SQLALCHEMY_DATABASE_URL = DATABASE_URL | ||
|
||
# Debugging: Print the resolved database URL | ||
print(f"SQLAlchemy Database URL: {SQLALCHEMY_DATABASE_URL}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from sqlalchemy import create_engine | ||
from sqlalchemy.ext.declarative import declarative_base | ||
from sqlalchemy.orm import sessionmaker | ||
from app.config import SQLALCHEMY_DATABASE_URL | ||
import os | ||
|
||
# Determine connection arguments based on the database type | ||
connect_args = {"check_same_thread": False} if "sqlite" in SQLALCHEMY_DATABASE_URL else None | ||
|
||
# SQLAlchemy engine configuration | ||
if connect_args: | ||
engine = create_engine( | ||
SQLALCHEMY_DATABASE_URL, | ||
connect_args=connect_args # Pass this only if not None | ||
) | ||
else: | ||
engine = create_engine(SQLALCHEMY_DATABASE_URL) # Omit connect_args entirely for PostgreSQL | ||
|
||
# Session maker for database sessions | ||
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) | ||
|
||
# Declarative base for ORM models | ||
Base = declarative_base() | ||
|
||
def initialize_database(): | ||
"""Initialize the database and create tables.""" | ||
if "sqlite" in SQLALCHEMY_DATABASE_URL: | ||
# SQLite-specific logic | ||
db_path = SQLALCHEMY_DATABASE_URL.replace("sqlite:///", "") | ||
absolute_path = os.path.abspath(db_path) | ||
print(f"Resolved database path: {absolute_path}") | ||
print(f"Initializing database at: {db_path}") | ||
if not os.path.exists(db_path): | ||
print("Database file does not exist. Creating new database.") | ||
else: | ||
print("Database file already exists.") | ||
|
||
# Create all tables using the engine | ||
Base.metadata.create_all(bind=engine) | ||
|
||
def get_db(): | ||
"""Provide a database session for dependency injection.""" | ||
db = SessionLocal() | ||
try: | ||
yield db | ||
finally: | ||
db.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.