How siderolabs/bldr works
Main Components
• CLI Frontend: Under cmd/bldr, this is the entry point for users—handling commands like build, validate, graph, and llb.
• Package Loader & Parser: This component is responsible for loading “Pkgfile”, “pkg.yaml”, and “vars.yaml” files from the project directory. This is implemented in the internal/pkg/pkgfile and related conversion modules (under internal/pkg/convert).
• Dependency Resolver & Graph Generator: Found in modules under internal/pkg/solver and internal/pkg/integration (for tests and graph generation). This piece resolves both internal package dependencies and external image dependencies, and creates an LLB dependency graph (which can be rendered with Graphviz).
• Build Flow Manager: This component orchestrates the multiple build phases (sources, prepare, build, install, test, finalize) as described in the README. It coordinates the integration with BuildKit (and docker buildx) and manages the build context and environment setup (including environment variables and caching via internal/pkg/environment).
• Update & Upgrade Subsystems: Modules such as internal/pkg/update and internal/pkg/upgrade handle versioning, update operations, and integration with external repositories (like GitHub).
• Utility Modules: Under internal/pkg/util, shared helper functions (including testing utilities) are spread out to support the primary components.
Relationships and Data Flow
• The CLI Frontend receives the user’s command and parameters.
• It reads the “Pkgfile” at the root (global build configuration) and then scans the subdirectories for package directories by detecting pkg.yaml files.
• The Package Loader then parses these definitions (with templating using Go’s text/template) and hands off the data.
• The Build Flow Manager uses this data to generate an LLB graph that orchestrates the entire build process: downloading resources, setting up the environment, executing build steps, and finally finalizing the output.
• Upon completion, the result can be saved to cache, pushed to a container registry, or otherwise output as specified.
Architectural Patterns and Design Principles
• Modular Design: The system is clearly divided into modules (conversion, solver, update, integration, environment) making it easier to test, maintain, and extend.
• Pipeline Processing: The build flow is set up as a series of phases (download, prepare, build, install, test, finalize) that form a pipeline following BuildKit’s LLB stages.
• Declarative Configuration: Using YAML files for defining build instructions promotes a declarative approach.
• Dependency Injection and Template Engine Usage: Integrating variables from global (Pkgfile) and local (vars.yaml) contexts using Go’s templating engine is a key design aspect.
• Graph-based Build Dependency Resolution: The creation and rendering of dependency graphs (in Graphviz format) is central to understanding the build flow.
Relevant Technologies, Frameworks, or Libraries
• Golang (for the implementation)
• BuildKit (and docker buildx) for backend builds
• Graphviz for dependency graph rendering (as shown by the “bldr graph” command)
• (Go) Text/template and functions from the Sprig library for templating across YAML files