Skip to content

Commit 8afb4e5

Browse files
authored
Merge pull request #319 from DevanshuNEU/fix/railway-dynamic-port-bind
fix: bind uvicorn to Railway's dynamic $PORT (prod deploy healthcheck failure)
2 parents 022ef14 + 1ce41ee commit 8afb4e5

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

backend/Dockerfile

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ COPY . .
2222
# Create repos directory for cloning
2323
RUN mkdir -p repos
2424

25-
# Expose port
25+
# Expose the default port (informational; Railway injects its own $PORT at runtime)
2626
EXPOSE 8000
2727

28-
# Health check
28+
# Health check hits whatever port the app bound to, so it tracks $PORT not a hardcoded 8000
2929
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
30-
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health').read()" || exit 1
30+
CMD python -c "import os,urllib.request; p=os.environ.get('PORT','8000'); urllib.request.urlopen('http://localhost:'+p+'/health').read()" || exit 1
3131

32-
# Run with uvicorn (proxy-headers enabled for rate limiting behind reverse proxy)
33-
# Set FORWARDED_ALLOW_IPS env var in production to your proxy's IP range
34-
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", "--proxy-headers"]
32+
# Bind Railway's dynamic $PORT (fallback 8000 for local/compose). The platform healthcheck
33+
# queries $PORT, so hardcoding 8000 here makes the deploy fail "service unavailable".
34+
# exec keeps uvicorn as PID 1 so it gets SIGTERM for graceful shutdown.
35+
# proxy-headers for rate limiting behind the reverse proxy (set FORWARDED_ALLOW_IPS in prod).
36+
CMD exec uvicorn main:app --host 0.0.0.0 --port ${PORT:-8000} --proxy-headers

0 commit comments

Comments
 (0)