Skip to content

fix(docker): use next-runtime instead of accessing next_public vars directly#746

Merged
waleedlatif1 merged 1 commit intostagingfrom
fix/d
Jul 22, 2025
Merged

fix(docker): use next-runtime instead of accessing next_public vars directly#746
waleedlatif1 merged 1 commit intostagingfrom
fix/d

Conversation

@waleedlatif1
Copy link
Collaborator

Description

Added next-runtime-env to enable Docker runtime environment variable injection for NEXT_PUBLIC_ vars. Fixes Docker deployments where socket URLs were hardcoded at build time.

Fixes # (issue)

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Tested runtime variable injection with custom NEXT_PUBLIC_SOCKET_URL values in development environment. Verified getEnv() function returns runtime values when available and falls back to process.env.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works
  • All tests pass locally and in CI (bun run test)
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules
  • I have updated version numbers as needed (if needed)
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

Security Considerations:

  • My changes do not introduce any new security vulnerabilities
  • I have considered the security implications of my changes

@vercel
Copy link

vercel bot commented Jul 22, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
sim ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 22, 2025 7:21pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
docs ⬜️ Skipped (Inspect) Jul 22, 2025 7:21pm

@delve-auditor
Copy link

delve-auditor bot commented Jul 22, 2025

No security or compliance issues detected. Reviewed everything up to 8ea6a22.

Security Overview
  • 🔎 Scanned files: 1 changed file(s)
Detected Code Changes
Change Type Relevant files
Enhancement ► env.ts
    Use next-runtime-env for environment variables
    Add getEnv utility function for client/server context support

Reply to this PR with @delve-auditor followed by a description of what change you want and we'll auto-submit a change to this PR to implement it.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Greptile Summary

This PR introduces Docker runtime environment variable support by integrating the next-runtime-env library into the application's environment configuration system. The core change is the addition of a getEnv() utility function in lib/env.ts that prioritizes runtime environment variable injection over static process.env access for client-side NEXT_PUBLIC_ variables.

The implementation adds a fallback mechanism where getEnv() first attempts to retrieve variables from next-runtime-env (for Docker runtime injection) and falls back to process.env if the runtime library is unavailable. This approach specifically targets the Docker deployment issue where Next.js embeds NEXT_PUBLIC_ variables at build time, making it impossible to configure socket URLs and other dynamic settings without rebuilding container images.

The change selectively applies this new approach to client-side variables like NEXT_PUBLIC_SOCKET_URL, NEXT_PUBLIC_APP_URL, and authentication-related Google configuration variables, while preserving process.env access for server-only variables (VERCEL_URL) and build-time constants (NODE_ENV). This selective application demonstrates understanding of which environment variables need runtime flexibility versus which should remain static.

The integration fits well with the existing environment management system built on @t3-oss/env-nextjs and maintains the same validation and type safety patterns already established in the codebase. The getEnv() function is exported for potential use in other modules that need similar runtime variable access.

Confidence score: 4/5

  • This is a solid technical solution that addresses a real Docker deployment problem with minimal risk.
  • The implementation is clean, follows existing patterns, and maintains backward compatibility with proper fallback handling.
  • The selective application of getEnv() shows good judgment about which variables need runtime flexibility, though the missing package.json update needs attention.

1 file reviewed, no comments

Edit Code Review Bot Settings | Greptile

@waleedlatif1 waleedlatif1 merged commit f5a64f4 into staging Jul 22, 2025
6 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/d branch July 22, 2025 19:57
arenadeveloper02 pushed a commit to arenadeveloper02/p2-sim that referenced this pull request Sep 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant