MCPcopy Index your code
hub / github.com/cloudfoundry/java-buildpack / writeReleaseYaml

Method writeReleaseYaml

src/java/finalize/finalize.go:256–297  ·  view source on GitHub ↗

writeReleaseYaml writes the release configuration to a YAML file

(container containers.Container)

Source from the content-addressed store, hash-verified

254
255// writeReleaseYaml writes the release configuration to a YAML file
256func (f *Finalizer) writeReleaseYaml(container containers.Container) error {
257 f.Log.BeginStep("Writing release configuration")
258
259 containerCommand, err := container.Release()
260 if err != nil {
261 return fmt.Errorf("failed to get container command: %w", err)
262 }
263
264 var fullCommand string
265 if f.JRE != nil {
266 memCalcCmd := f.JRE.MemoryCalculatorCommand()
267 if memCalcCmd != "" {
268 fullCommand = memCalcCmd + " && " + containerCommand
269 f.Log.Debug("Prepended memory calculator command to startup")
270 } else {
271 fullCommand = containerCommand
272 }
273 } else {
274 fullCommand = containerCommand
275 }
276
277 tmpDir := filepath.Join(f.Stager.BuildDir(), "tmp")
278 if err := os.MkdirAll(tmpDir, 0755); err != nil {
279 return fmt.Errorf("failed to create tmp directory: %w", err)
280 }
281
282 releaseYamlPath := filepath.Join(tmpDir, "java-buildpack-release-step.yml")
283 escapedCommand := strings.ReplaceAll(fullCommand, "'", "''")
284 yamlContent := fmt.Sprintf(`---
285default_process_types:
286 web: '%s'
287 task: '%s'
288`, escapedCommand, escapedCommand)
289
290 if err := os.WriteFile(releaseYamlPath, []byte(yamlContent), 0644); err != nil {
291 return fmt.Errorf("failed to write release YAML: %w", err)
292 }
293
294 f.Log.Info("Release YAML written: %s", releaseYamlPath)
295 f.Log.Info("Web process command: %s", fullCommand)
296 return nil
297}

Callers 1

RunFunction · 0.80

Calls 3

ReleaseMethod · 0.65
BuildDirMethod · 0.65

Tested by

no test coverage detected