Skip to content

Commit 8b8a869

Browse files
authored
dag: Allow multiple pipeline dirs (#1899)
We can pass multiple pipeline dirs for melange configs, so we should accept multiple in dag.NewPackages. Signed-off-by: Jon Johnson <jon.johnson@chainguard.dev>
1 parent 19b64c4 commit 8b8a869

7 files changed

Lines changed: 27 additions & 25 deletions

File tree

docs/cmd/wolfictl_dot.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Open browser to explore crane's deps recursively, only showing a minimum subgrap
3434
-d, --dir string directory to search for melange configs (default ".")
3535
-h, --help help for dot
3636
-k, --keyring-append strings path to extra keys to include in the build environment keyring (default [https://packages.wolfi.dev/os/wolfi-signing.rsa.pub])
37-
--pipeline-dir string directory used to extend defined built-in pipelines
37+
--pipeline-dir strings directory used to extend defined built-in pipelines
3838
-R, --recursive recurse through package dependencies
3939
-r, --repository-append strings path to extra repositories to include in the build environment (default [https://packages.wolfi.dev/os])
4040
-D, --show-dependents show packages that depend on these packages, instead of these packages' dependencies

docs/man/man1/wolfictl-dot.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ wolfictl dot \-\-web \-R \-S crane
5454
path to extra keys to include in the build environment keyring
5555

5656
.PP
57-
\fB\-\-pipeline\-dir\fP=""
57+
\fB\-\-pipeline\-dir\fP=[]
5858
directory used to extend defined built\-in pipelines
5959

6060
.PP

pkg/cli/dot.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import (
2121
)
2222

2323
func cmdSVG() *cobra.Command { //nolint:gocyclo
24-
var dir, pipelineDir string
24+
var dir string
25+
var pipelineDirs []string
2526
var showDependents, recursive, span, web bool
2627
var extraKeys, extraRepos []string
2728
d := &cobra.Command{
@@ -47,11 +48,11 @@ Open browser to explore crane's deps recursively, only showing a minimum subgrap
4748
`,
4849
RunE: func(cmd *cobra.Command, args []string) error {
4950
ctx := cmd.Context()
50-
if pipelineDir == "" {
51-
pipelineDir = filepath.Join(dir, "pipelines")
51+
if len(pipelineDirs) == 0 {
52+
pipelineDirs = []string{filepath.Join(dir, "pipelines")}
5253
}
5354

54-
pkgs, err := dag.NewPackages(ctx, os.DirFS(dir), dir, pipelineDir)
55+
pkgs, err := dag.NewPackages(ctx, os.DirFS(dir), dir, pipelineDirs)
5556
if err != nil {
5657
return fmt.Errorf("NewPackages: %w", err)
5758
}
@@ -298,7 +299,7 @@ Open browser to explore crane's deps recursively, only showing a minimum subgrap
298299
},
299300
}
300301
d.Flags().StringVarP(&dir, "dir", "d", ".", "directory to search for melange configs")
301-
d.Flags().StringVar(&pipelineDir, "pipeline-dir", "", "directory used to extend defined built-in pipelines")
302+
d.Flags().StringSliceVar(&pipelineDirs, "pipeline-dir", nil, "directory used to extend defined built-in pipelines")
302303
d.Flags().BoolVarP(&showDependents, "show-dependents", "D", false, "show packages that depend on these packages, instead of these packages' dependencies")
303304
d.Flags().BoolVarP(&recursive, "recursive", "R", false, "recurse through package dependencies")
304305
d.Flags().BoolVarP(&span, "spanning-tree", "S", false, "does something like a spanning tree to avoid a huge number of edges")

pkg/cli/text.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import (
1313
)
1414

1515
func cmdText() *cobra.Command {
16-
var dir, pipelineDir, arch, t string
16+
var dir, arch, t string
17+
var pipelineDirs []string
1718
var extraKeys, extraRepos []string
1819
text := &cobra.Command{
1920
Use: "text",
@@ -27,13 +28,13 @@ If this fails, there may be an unsatisfiable dependency or a cycle in the graph.
2728
Hidden: true,
2829
RunE: func(cmd *cobra.Command, _ []string) error {
2930
ctx := cmd.Context()
30-
if pipelineDir == "" {
31-
pipelineDir = filepath.Join(dir, "pipelines")
31+
if len(pipelineDirs) == 0 {
32+
pipelineDirs = []string{filepath.Join(dir, "pipelines")}
3233
}
3334

3435
arch := types.ParseArchitecture(arch).ToAPK()
3536

36-
pkgs, err := dag.NewPackages(ctx, os.DirFS(dir), dir, pipelineDir)
37+
pkgs, err := dag.NewPackages(ctx, os.DirFS(dir), dir, pipelineDirs)
3738
if err != nil {
3839
return fmt.Errorf("constructing new package set from directory %q: %w", dir, err)
3940
}
@@ -49,7 +50,7 @@ If this fails, there may be an unsatisfiable dependency or a cycle in the graph.
4950
},
5051
}
5152
text.Flags().StringVarP(&dir, "dir", "d", ".", "directory to search for melange configs")
52-
text.Flags().StringVar(&pipelineDir, "pipeline-dir", "", "directory used to extend defined built-in pipelines")
53+
text.Flags().StringSliceVar(&pipelineDirs, "pipeline-dir", nil, "directory used to extend defined built-in pipelines")
5354
text.Flags().StringVarP(&arch, "arch", "a", "x86_64", "architecture to build for")
5455
text.Flags().StringVarP(&t, "type", "t", string(typeTarget), fmt.Sprintf("What type of text to emit; values can be one of: %v", textTypes))
5556
text.Flags().StringSliceVarP(&extraKeys, "keyring-append", "k", []string{"https://packages.wolfi.dev/os/wolfi-signing.rsa.pub"}, "path to extra keys to include in the build environment keyring")

pkg/dag/graph_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func TestNewGraph(t *testing.T) {
2323
testDir = "testdata/basic"
2424
)
2525
t.Run("allowed dangling", func(t *testing.T) {
26-
pkgs, err := NewPackages(ctx, os.DirFS(testDir), testDir, "")
26+
pkgs, err := NewPackages(ctx, os.DirFS(testDir), testDir, nil)
2727
require.NoError(t, err)
2828
graph, err := NewGraph(ctx, pkgs, WithAllowUnresolved())
2929
require.NoError(t, err)
@@ -54,7 +54,7 @@ func TestNewGraph(t *testing.T) {
5454
}
5555
})
5656
t.Run("has expected tree", func(t *testing.T) {
57-
pkgs, err := NewPackages(ctx, os.DirFS(testDir), testDir, "")
57+
pkgs, err := NewPackages(ctx, os.DirFS(testDir), testDir, nil)
5858
require.NoError(t, err)
5959
graph, err := NewGraph(ctx, pkgs, WithRepos(packageRepo), WithKeys(key))
6060
require.NoError(t, err)
@@ -93,13 +93,13 @@ func TestNewGraph(t *testing.T) {
9393
ctx := context.Background()
9494
var testDir = "testdata/multiple"
9595
t.Run("allowed dangling", func(t *testing.T) {
96-
pkgs, err := NewPackages(ctx, os.DirFS(testDir), testDir, "")
96+
pkgs, err := NewPackages(ctx, os.DirFS(testDir), testDir, nil)
9797
require.NoError(t, err)
9898
_, err = NewGraph(ctx, pkgs, WithAllowUnresolved())
9999
require.NoError(t, err)
100100
})
101101
t.Run("external dependencies only", func(t *testing.T) {
102-
pkgs, err := NewPackages(ctx, os.DirFS(testDir), testDir, "")
102+
pkgs, err := NewPackages(ctx, os.DirFS(testDir), testDir, nil)
103103
require.NoError(t, err)
104104
graph, err := NewGraph(ctx, pkgs, WithRepos(packageRepo), WithKeys(key))
105105
require.NoError(t, err)
@@ -134,7 +134,7 @@ func TestNewGraph(t *testing.T) {
134134
}
135135
})
136136
t.Run("internal and external dependencies", func(t *testing.T) {
137-
pkgs, err := NewPackages(ctx, os.DirFS(testDir), testDir, "")
137+
pkgs, err := NewPackages(ctx, os.DirFS(testDir), testDir, nil)
138138
require.NoError(t, err)
139139
graph, err := NewGraph(ctx, pkgs, WithRepos(packageRepo), WithKeys(key))
140140
require.NoError(t, err)
@@ -180,7 +180,7 @@ func TestNewGraph(t *testing.T) {
180180
})
181181

182182
t.Run("internal dependencies numbered", func(t *testing.T) {
183-
pkgs, err := NewPackages(ctx, os.DirFS(testDir), testDir, "")
183+
pkgs, err := NewPackages(ctx, os.DirFS(testDir), testDir, nil)
184184
require.NoError(t, err)
185185
graph, err := NewGraph(ctx, pkgs, WithRepos(packageRepo), WithKeys(key))
186186
require.NoError(t, err)
@@ -242,7 +242,7 @@ func TestNewGraph(t *testing.T) {
242242
"d": {"a:1.3.5-r1@local"},
243243
}
244244
)
245-
pkgs, err := NewPackages(ctx, os.DirFS(testDir), testDir, "")
245+
pkgs, err := NewPackages(ctx, os.DirFS(testDir), testDir, nil)
246246
require.NoError(t, err)
247247
graph, err := NewGraph(ctx, pkgs, WithRepos(cyclePackageRepo), WithKeys(cycleKey))
248248
require.NoError(t, err)
@@ -266,7 +266,7 @@ func TestTargets(t *testing.T) {
266266
ctx := context.Background()
267267
testDir := "testdata/subpackages"
268268

269-
pkgs, err := NewPackages(ctx, os.DirFS(testDir), testDir, "")
269+
pkgs, err := NewPackages(ctx, os.DirFS(testDir), testDir, nil)
270270
require.NoError(t, err)
271271
graph, err := NewGraph(ctx, pkgs, WithAllowUnresolved())
272272
require.NoError(t, err)

pkg/dag/packages.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,11 @@ func (p *Packages) addProvides(c *Configuration, provides []string) error {
144144
// The input is any fs.FS filesystem implementation. Given a directory path, you
145145
// can call NewPackages like this:
146146
//
147-
// NewPackages(ctx, os.DirFS("/path/to/dir"), "/path/to/dir", "./pipelines")
147+
// NewPackages(ctx, os.DirFS("/path/to/dir"), "/path/to/dir", []string{"./pipelines"})
148148
//
149149
// The repetition of the path is necessary because of how the upstream parser in
150150
// melange requires the full path to the directory to be passed in.
151-
func NewPackages(ctx context.Context, fsys fs.FS, dirPath, pipelineDir string) (*Packages, error) {
151+
func NewPackages(ctx context.Context, fsys fs.FS, dirPath string, pipelineDirs []string) (*Packages, error) {
152152
log := clog.FromContext(ctx)
153153

154154
pkgs := &Packages{
@@ -240,7 +240,7 @@ func NewPackages(ctx context.Context, fsys fs.FS, dirPath, pipelineDir string) (
240240
// Resolve all `uses` used by the pipeline. This updates the set of
241241
// .environment.contents.packages so the next block can include those as build deps.
242242
build := &build.Build{
243-
PipelineDirs: []string{pipelineDir},
243+
PipelineDirs: pipelineDirs,
244244
Configuration: c.Configuration,
245245
}
246246
if err := build.Compile(ctx); err != nil {

pkg/dag/packages_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func TestNewPackages(t *testing.T) {
1212
ctx := context.Background()
1313

1414
testdir := "testdata/multiple"
15-
pkgs, err := NewPackages(ctx, os.DirFS(testdir), testdir, "")
15+
pkgs, err := NewPackages(ctx, os.DirFS(testdir), testdir, nil)
1616
require.NoError(t, err)
1717

1818
t.Run("loads data correctly", func(t *testing.T) {
@@ -31,7 +31,7 @@ func TestNewPackages(t *testing.T) {
3131

3232
t.Run("multiple configurations using the same package name", func(t *testing.T) {
3333
testdir = "testdata/duplicate"
34-
pkgs, err = NewPackages(ctx, os.DirFS(testdir), testdir, "")
34+
pkgs, err = NewPackages(ctx, os.DirFS(testdir), testdir, nil)
3535
if err == nil {
3636
t.Error("should yield an error but got nil")
3737
}

0 commit comments

Comments
 (0)