func buildFn()

in cmd/php/webconfig/main.go [69:135]


func buildFn(ctx *gcp.Context) error {
	// create webconfig layer
	l, err := ctx.Layer("webconfig", gcp.LaunchLayer)
	if err != nil {
		return fmt.Errorf("creating layer: %w", err)
	}

	if env.IsFlex() {
		runtimeConfig, err := appyaml.PhpConfiguration(ctx.ApplicationRoot())
		if err != nil {
			return err
		}
		overrides = webconfig.OverriddenProperties(ctx, runtimeConfig)
		webconfig.SetEnvVariables(l, overrides)
	}

	if customNginxConf, present := os.LookupEnv(php.CustomNginxConfig); present {
		overrides.NginxConfOverride = true
		overrides.NginxConfOverrideFileName = filepath.Join(defaultRoot, customNginxConf)
	}

	nginxServesStaticFiles, err := env.IsPresentAndTrue(php.NginxServesStaticFiles)
	if err != nil {
		return err
	}
	overrides.NginxServesStaticFiles = nginxServesStaticFiles

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

	nginxServerConfFile, err := writeNginxServerConfig(l.Path, overrides)
	if err != nil {
		return err
	}
	defer nginxServerConfFile.Close()

	procExists, err := ctx.FileExists("Procfile")
	if err != nil {
		return err
	}
	_, entrypointExists := os.LookupEnv(env.Entrypoint)

	if !procExists && !entrypointExists {
		cmd := []string{
			filepath.Join(os.Getenv("PID1_DIR"), "pid1"),
			"--nginxBinaryPath", defaultNginxBinary,
			"--nginxErrLogFilePath", filepath.Join(l.Path, nginxLog),
			"--customAppCmd", fmt.Sprintf("%q", fmt.Sprintf("%s -R --nodaemonize --fpm-config %s", defaultFPMBinary, fpmConfFile.Name())),
			"--pid1LogFilePath", filepath.Join(l.Path, pid1Log),
			// Ideally, we should be able to use the path of the nginx layer and not hardcode it here.
			// This needs some investigation on how to pass values between build steps of buildpacks.
			"--mimeTypesPath", filepath.Join("/layers/google.utils.nginx/nginx", "conf/mime.types"),
		}
		addArgs, err := addNginxConfCmdArgs(l.Path, nginxServerConfFile.Name(), overrides)
		if err != nil {
			return err
		}
		cmd = append(cmd, addArgs...)

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

	return nil
}