Documentation
¶
Overview ¶
Package docksmith detects application frameworks and generates production-ready Dockerfiles.
The pipeline has three stages:
fw, err := docksmith.Detect("/path/to/project")
plan := docksmith.Plan(fw)
dockerfile := docksmith.EmitDockerfile(plan)
Each stage is independently useful. Detect analyzes project files to identify the framework and runtime. Plan converts a Framework into abstract build steps. EmitDockerfile serializes a plan into a multi-stage Dockerfile with cache mounts and non-root users.
Detection supports 45 frameworks across 12 runtimes. Custom frameworks can be added via YAML definitions or RegisterDetector.
Index ¶
- Constants
- Variables
- func EmitDockerfile(p *BuildPlan) string
- func GenerateDockerfile(fw *Framework, opts ...PlanOption) (string, error)
- func GenerateDockerignore(fw *Framework) string
- func LoadAndRegisterFrameworks(dirs ...string) error
- func NewAutoFetch(afo AutoFetchOptions) func(dir string) (*core.Framework, error)
- func RegisterDetector(name string, d DetectorFunc)
- func RegisterDetectorBefore(before, name string, d DetectorFunc)
- func RunFrameworkDefTests(def *FrameworkDef) error
- type AutoFetchOptions
- type BuildConfig
- type BuildPlan
- type CacheMount
- type Config
- type CopyFrom
- type CopyFromDef
- type DefaultsDef
- type DetectOptions
- type DetectRule
- type DetectRules
- type DetectorFunc
- type Framework
- func Build(dir string, opts ...PlanOption) (string, *Framework, error)
- func BuildWithOptions(dir string, detectOpts DetectOptions, planOpts ...PlanOption) (string, *Framework, error)
- func ConfigToFramework(c *config.Config) *Framework
- func Detect(dir string) (*Framework, error)
- func DetectWithOptions(dir string, opts DetectOptions) (*Framework, error)
- type FrameworkDef
- type InstallConfig
- type NamedDetector
- type PMConfig
- type PMSource
- type PlanDef
- type PlanOption
- type RegistryEntry
- type RegistryIndex
- type RuntimeCfg
- type SecretConfig
- type SecretDef
- type SecretMount
- type Stage
- type StageDef
- type StartConfig
- type Step
- type StepDef
- type StepType
- type TestCase
- type TestExpect
- type TestResult
- type VersionConfig
- type VersionSource
Constants ¶
const ( StepWorkdir = core.StepWorkdir StepCopy = core.StepCopy StepCopyFrom = core.StepCopyFrom StepRun = core.StepRun StepEnv = core.StepEnv StepArg = core.StepArg StepExpose = core.StepExpose StepCmd = core.StepCmd StepEntrypoint = core.StepEntrypoint StepUser = core.StepUser StepHealthcheck = core.StepHealthcheck )
const DefaultRegistryURL = registry.DefaultRegistryURL
Registry types
Variables ¶
var ( ErrNotDetected = core.ErrNotDetected ErrInvalidConfig = core.ErrInvalidConfig ErrInvalidPlan = core.ErrInvalidPlan )
var ( WithUser = plan.WithUser WithHealthcheck = plan.WithHealthcheck WithHealthcheckDisabled = plan.WithHealthcheckDisabled WithRuntimeImage = plan.WithRuntimeImage WithBaseImage = plan.WithBaseImage WithEntrypoint = plan.WithEntrypoint WithExtraEnv = plan.WithExtraEnv WithExpose = plan.WithExpose WithInstallCommand = plan.WithInstallCommand WithBuildCommand = plan.WithBuildCommand WithStartCommand = plan.WithStartCommand WithSystemDeps = plan.WithSystemDeps WithBuildCacheDisabled = plan.WithBuildCacheDisabled WithSecrets = plan.WithSecrets WithContextRoot = plan.WithContextRoot )
Plan option constructors
var ApplySecretMounts = plan.ApplySecretMounts
var BuildkitCacheArgs = plan.BuildkitCacheArgs
var CacheDir = plan.CacheDir
var FetchRegistryIndex = registry.FetchIndex
Registry function aliases
var FrameworkDefaults = plan.FrameworkDefaults
var FrameworkFromJSON = core.FrameworkFromJSON
var InstallFramework = registry.InstallFramework
var ResolveDockerTag = plan.ResolveDockerTag
var SearchRegistry = registry.Search
var SecretBuildHint = plan.SecretBuildHint
var SecretIgnoreFiles = plan.SecretIgnoreFiles
var ValidateContextRoot = config.ValidateContextRoot
Functions ¶
func EmitDockerfile ¶
EmitDockerfile serializes a BuildPlan into a Dockerfile string.
func GenerateDockerfile ¶
func GenerateDockerfile(fw *Framework, opts ...PlanOption) (string, error)
GenerateDockerfile runs Plan + EmitDockerfile for the given framework. Returns ("", nil) when fw.Name == "dockerfile" (user already has one).
func GenerateDockerignore ¶
GenerateDockerignore returns .dockerignore file content tailored to the framework.
func LoadAndRegisterFrameworks ¶
LoadAndRegisterFrameworks loads YAML defs from each dir (in order) and registers them as detectors. Resolution order after registration:
- .docksmith/frameworks/ in project dir (call with project path first)
- ~/.docksmith/frameworks/ (call with home path second)
- Built-in Go detectors (already registered at init time)
YAML detectors are prepended, so the last dir passed has lowest YAML priority. Dirs that don't exist are silently skipped.
func NewAutoFetch ¶
func NewAutoFetch(afo AutoFetchOptions) func(dir string) (*core.Framework, error)
NewAutoFetch returns a callback suitable for DetectOptions.AutoFetch. It searches the community registry, installs a matching framework, reloads YAML defs, and re-detects. Returns (nil, nil) on miss or network failure.
func RegisterDetector ¶
func RegisterDetector(name string, d DetectorFunc)
RegisterDetector prepends d to the registry.
func RegisterDetectorBefore ¶
func RegisterDetectorBefore(before, name string, d DetectorFunc)
RegisterDetectorBefore inserts d immediately before the named detector.
func RunFrameworkDefTests ¶
func RunFrameworkDefTests(def *FrameworkDef) error
RunFrameworkDefTests delegates to yamldef.RunFrameworkDefTests.
Types ¶
type AutoFetchOptions ¶
type AutoFetchOptions struct {
RegistryURL string
Interactive bool
ConfirmInstall func(name, description string) bool
}
AutoFetchOptions configures the registry auto-fetch callback returned by NewAutoFetch. Pass the result as DetectOptions.AutoFetch.
type BuildConfig ¶
type BuildConfig = config.BuildConfig
type BuildPlan ¶
func BuildPlanFromDef ¶
func BuildPlanFromDef(def *FrameworkDef, fw *Framework) (*BuildPlan, error)
BuildPlanFromDef converts a FrameworkDef into a BuildPlan. It resolves Base fields via ResolveDockerTag and converts StepDefs to Steps.
func BuildPlanFromDefDir ¶
func BuildPlanFromDefDir(def *FrameworkDef, dir string) (*BuildPlan, error)
BuildPlanFromDefDir builds a BuildPlan from a FrameworkDef by resolving version and package manager from the given project directory.
type CacheMount ¶
type CacheMount = core.CacheMount
type Config ¶
Config types
func LoadConfig ¶
LoadConfig reads the first matching config file from dir. Returns (nil, nil) if no config file exists.
type CopyFromDef ¶
type CopyFromDef = yamldef.CopyFromDef
type DefaultsDef ¶
type DefaultsDef = yamldef.DefaultsDef
type DetectOptions ¶
type DetectOptions = detect.DetectOptions
type DetectRule ¶
type DetectRule = yamldef.DetectRule
type DetectRules ¶
type DetectRules = yamldef.DetectRules
type DetectorFunc ¶
type DetectorFunc = core.DetectorFunc
type Framework ¶
func Build ¶
func Build(dir string, opts ...PlanOption) (string, *Framework, error)
Build runs the full pipeline for dir: detect -> plan -> emit.
func BuildWithOptions ¶
func BuildWithOptions(dir string, detectOpts DetectOptions, planOpts ...PlanOption) (string, *Framework, error)
BuildWithOptions runs the pipeline with custom detection options. When private registry indicators are found, secret mounts are wired into the plan and a build hint comment is prepended to the Dockerfile.
func ConfigToFramework ¶
ConfigToFramework converts a Config to a Framework for Dockerfile generation.
func DetectWithOptions ¶
func DetectWithOptions(dir string, opts DetectOptions) (*Framework, error)
DetectWithOptions runs detection with custom options.
type FrameworkDef ¶
type FrameworkDef = yamldef.FrameworkDef
YAML definition types
func LoadFrameworkDefs ¶
func LoadFrameworkDefs(dir string) ([]*FrameworkDef, error)
LoadFrameworkDefs loads YAML framework definitions from dir.
type InstallConfig ¶
type InstallConfig = config.InstallConfig
type PlanOption ¶
type PlanOption = plan.PlanOption
Plan option type
func ConfigToPlanOptions ¶
func ConfigToPlanOptions(c *Config) ([]PlanOption, error)
ConfigToPlanOptions converts Config fields into a PlanOption slice.
func LoadPlanOptions ¶
func LoadPlanOptions(dir string) ([]PlanOption, error)
LoadPlanOptions reads the config from dir and converts it to a PlanOption slice. Returns nil (not an error) when no config file exists.
type RegistryEntry ¶
type RegistryIndex ¶
type RuntimeCfg ¶
type RuntimeCfg = config.RuntimeCfg
type SecretConfig ¶
type SecretConfig = config.SecretConfig
type SecretMount ¶
type SecretMount = core.SecretMount
type StartConfig ¶
type StartConfig = config.StartConfig
type TestExpect ¶
type TestExpect = yamldef.TestExpect
type TestResult ¶
type TestResult = yamldef.TestResult
func RunFrameworkTests ¶
func RunFrameworkTests(yamlPath string) ([]TestResult, error)
RunFrameworkTests delegates to yamldef.RunFrameworkTests.
type VersionConfig ¶
type VersionConfig = yamldef.VersionConfig
type VersionSource ¶
type VersionSource = yamldef.VersionSource
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
docksmith
command
|
|
|
Package core defines the shared types used across all docksmith layers: Framework (detection result), BuildPlan (abstract build steps), Stage, Step, CacheMount, and SecretMount.
|
Package core defines the shared types used across all docksmith layers: Framework (detection result), BuildPlan (abstract build steps), Stage, Step, CacheMount, and SecretMount. |
|
Package detect identifies application frameworks from project files.
|
Package detect identifies application frameworks from project files. |
|
Package emit serializes a BuildPlan into a Dockerfile string.
|
Package emit serializes a BuildPlan into a Dockerfile string. |
|
examples
|
|
|
config-file
command
Command config-file shows how to load a docksmith.toml config file and use it to drive Dockerfile generation.
|
Command config-file shows how to load a docksmith.toml config file and use it to drive Dockerfile generation. |
|
custom-detector
command
Command custom-detector shows how to register a custom framework detector.
|
Command custom-detector shows how to register a custom framework detector. |
|
detect
command
Command detect shows how to detect the framework for a project directory.
|
Command detect shows how to detect the framework for a project directory. |
|
generate
command
Command generate detects a project's framework and prints a production Dockerfile.
|
Command generate detects a project's framework and prints a production Dockerfile. |
|
pipeline
command
Command pipeline demonstrates each stage of docksmith separately: detect -> plan -> emit.
|
Command pipeline demonstrates each stage of docksmith separately: detect -> plan -> emit. |
|
with-overrides
command
Command with-overrides shows how to customize Dockerfile generation using PlanOption overrides.
|
Command with-overrides shows how to customize Dockerfile generation using PlanOption overrides. |
|
Package plan converts a detected Framework into an abstract BuildPlan.
|
Package plan converts a detected Framework into an abstract BuildPlan. |
|
Package yamldef defines the YAML-driven framework definition schema and evaluation logic for docksmith's extensible detection system.
|
Package yamldef defines the YAML-driven framework definition schema and evaluation logic for docksmith's extensible detection system. |