Skip to content

fix: use start.sh to reliably expand $PORT on Railway#23

Merged
timothylee58 merged 1 commit into
mainfrom
claude/funny-johnson-bVave
May 25, 2026
Merged

fix: use start.sh to reliably expand $PORT on Railway#23
timothylee58 merged 1 commit into
mainfrom
claude/funny-johnson-bVave

Conversation

@timothylee58

@timothylee58 timothylee58 commented May 25, 2026

Copy link
Copy Markdown
Owner

Summary

Railway's exec-form start command (both railway.toml and the dashboard override) passes args directly without a shell, so $PORT was never expanded — uvicorn saw the literal string $PORT and rejected it.

A #!/bin/sh script is always invoked via its shebang by the OS kernel, guaranteeing shell expansion in every code path.

Changes:

  • start.sh — new entry point: exec uvicorn ... --port "${PORT:-8080}" (falls back to 8080 locally)
  • Dockerfilechmod +x start.sh, CMD ["./start.sh"]
  • railway.tomlstartCommand = "./start.sh"

In Railway dashboard: clear the custom start command field (leave it blank) so railway.toml takes over, or set it to ./start.sh.

https://claude.ai/code/session_017cLXjZu6kkjXRf2BemMPpp


Generated by Claude Code


Summary by cubic

Fixes missing $PORT expansion on Railway by switching to a shebang start.sh entrypoint. Ensures uvicorn always receives the real port (defaults to 8080 locally).

  • Bug Fixes

    • Add start.sh to exec uvicorn with "${PORT:-8080}"
    • Update Dockerfile to chmod +x and set CMD to ./start.sh
    • Point railway.toml startCommand to ./start.sh
  • Migration

    • In Railway dashboard, clear the custom start command or set it to ./start.sh

Written for commit 2c932f0. Summary will update on new commits. Review in cubic

…y invocation

Railway's exec-form start command and dashboard overrides both pass
args without shell expansion, so \$PORT was never substituted.
A #!/bin/sh script is always run through the OS shell via its shebang,
making \${PORT:-8080} expansion reliable in every code path.

https://claude.ai/code/session_017cLXjZu6kkjXRf2BemMPpp
@netlify

netlify Bot commented May 25, 2026

Copy link
Copy Markdown

Deploy Preview for bajet-buddy canceled.

Name Link
🔨 Latest commit 2c932f0
🔍 Latest deploy log https://app.netlify.com/projects/bajet-buddy/deploys/6a1406030dc1e70008ab9c74

@timothylee58
timothylee58 marked this pull request as ready for review May 25, 2026 08:19
@timothylee58
timothylee58 merged commit 0badaa4 into main May 25, 2026
6 of 7 checks passed

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 3 files

Re-trigger cubic

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the API startup process by moving the uvicorn command into a dedicated start.sh script and updating the Dockerfile and Railway configuration to use this script. Feedback suggests improving the Dockerfile to handle potential CRLF line ending issues for better cross-platform compatibility and parameterizing the number of workers in the shell script using an environment variable to allow for easier scaling.

Comment thread apps/api/Dockerfile

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

Comment thread apps/api/start.sh
@@ -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}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants