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
4 changes: 3 additions & 1 deletion apps/api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ RUN pip install --no-cache-dir -r requirements.txt

COPY . .

RUN chmod +x start.sh

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Shell scripts created on Windows environments often contain CRLF line endings, which can cause an exec format error when the container starts in a Linux environment. It is a best practice to ensure the script has LF line endings during the build process to maintain cross-platform compatibility.

RUN sed -i 's/\r$//' start.sh && chmod +x start.sh


EXPOSE ${PORT:-8080}

HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \
CMD curl -f http://localhost:${PORT:-8080}/health || exit 1

CMD ["sh", "-c", "uvicorn app.main:app --host 0.0.0.0 --port ${PORT:-8080} --workers 2"]
CMD ["./start.sh"]
2 changes: 1 addition & 1 deletion apps/api/railway.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ builder = "DOCKERFILE"
dockerfilePath = "Dockerfile"

[deploy]
startCommand = "sh -c 'uvicorn app.main:app --host 0.0.0.0 --port $PORT --workers 2'"
startCommand = "./start.sh"
healthcheckPath = "/health"
healthcheckTimeout = 30
restartPolicyType = "ON_FAILURE"
Expand Down
2 changes: 2 additions & 0 deletions apps/api/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
exec uvicorn app.main:app --host 0.0.0.0 --port "${PORT:-8080}" --workers 2

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Hardcoding the number of workers can limit the application's ability to scale based on the available resources of the deployment environment. Using an environment variable with a default value allows for easier tuning (e.g., increasing workers on larger production instances) without requiring code changes.

Suggested change
exec uvicorn app.main:app --host 0.0.0.0 --port "${PORT:-8080}" --workers 2
exec uvicorn app.main:app --host 0.0.0.0 --port "${PORT:-8080}" --workers "${WORKERS:-2}"

Loading