Skip to content

Issue 1255 server port sb fix#1256

Merged
ramonskie merged 3 commits intocloudfoundry:mainfrom
stokpop:issue-1255-server-port-sb-fix
May 4, 2026
Merged

Issue 1255 server port sb fix#1256
ramonskie merged 3 commits intocloudfoundry:mainfrom
stokpop:issue-1255-server-port-sb-fix

Conversation

@stokpop
Copy link
Copy Markdown
Contributor

@stokpop stokpop commented Apr 28, 2026

fixes #1255

stokpop added 3 commits April 28, 2026 10:56
Apps with server.port set in application.yml would bind to the wrong
port at startup, causing CF health checks to fail. Apps with a
privileged port (< 1024, e.g. 443) would crash immediately with
java.net.BindException: Permission denied.

Mirrors the Ruby buildpack behaviour in spring_boot.rb release().

Fixes cloudfoundry#1255
…runtime

WriteEnvFile writes the literal string "$PORT" to deps/0/env/SERVER_PORT.
CF's launcher reads env files as plain text (no shell expansion), so Spring Boot
received the literal string "$PORT" as the port, which is invalid and ignored,
leaving server.port from application.yml in effect.

Replace with WriteProfileD which writes a bash profile.d script that is
*sourced* at container start — so $PORT is expanded to the actual CF-assigned
port number before Spring Boot initialises its embedded server.

This fixes:
  - apps binding to a hardcoded port instead of the CF-assigned $PORT
  - java.net.BindException: Permission denied for privileged ports (e.g. 443)
@rkoster rkoster requested a review from ramonskie May 4, 2026 08:19
@ramonskie
Copy link
Copy Markdown
Contributor

it seems there are more frameworks that have similar issues.
i will create a new pr for this as well

"JAVA_OPTS": "$JAVA_OPTS",
"SERVER_PORT": "$PORT",
if err := s.context.Stager.WriteEnvFile("JAVA_OPTS", "$JAVA_OPTS"); err != nil {
s.context.Log.Warning("Failed to set JAVA_OPTS: %s", err.Error())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

isn't this interfering the java opts finalization here? Could have been an issue also prior to this change that was missed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

yeah its addressed in #1262

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i really thought we handled all the old style writeEnvFile to writeProfileD but apparently not

@ramonskie
Copy link
Copy Markdown
Contributor

ramonskie commented May 4, 2026

if you want you can combine this with #1262

@stokpop
Copy link
Copy Markdown
Contributor Author

stokpop commented May 4, 2026

should I do something to combine it with #1262? or will that merge on top of this PR?

@ramonskie
Copy link
Copy Markdown
Contributor

If we merge this first it will just be fine as well

@ramonskie ramonskie merged commit bf4b21c into cloudfoundry:main May 4, 2026
1 check passed
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.

SERVER_PORT=$PORT not injected for Spring Boot JAR apps

3 participants