Skip to content

Commit 5d27376

Browse files
committed
Add Railway deployment configuration
1 parent fbe9f82 commit 5d27376

3 files changed

Lines changed: 24 additions & 4 deletions

File tree

backend/Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ COPY . .
2020
RUN useradd -m -u 1000 appuser && chown -R appuser:appuser /app
2121
USER appuser
2222

23-
# Expose port
23+
# Expose port (Railway uses dynamic PORT)
2424
EXPOSE 8000
2525

26-
# Run the application
27-
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
26+
# Default command (Railway overrides via railway.toml)
27+
CMD ["sh", "-c", "uvicorn app.main:app --host 0.0.0.0 --port ${PORT:-8000}"]

backend/app/config.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from typing import List, Optional
44
from pydantic_settings import BaseSettings, SettingsConfigDict
5+
from pydantic import field_validator
56
from functools import lru_cache
67

78

@@ -18,8 +19,16 @@ class Settings(BaseSettings):
1819
app_version: str = "0.2.0"
1920
debug: bool = False
2021

21-
# Database
22+
# Database (Railway uses DATABASE_URL)
2223
database_url: str = "postgresql://postgres:postgres@localhost:5432/nsr"
24+
25+
@field_validator("database_url", mode="before")
26+
@classmethod
27+
def fix_database_url(cls, v: str) -> str:
28+
"""Convert postgres:// to postgresql:// for SQLAlchemy compatibility."""
29+
if v and v.startswith("postgres://"):
30+
return v.replace("postgres://", "postgresql://", 1)
31+
return v
2332

2433
# Security
2534
secret_key: str = "dev-secret-key-change-in-production"

backend/railway.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Railway configuration for NSR Backend
2+
[build]
3+
builder = "dockerfile"
4+
dockerfilePath = "Dockerfile"
5+
6+
[deploy]
7+
startCommand = "alembic upgrade head && python scripts/seed_data.py && uvicorn app.main:app --host 0.0.0.0 --port $PORT"
8+
healthcheckPath = "/health"
9+
healthcheckTimeout = 100
10+
restartPolicyType = "on_failure"
11+
restartPolicyMaxRetries = 3

0 commit comments

Comments
 (0)