Skip to content

Commit 8b637ce

Browse files
authored
fix(deploy): update LITESTAR_PORT to reference Railway's injected PORT (#236)
* fix(deploy): update LITESTAR_PORT to reference Railway's injected PORT * fix(deploy): update CMD to remove hardcoded port and use LITESTAR_PORT environment variable
1 parent e7cf2a6 commit 8b637ce

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

tools/deploy/docker/Dockerfile.distroless

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,12 @@ WORKDIR /workspace/app
213213
COPY --from=runtime-prep --chown=65532:65532 /workspace/app/.venv /workspace/app/.venv
214214

215215
# Container configuration
216+
# Port is configured via LITESTAR_PORT env var (defaults to 8000)
216217
STOPSIGNAL SIGTERM
217218
EXPOSE 8000
218219

219220
ENTRYPOINT ["/usr/local/bin/tini", "--"]
220-
CMD ["app", "run", "--host", "0.0.0.0", "--port", "8000"]
221+
CMD ["app", "run", "--host", "0.0.0.0"]
221222

222223
# Labels for container metadata (OCI spec)
223224
LABEL org.opencontainers.image.title="Litestar Fullstack SPA" \

tools/deploy/railway/.env.railway.example

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ APP_URL=https://your-app.up.railway.app
2626
LITESTAR_DEBUG=false
2727

2828
# Port configuration - auto-configured by deploy.sh
29-
# Railway injects PORT, we map it to LITESTAR_PORT
30-
# Do NOT set this manually - it uses Railway variable references
31-
# LITESTAR_PORT=${{PORT}}
29+
# Railway injects PORT env var at runtime (usually 8080)
30+
# LITESTAR_PORT must reference it dynamically:
31+
# LITESTAR_PORT=${{PORT}}
32+
# Do NOT hardcode a port number - use the Railway variable reference above
3233

3334
# -----------------------------------------------------------------------------
3435
# Database

tools/deploy/railway/deploy.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -300,10 +300,10 @@ ensure_environment() {
300300
if railway variables --kv 2>/dev/null | grep -q "SECRET_KEY="; then
301301
log_success "Environment variables already configured"
302302

303-
# Always ensure PORT is set (may need update)
304-
if ! railway variables --kv 2>/dev/null | grep -q "PORT=8080"; then
305-
log_info "Updating PORT configuration..."
306-
railway variables --set "PORT=8080" --set "LITESTAR_PORT=8080" --skip-deploys
303+
# Ensure LITESTAR_PORT references Railway's injected PORT
304+
if ! railway variables --kv 2>/dev/null | grep -q 'LITESTAR_PORT=\${{PORT}}'; then
305+
log_info "Setting LITESTAR_PORT to use Railway's PORT..."
306+
railway variables --set 'LITESTAR_PORT=${{PORT}}' --skip-deploys
307307
fi
308308

309309
# Ensure SQLAlchemy logs are quiet by default
@@ -330,6 +330,7 @@ ensure_environment() {
330330
SECRET_KEY=$(openssl rand -base64 32 | tr -d '=' | tr '+/' '-_')
331331

332332
# Set essential variables
333+
# Note: Railway injects PORT automatically, we reference it for LITESTAR_PORT
333334
railway variables --set "SECRET_KEY=${SECRET_KEY}" \
334335
--set "LITESTAR_DEBUG=false" \
335336
--set "VITE_DEV_MODE=false" \
@@ -338,8 +339,7 @@ ensure_environment() {
338339
--set "SQLALCHEMY_LOG_LEVEL=30" \
339340
--set "EMAIL_ENABLED=false" \
340341
--set "EMAIL_BACKEND=console" \
341-
--set "PORT=8080" \
342-
--set "LITESTAR_PORT=8080" \
342+
--set 'LITESTAR_PORT=${{PORT}}' \
343343
--set 'DATABASE_URL=${{Postgres.DATABASE_URL}}' \
344344
--set 'SAQ_REDIS_URL=${{Redis.REDIS_URL}}' \
345345
--set 'APP_URL=https://${{RAILWAY_PUBLIC_DOMAIN}}' \
@@ -349,7 +349,7 @@ ensure_environment() {
349349
log_info " - DATABASE_URL: linked to Postgres service"
350350
log_info " - SAQ_REDIS_URL: linked to Redis service"
351351
log_info " - APP_URL: auto-configured from Railway domain"
352-
log_info " - PORT/LITESTAR_PORT: 8080"
352+
log_info " - LITESTAR_PORT: uses Railway's injected PORT"
353353
}
354354

355355
# -----------------------------------------------------------------------------

0 commit comments

Comments
 (0)