Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .railway/turl.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[build]
builder = "DOCKERFILE"
dockerfilePath = "./Dockerfile"

[deploy]
preDeployCommand = [
"uv run --no-sync --no-dev alembic upgrade head"
]
startCommand = """
sh -c '
gunicorn -k uvicorn.workers.UvicornWorker source.app:app --bind 0.0.0.0:$PORT --workers $WORKERS
'
"""

healthcheckPath = "/status"
32 changes: 32 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM python:3.13-slim

ARG APP_DIR=/source
WORKDIR ${APP_DIR}

ENV PATH=${APP_DIR}/.venv/bin:${PATH} \
PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1

# Install gettext (for compiling messages to other languages) and uv (single static binary) and clean up
RUN apt-get update && apt-get install -y --no-install-recommends curl ca-certificates \
&& curl -LsSf https://astral.sh/uv/install.sh | env UV_INSTALL_DIR=/usr/local/bin sh \
&& apt-get purge -y curl \
&& rm -rf /var/lib/apt/lists/*

# Copy dependency files first for better layer caching
COPY pyproject.toml uv.lock ./

# Install dependencies
RUN uv sync --frozen --no-dev

# Copy source code
COPY source/ ./source/
COPY alembic.ini ./alembic.ini
COPY alembic/ ./alembic/

# Expose port (Railway will set PORT environment variable)
EXPOSE 8000

# Add health check
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
CMD curl -f http://localhost:${PORT:-8000}/status || exit 1
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dependencies = [
"fastapi>=0.116.1",
"fastapi-throttle>=0.1.8",
"greenlet>=3.2.4",
"gunicorn>=23.0.0",
"httpx>=0.28.1",
"pydantic>=2.11.7",
"pydantic-settings>=2.10.1",
Expand Down
2 changes: 1 addition & 1 deletion source/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def create_app() -> FastAPI:
application = FastAPI(
name="tURL",
description="Tiny microservice for shortening URLs.",
docs_url="/swagger",
docs_url=None,
redoc_url="/docs",
dependencies=[
Depends(RateLimiter(times=settings.rate_limit_requests, seconds=settings.rate_limit_window_seconds)),
Expand Down
14 changes: 14 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.