stackdetect

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 20, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package stackdetect inspects a local project directory and guesses its framework and how to build it (Dockerfile, Compose, Node.js, Go, Java, Python, or static site), without executing anything from the project.

Index

Examples

Constants

View Source
const (
	BuildDockerfile = "dockerfile"
	BuildRailpack   = "railpack"
	BuildStatic     = "static"
	BuildCompose    = "compose"
)

Build types, matching internal/spec's build.type values.

Variables

This section is empty.

Functions

This section is empty.

Types

type Stack

type Stack struct {
	// Provider is the Railpack provider id, or "dockerfile", "compose",
	// "static", or "" when nothing matched.
	Provider string
	// Label is the human-readable stack name.
	Label string
	// Build is the app.yaml build.type to use, empty when nothing matched.
	Build string
	// Path is build.path, set for dockerfile, compose and static.
	Path string
	// Port is the container port, 0 for static sites and unknown stacks.
	Port int
	// Name is a suggested service name.
	Name string
	// Notes are short hints for the person reading the result.
	Notes []string
}

Stack is the detection result for one project directory.

func Detect

func Detect(dir string) (Stack, error)

Detect inspects dir without executing anything from it. Order: Dockerfile, compose file, package.json, go.mod, Java, Python, static site.

Example
package main

import (
	"fmt"
	"os"
	"path/filepath"

	"github.com/GLINCKER/levelrail/kit/stackdetect"
)

func main() {
	dir, err := os.MkdirTemp("", "app")
	if err != nil {
		panic(err)
	}
	defer func() { _ = os.RemoveAll(dir) }()

	pkg := `{"dependencies":{"express":"4"},"scripts":{"start":"node server.js"}}`
	if err := os.WriteFile(filepath.Join(dir, "package.json"), []byte(pkg), 0o600); err != nil {
		panic(err)
	}

	s, err := stackdetect.Detect(dir)
	if err != nil {
		panic(err)
	}
	fmt.Println(s.Label, s.Build, s.Port, s.Detected())
}
Output:
Node.js (Express) railpack 3000 true

func (Stack) Detected

func (s Stack) Detected() bool

Detected reports whether a buildable stack was found.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL