Skip to content

Commit f874a32

Browse files
authored
fix(build, stapel, import): import from root causes runner to hang (add: /) (#6906)
Signed-off-by: Alexandr Zaytsev <alexandr.zaytsev@flant.com>
1 parent c86bd0c commit f874a32

File tree

5 files changed

+121
-0
lines changed

5 files changed

+121
-0
lines changed

pkg/build/stage/dependencies.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,8 @@ func generateChecksumCommand(from string, includePaths, excludePaths []string, r
382382
findCommandParts = append(findCommandParts, fmt.Sprintf("\\( %s \\)", strings.Join(nameIncludeArgs, " -or ")))
383383
}
384384

385+
excludePaths = append(excludePaths, stapel.CONTAINER_MOUNT_ROOT)
386+
385387
var nameExcludeArgs []string
386388
for _, excludePath := range excludePaths {
387389
formattedPath := util.SafeTrimGlobsAndSlashesFromPath(excludePath)

pkg/config/common.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"github.com/werf/common-go/pkg/util"
1111
)
1212

13+
//go:generate mockgen -source common.go -package config -destination common_mock.go
14+
1315
type rawOrigin interface {
1416
configSection() interface{}
1517
doc() *doc

pkg/config/common_mock.go

Lines changed: 68 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/config/export_base.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ func (c *ExportBase) validate() error {
124124
return newDetailedConfigError("`includePaths: [PATH, ...]|PATH` should be relative paths!", c.raw.rawOrigin.configSection(), c.raw.rawOrigin.doc())
125125
case !allRelativePaths(c.ExcludePaths):
126126
return newDetailedConfigError("`excludePaths: [PATH, ...]|PATH` should be relative paths!", c.raw.rawOrigin.configSection(), c.raw.rawOrigin.doc())
127+
case c.Add == "/" && len(c.IncludePaths) == 0:
128+
return newDetailedConfigError("`add: '/'` requires not empty includePaths to interpret copy sources unambiguously", c.raw.rawOrigin.configSection(), c.raw.rawOrigin.doc())
127129
default:
128130
return nil
129131
}

pkg/config/export_base_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package config
2+
3+
import (
4+
. "github.com/onsi/ginkgo/v2"
5+
. "github.com/onsi/gomega"
6+
"go.uber.org/mock/gomock"
7+
"gopkg.in/yaml.v2"
8+
)
9+
10+
var _ = Describe("ExportBase", func() {
11+
DescribeTable("validate()",
12+
func(yamlMap map[string]any, errMessage string) {
13+
Expect(yamlMap).NotTo(HaveLen(0), "yamlMap should not be empty")
14+
15+
testConfigSection := "test config"
16+
testDoc := &doc{
17+
Content: []byte("some content"),
18+
Line: -1,
19+
RenderFilePath: "some file path",
20+
}
21+
22+
rawOriginMock := NewMockrawOrigin(gomock.NewController(GinkgoT()))
23+
rawOriginMock.EXPECT().configSection().Return(testConfigSection)
24+
rawOriginMock.EXPECT().doc().Return(testDoc)
25+
26+
rawExBase := &rawExportBase{rawOrigin: rawOriginMock}
27+
exBase := &ExportBase{raw: rawExBase}
28+
29+
rawYaml, err := yaml.Marshal(yamlMap)
30+
Expect(err).To(Succeed())
31+
32+
Expect(yaml.UnmarshalStrict(rawYaml, &exBase)).To(Succeed())
33+
34+
expectedErr := newDetailedConfigError(errMessage, testConfigSection, testDoc)
35+
36+
Expect(exBase.validate()).To(Equal(expectedErr))
37+
},
38+
Entry(
39+
"should return err if b.Add = / and b.IncludePaths=[]",
40+
map[string]any{
41+
"add": "/",
42+
"to": "/some/path",
43+
},
44+
"`add: '/'` requires not empty includePaths to interpret copy sources unambiguously",
45+
),
46+
)
47+
})

0 commit comments

Comments
 (0)