From 1ce41eea2f3c86e246b436e2276d5910b721c99d Mon Sep 17 00:00:00 2001 From: Devanshu Rajesh Chicholikar Date: Thu, 11 Jun 2026 17:01:38 -0400 Subject: [PATCH] fix: bind uvicorn to Railway's dynamic $PORT instead of hardcoded 8000 Railway assigns a dynamic $PORT and runs its healthcheck against it. The Dockerfile hardcoded --port 8000, so every deploy after healthcheckPath was added to railway.json failed with "service unavailable" on /health. #316 and #318 have both been stuck for days; prod only survived on the pre-healthcheck #293 image until that replica was knocked out. Bind ${PORT:-8000} (fallback for local/compose) and make the internal healthcheck read the same port. --- backend/Dockerfile | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/backend/Dockerfile b/backend/Dockerfile index 34ea822..7c6ca1f 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -22,13 +22,15 @@ COPY . . # Create repos directory for cloning RUN mkdir -p repos -# Expose port +# Expose the default port (informational; Railway injects its own $PORT at runtime) EXPOSE 8000 -# Health check +# Health check hits whatever port the app bound to, so it tracks $PORT not a hardcoded 8000 HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ - CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health').read()" || exit 1 + CMD python -c "import os,urllib.request; p=os.environ.get('PORT','8000'); urllib.request.urlopen('http://localhost:'+p+'/health').read()" || exit 1 -# Run with uvicorn (proxy-headers enabled for rate limiting behind reverse proxy) -# Set FORWARDED_ALLOW_IPS env var in production to your proxy's IP range -CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", "--proxy-headers"] +# Bind Railway's dynamic $PORT (fallback 8000 for local/compose). The platform healthcheck +# queries $PORT, so hardcoding 8000 here makes the deploy fail "service unavailable". +# exec keeps uvicorn as PID 1 so it gets SIGTERM for graceful shutdown. +# proxy-headers for rate limiting behind the reverse proxy (set FORWARDED_ALLOW_IPS in prod). +CMD exec uvicorn main:app --host 0.0.0.0 --port ${PORT:-8000} --proxy-headers