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