Ctrl K
ComunidadGuías…

builder/build/cnb/lang_static.go

Rama main · réplica de lectura del repositorio original.

Archivo original ↗Preguntar a KiBot
package cnb

import (
	"os"
	"path/filepath"

	"github.com/goodrain/rainbond/builder/build"
	"github.com/goodrain/rainbond/util"
	"github.com/sirupsen/logrus"
	corev1 "k8s.io/api/core/v1"
)

// staticConfig implements LanguageConfig for pure static projects (no package.json).
type staticConfig struct{}

// BuildAnnotations configures nginx web server for static file serving.
func (s *staticConfig) BuildAnnotations(re *build.Request, annotations map[string]string) {
	applyDependencyMirrorAnnotation(annotations)

	// BP_WEB_SERVER=nginx tells Paketo to overwrite nginx.conf with generated
	// defaults. Without it, the nginx buildpack detects and uses the project file.
	if re.SourceDir != "" {
		if info, err := os.Stat(filepath.Join(re.SourceDir, "nginx.conf")); err == nil && info.Mode().IsRegular() {
			logrus.Info("Pure static project: using project nginx.conf")
			return
		}
	}

	outputDir := re.BuildEnvs["CNB_OUTPUT_DIR"]
	if outputDir == "" {
		outputDir = "."
	}
	annotations["cnb-bp-web-server"] = "nginx"
	annotations["cnb-bp-web-server-root"] = outputDir
	annotations["cnb-bp-web-server-enable-push-state"] = "true"

	logrus.Infof("Pure static project: nginx web server at '%s', mirror=%s", outputDir, annotations["cnb-bp-dependency-mirror"])
}

func (s *staticConfig) BuildEnvVars(re *build.Request) []corev1.EnvVar {
	return nil
}

// InjectMirrorConfig is a no-op for static projects (no package manager).
func (s *staticConfig) InjectMirrorConfig(re *build.Request) error {
	return nil
}

// CustomOrder returns nginx-only buildpack order for static projects.
func (s *staticConfig) CustomOrder(re *build.Request) []orderBuildpack {
	version := util.GetenvDefault("CNB_NGINX_BUILDPACK_VERSION", "1.0.12")
	return []orderBuildpack{
		{ID: "paketo-buildpacks/nginx", Version: version},
	}
}

// isPureStaticProject checks if the source directory has no package.json.
func isPureStaticProject(sourceDir string) bool {
	packageJSONPath := filepath.Join(sourceDir, "package.json")
	_, err := os.Stat(packageJSONPath)
	return os.IsNotExist(err)
}