fix: use start.sh to reliably expand $PORT on Railway#23
Conversation
…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
✅ Deploy Preview for bajet-buddy canceled.
|
There was a problem hiding this comment.
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.
|
|
||
| COPY . . | ||
|
|
||
| RUN chmod +x start.sh |
There was a problem hiding this comment.
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
| @@ -0,0 +1,2 @@ | |||
| #!/bin/sh | |||
| exec uvicorn app.main:app --host 0.0.0.0 --port "${PORT:-8080}" --workers 2 | |||
There was a problem hiding this comment.
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.
| 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}" |
Summary
Railway's exec-form start command (both
railway.tomland the dashboard override) passes args directly without a shell, so$PORTwas never expanded — uvicorn saw the literal string$PORTand rejected it.A
#!/bin/shscript 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)Dockerfile—chmod +x start.sh,CMD ["./start.sh"]railway.toml—startCommand = "./start.sh"In Railway dashboard: clear the custom start command field (leave it blank) so
railway.tomltakes 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
uvicornalways receives the real port (defaults to 8080 locally).Bug Fixes
uvicornwith "${PORT:-8080}"Migration
Written for commit 2c932f0. Summary will update on new commits. Review in cubic