Skip to content

Commit 9613ee4

Browse files
committed
fix: update graph for build-arg support
Support build-arg in graph command, fix filesystem loader for non-root paths (for `docker run`), add automatic filtering out of nodes for e.g. `reproducibility` and `grype-scan` targets. Signed-off-by: Andrey Smirnov <[email protected]>
1 parent 7adc01f commit 9613ee4

File tree

4 files changed

+44
-4
lines changed

4 files changed

+44
-4
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
22
#
3-
# Generated on 2025-08-20T12:12:40Z by kres 18c31cf.
3+
# Generated on 2025-09-04T12:37:31Z by kres 784fa1f.
44

55
concurrency:
66
group: ${{ github.head_ref || github.run_id }}
@@ -32,7 +32,7 @@ jobs:
3232
steps:
3333
- name: gather-system-info
3434
id: system-info
35-
uses: kenchan0130/actions-system-info@v1.4.0
35+
uses: kenchan0130/actions-system-info@v1.3.1
3636
continue-on-error: true
3737
- name: print-system-info
3838
run: |

cmd/bldr/cmd/graph.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,18 @@ package cmd
77
import (
88
"log"
99
"os"
10+
"strings"
1011

1112
"github.com/spf13/cobra"
1213

1314
"github.com/siderolabs/bldr/internal/pkg/solver"
15+
"github.com/siderolabs/bldr/internal/pkg/types/v1alpha2"
1416
)
1517

18+
var graphCmdFlags struct {
19+
buildArgs []string
20+
}
21+
1622
// graphCmd represents the graph command.
1723
var graphCmd = &cobra.Command{
1824
Use: "graph",
@@ -26,16 +32,28 @@ Typical usage:
2632
`,
2733
Args: cobra.NoArgs,
2834
Run: func(_ *cobra.Command, _ []string) {
35+
context := options.GetVariables().Copy()
36+
37+
for _, buildArg := range graphCmdFlags.buildArgs {
38+
name, value, _ := strings.Cut(buildArg, "=")
39+
40+
context["BUILD_ARG_"+name] = value
41+
}
42+
2943
loader := solver.FilesystemPackageLoader{
3044
Root: pkgRoot,
31-
Context: options.GetVariables(),
45+
Context: context,
3246
}
3347

3448
packages, err := solver.NewPackages(&loader)
3549
if err != nil {
3650
log.Fatal(err)
3751
}
3852

53+
packages.FilterInPlace(func(pkg *v1alpha2.Pkg) bool {
54+
return pkg.Context["GRAPH_IGNORE"] != "true"
55+
})
56+
3957
var packageSet solver.PackageSet
4058

4159
if options.Target != "" {
@@ -55,5 +73,6 @@ Typical usage:
5573

5674
func init() {
5775
graphCmd.Flags().StringVarP(&options.Target, "target", "t", "", "Target image to graph, if not set - graph all stages")
76+
graphCmd.Flags().StringSliceVar(&graphCmdFlags.buildArgs, "build-arg", nil, "Build arguments to pass similar to docker buildx")
5877
rootCmd.AddCommand(graphCmd)
5978
}

internal/pkg/solver/filesystem_loader.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,20 @@ func (fspl *FilesystemPackageLoader) attachTemplate(path string) (*v1alpha2.Pkg,
218218
shortestRel string
219219
)
220220

221+
absFile, err := filepath.Abs(path)
222+
if err != nil {
223+
return nil, err
224+
}
225+
226+
relPath, err := filepath.Rel(fspl.absRootPath, absFile)
227+
if err != nil {
228+
return nil, err
229+
}
230+
221231
for _, pkg := range fspl.pkgs {
222-
rel, err := filepath.Rel(pkg.BaseDir, filepath.Dir(path))
232+
var rel string
233+
234+
rel, err = filepath.Rel(pkg.BaseDir, filepath.Dir(relPath))
223235
if err != nil || strings.HasPrefix(rel, "..") {
224236
continue
225237
}

internal/pkg/solver/packages.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ func NewPackages(loader PackageLoader) (*Packages, error) {
4141
return result, nil
4242
}
4343

44+
// FilterInPlace filters packages in place using the given filter function.
45+
func (pkgs *Packages) FilterInPlace(f func(pkg *v1alpha2.Pkg) bool) {
46+
for name, pkg := range pkgs.packages {
47+
if !f(pkg) {
48+
delete(pkgs.packages, name)
49+
}
50+
}
51+
}
52+
4453
func (pkgs *Packages) resolve(name string, path []string, cache map[string]*PackageNode) (*PackageNode, error) {
4554
if node := cache[name]; node != nil {
4655
return node, nil

0 commit comments

Comments
 (0)