Skip to content
Permalink
Browse files
feat(images-dependencies): stapel deps configuration for dependencies…
… stage

Signed-off-by: Timofey Kirillov <timofey.kirillov@flant.com>
  • Loading branch information
distorhead committed Jan 31, 2022
1 parent 2de7865 commit 30f06fb0537c508e929b9a6a2adba028982695a8
Showing with 75 additions and 1 deletion.
  1. +12 −1 pkg/build/stage/dependencies.go
  2. +63 −0 pkg/build/stage/dependencies_test.go
@@ -38,7 +38,18 @@ func getImports(imageBaseConfig *config.StapelImageBase, options *getImportsOpti
}

func getDependencies(imageBaseConfig *config.StapelImageBase, options *getImportsOptions) []*config.Dependency {
return nil // TODO(images-dependencies)
var dependencies []*config.Dependency

for _, dep := range imageBaseConfig.Dependencies {
switch {
case dep.Before != "" && string(options.Before) == dep.Before:
dependencies = append(dependencies, dep)
case dep.After != "" && string(options.After) == dep.After:
dependencies = append(dependencies, dep)
}
}

return dependencies
}

func newDependenciesStage(imports []*config.Import, dependencies []*config.Dependency, name StageName, baseStageOptions *NewBaseStageOptions) *DependenciesStage {
@@ -5,6 +5,8 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/werf/werf/pkg/config"
)

var _ = Describe("DependenciesStage", func() {
@@ -200,3 +202,64 @@ var _ = Describe("DependenciesStage", func() {
}),
)
})

var _ = Describe("getDependencies helper", func() {
When("using stapel image dependencies", func() {
It("", func() {
img := &config.StapelImageBase{
Dependencies: []*config.Dependency{
{
ImageName: "one",
Before: "setup",
},
{
ImageName: "two",
Before: "setup",
},
{
ImageName: "three",
Before: "install",
},
{
ImageName: "four",
After: "install",
},
{
ImageName: "five",
After: "install",
},
{
ImageName: "six",
After: "setup",
},
},
}

{
deps := getDependencies(img, &getImportsOptions{Before: "install"})
Expect(len(deps)).To(Equal(1))
Expect(deps[0].ImageName).To(Equal("three"))
}

{
deps := getDependencies(img, &getImportsOptions{After: "install"})
Expect(len(deps)).To(Equal(2))
Expect(deps[0].ImageName).To(Equal("four"))
Expect(deps[1].ImageName).To(Equal("five"))
}

{
deps := getDependencies(img, &getImportsOptions{Before: "setup"})
Expect(len(deps)).To(Equal(2))
Expect(deps[0].ImageName).To(Equal("one"))
Expect(deps[1].ImageName).To(Equal("two"))
}

{
deps := getDependencies(img, &getImportsOptions{After: "setup"})
Expect(len(deps)).To(Equal(1))
Expect(deps[0].ImageName).To(Equal("six"))
}
})
})
})

0 comments on commit 30f06fb

Please sign in to comment.