From fcd90fa78ae4f04b84ee08cfaa500bd10045eb6a Mon Sep 17 00:00:00 2001 From: Vasek - Tom C Date: Fri, 28 Jan 2022 15:27:32 +0100 Subject: [PATCH 1/3] Solves #1512 Signed-off-by: Vasek - Tom C --- pkg/pkg.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/pkg/pkg.go b/pkg/pkg.go index c3dd2330..0b7abbf6 100644 --- a/pkg/pkg.go +++ b/pkg/pkg.go @@ -17,7 +17,7 @@ import ( var ( // FS contains the filesystem of the stdlib. - //go:embed */**/*.cue */**/**/*.cue + //go:embed */**/*.cue */**/**/*.cue */**/*.sh FS embed.FS ) @@ -112,6 +112,17 @@ func Vendor(ctx context.Context, p string) error { return nil } +func isAllowedExt(ext string) bool { + // List of allowed extension to vendor in + allowedExtension := []string{".cue", ".sh"} + for _, v := range allowedExtension { + if v == ext { + return true + } + } + return false +} + func extractModules(dest string) error { return fs.WalkDir(FS, ".", func(p string, entry fs.DirEntry, err error) error { if err != nil { @@ -122,7 +133,7 @@ func extractModules(dest string) error { return nil } - if filepath.Ext(entry.Name()) != ".cue" { + if !isAllowedExt(filepath.Ext(entry.Name())) { return nil } From 5de86cb1ee844eeff276943adaa58409a86341a8 Mon Sep 17 00:00:00 2001 From: Vasek - Tom C Date: Fri, 28 Jan 2022 22:02:21 +0100 Subject: [PATCH 2/3] Embed all files instead of just cue file Signed-off-by: Vasek - Tom C --- pkg/pkg.go | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/pkg/pkg.go b/pkg/pkg.go index 0b7abbf6..8bfde31e 100644 --- a/pkg/pkg.go +++ b/pkg/pkg.go @@ -17,7 +17,7 @@ import ( var ( // FS contains the filesystem of the stdlib. - //go:embed */**/*.cue */**/**/*.cue */**/*.sh + //go:embed alpha.dagger.io dagger.io universe.dagger.io FS embed.FS ) @@ -112,17 +112,6 @@ func Vendor(ctx context.Context, p string) error { return nil } -func isAllowedExt(ext string) bool { - // List of allowed extension to vendor in - allowedExtension := []string{".cue", ".sh"} - for _, v := range allowedExtension { - if v == ext { - return true - } - } - return false -} - func extractModules(dest string) error { return fs.WalkDir(FS, ".", func(p string, entry fs.DirEntry, err error) error { if err != nil { @@ -133,10 +122,6 @@ func extractModules(dest string) error { return nil } - if !isAllowedExt(filepath.Ext(entry.Name())) { - return nil - } - contents, err := fs.ReadFile(FS, p) if err != nil { return fmt.Errorf("%s: %w", p, err) @@ -148,7 +133,11 @@ func extractModules(dest string) error { return err } - return os.WriteFile(overlayPath, contents, 0600) + info, err := fs.Stat(FS, p) + if err != nil { + return err + } + return os.WriteFile(overlayPath, contents, info.Mode().Perm()) }) } From 6f5095ec1974fc4c95fcbcfef49262f9dd3dabbc Mon Sep 17 00:00:00 2001 From: Vasek - Tom C Date: Fri, 28 Jan 2022 22:46:36 +0100 Subject: [PATCH 3/3] Fix permissions issue and doc generation issue Signed-off-by: Vasek - Tom C --- cmd/dagger/cmd/doc.go | 8 +++++++- pkg/pkg.go | 9 ++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/cmd/dagger/cmd/doc.go b/cmd/dagger/cmd/doc.go index eee6c296..48025d42 100644 --- a/cmd/dagger/cmd/doc.go +++ b/cmd/dagger/cmd/doc.go @@ -338,7 +338,9 @@ func walkStdlib(ctx context.Context, output, format string) { return err } - if p == "." || d.Name() == pkg.AlphaModule || !d.IsDir() || d.Name() == "cue.mod" { + // Ignore useless embedded files + if p == "." || d.Name() == pkg.AlphaModule || !d.IsDir() || d.Name() == "cue.mod" || + strings.Contains(p, "cue.mod") || strings.Contains(p, "tests") { return nil } @@ -357,6 +359,10 @@ func walkStdlib(ctx context.Context, output, format string) { lg.Warn().Str("package", p).Err(err).Msg("ignoring") return nil } + if strings.Contains(err.Error(), "cannot find package") { + lg.Warn().Str("package", p).Err(err).Msg("ignoring") + return nil + } return err } diff --git a/pkg/pkg.go b/pkg/pkg.go index 8bfde31e..8ed20881 100644 --- a/pkg/pkg.go +++ b/pkg/pkg.go @@ -133,11 +133,10 @@ func extractModules(dest string) error { return err } - info, err := fs.Stat(FS, p) - if err != nil { - return err - } - return os.WriteFile(overlayPath, contents, info.Mode().Perm()) + // Give exec permission on embedded file to freely use shell script + // Exclude permission linter + //nolint + return os.WriteFile(overlayPath, contents, 0700) }) }