func buildFn()

in cmd/php/supervisor/main.go [54:111]


func buildFn(ctx *gcp.Context) error {
	l, err := ctx.Layer("supervisor", gcp.CacheLayer, gcp.LaunchLayerUnlessSkipRuntimeLaunch, gcp.BuildLayer)
	if err != nil {
		return err
	}
	l.LaunchEnvironment.Default("APP_DIR", defaultRoot)

	runtimeConfig, err := appyaml.PhpConfiguration(ctx.ApplicationRoot())
	if err != nil {
		return err
	}

	if err = flex.InstallSupervisor(ctx, l); err != nil {
		return err
	}

	overrides := webconfig.OverriddenProperties(ctx, runtimeConfig)
	webconfig.SetEnvVariables(l, overrides)

	fpmConfFile, err := writeFpmConfig(l.Path, overrides)
	if err != nil {
		return err
	}

	supervisorFiles, err := flex.SupervisorConfFiles(ctx, runtimeConfig, ctx.ApplicationRoot())
	if err != nil {
		return err
	}

	nginxPath := filepath.Join(l.Path, defaultNginxConf)
	// write the nginx configurations if they do not provide an override.
	if !overrides.NginxConfOverride {
		// nginx server section
		nginxServerConf, err := writeNginxServerConfig(l.Path, overrides)
		if err != nil {
			return err
		}
		// the nginx file to start the process.
		supervisorNginxConf := supervisorNginxConfig(nginxServerConf, overrides)

		if _, err = writeTemplateConfigToPath(nginxPath, flex.NginxConfTemplate, supervisorNginxConf); err != nil {
			return err
		}
	} else {
		nginxPath = overrides.NginxConfOverrideFileName
	}

	supervisorPath, err := supervisorLocation(supervisorFiles, nginxPath, fpmConfFile.Name(), l.Path)
	if err != nil {
		return err
	}
	cmd := []string{
		"supervisord", "-c", supervisorPath,
	}

	ctx.AddProcess(gcp.WebProcess, cmd, gcp.AsDefaultProcess())
	return nil
}