fix(tomcat): restore context_path support from Ruby buildpack#1333
fix(tomcat): restore context_path support from Ruby buildpack#1333stokpop wants to merge 9 commits into
Conversation
context_path was implemented in the Ruby buildpack (commit 0186270, 2015) but never ported to Go. Users setting JBP_CONFIG_TOMCAT context_path always got ROOT.xml regardless of config. Tomcat convention: /foo/bar → foo#bar.xml (strip leading /, replace / with #). Empty or / → ROOT.xml (root context, existing default). Changes: - Add ContextPath field to Tomcat config struct (yaml:"context_path") - Add contextXMLFilename() helper implementing the path→filename transform - Finalize() loads config if not already loaded (Supply() may not have run in all call paths), computes XML filename from context_path - Three new tests (TDD): context_path set, empty, and / Fixes cloudfoundry#1331.
There was a problem hiding this comment.
Pull request overview
Restores support for configuring Tomcat’s deployment context via JBP_CONFIG_TOMCAT.tomcat.context_path, matching the legacy Ruby buildpack behavior (and fixing #1331) by creating the appropriate context XML filename instead of always writing ROOT.xml.
Changes:
- Add
ContextPathto the Tomcat config struct and derive the context XML filename from it. - Update
Finalize()to write the context XML to the computed filename. - Add unit tests covering configured, empty, and
/context paths.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/java/containers/tomcat.go |
Adds context_path config support and uses it during Finalize() to select the context XML filename. |
src/java/containers/tomcat_test.go |
Adds Finalize() tests validating filename selection for configured/empty/root context paths. |
Comments suppressed due to low confidence (1)
src/java/containers/tomcat.go:617
- The write error message still says
failed to write ROOT.xml, but the target file may be something else whencontext_pathis configured. This will make failures harder to diagnose.
if err := os.WriteFile(contextXMLPath, []byte(contextContent), 0644); err != nil {
return fmt.Errorf("failed to write ROOT.xml: %w", err)
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…igured; add explicit empty context_path test
|
Note: Ruby buildpack (4.x) deploys the app into Go buildpack (5.x) uses Tomcat context descriptor files ( User-visible URL routing is identical: the application is accessible only at the configured path. Potential behavioral difference: Question for reviewers: Is this Details added to |
…d Go buildpack (§2A.11)
|
Finding: Current
But Also integration test named “WAR file” does not deploy real ROOT.xml history matters here: current buildpack writes
Without that, PR fixes happy path only, not full ROOT.xml/context_path problem. |
…r context_path - Finalize() now writes context XML for packaged .war apps (docBase points to the WAR file), so context_path works for both exploded and packaged WARs - Skip writing context XML if the file already exists (external config via external_configuration_enabled provides its own context descriptor) - Unit tests (TDD): 4 new tests covering WAR path, external-config guard - Integration test: verify context_path routes /my/app correctly and / returns 404
…s Tomcat default page not 404
…on-root context_path - os.Stat unexpected errors (non-IsNotExist) now returned as failures instead of silently treating the context XML as already existing - ROOT.xml removal now happens regardless of whether context XML was generated or already existed from external config, so non-root context_path always removes a stale ROOT.xml - Unit test added (TDD) for external-config + non-root ROOT.xml removal
|
@ramonskie thanks for the info, updates the PR and code based on your feedback, please have a look |
| return fmt.Errorf("failed to remove ROOT.xml: %w", err) | ||
| } | ||
| } | ||
| } else { |
| } | ||
| } else { | ||
| warMatches, err := filepath.Glob(filepath.Join(buildDir, "*.war")) | ||
| if err == nil && len(warMatches) == 1 { |
| } | ||
| } | ||
| } else if len(warMatches) > 1 { | ||
| t.context.Log.Warning("Multiple WAR files found in build directory; context_path not applied") |
Summary
Restores
context_path\support from the Ruby buildpack. Users settingJBP_CONFIG_TOMCAT: {tomcat: {context_path: /foo/bar}}always gotROOT.xmland their app deployed at/— the field was never ported to the Go rewrite.Changes
ContextPathfield toTomcatconfig structcontextXMLFilename()helper:/foo/bar→foo#bar.xml(Tomcat convention)Finalize()reads config and writes the correct context descriptor:WEB-INF/present):docBase="${user.home}/app"*.warpresent):docBase="${user.home}/app/<name>.war"/context path →ROOT.xml(unchanged default)context_pathnormalisedROOT.xmlremoved to avoid ambiguous deploymentexternal_configuration_enabled), the generated one is skipped — external config winsRUBY_VS_GO_BUILDPACK_COMPARISON.mdupdated with context_path parity note and mechanism difference (§2A.2, §2A.11)Fixes #1331.
Tests
Unit tests (
tomcat_test.go, TDD):context_path: /the/intended/path→the#intended#path.xmlcreated,ROOT.xmlabsent/context path →ROOT.xmlROOT.xmlremoved when non-root context path setJBP_CONFIG_TOMCAT→ROOT.xmlcontext_path→ context XML withdocBasepointing to WAR filecontext_path→ROOT.xmlwith WARdocBaseROOT.xmlIntegration test (
src/integration/tomcat_test.go):tomcat_jakartafixture withcontext_path: /my/app, verifies/my/appserves app content and/does not