Skip to content

Commit

Permalink
use vendor when uploading function
Browse files Browse the repository at this point in the history
  • Loading branch information
kvch committed Dec 12, 2019
1 parent ad1d427 commit bc3d378
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
19 changes: 17 additions & 2 deletions x-pack/functionbeat/manager/core/bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type Resource interface {
}

// Folder returns a list of files in a folder.
func Folder(folder string, filemode os.FileMode) []Resource {
func Folder(folder, root string, filemode os.FileMode) []Resource {
resources := make([]Resource, 0)
err := filepath.Walk(folder, func(path string, info os.FileInfo, err error) error {
if err != nil {
Expand All @@ -65,7 +65,7 @@ func Folder(folder string, filemode os.FileMode) []Resource {
return nil
}

resources = append(resources, &LocalFile{Path: path, FileMode: filemode})
resources = append(resources, &RelativeFile{LocalFile{Path: path, FileMode: filemode}, root})

return nil
})
Expand Down Expand Up @@ -104,6 +104,21 @@ func (l *LocalFile) Mode() os.FileMode {
return l.FileMode
}

// RelativeFile is a Localfile which needs to be placed relatively in the
// root of the bundle.
type RelativeFile struct {
LocalFile
root string
}

// Name returns the name of the file.
func (r *RelativeFile) Name() string {
if r.root == "" {
return r.LocalFile.Path
}
return r.LocalFile.Path[len(r.root)+1:]
}

// MemoryFile an in-memory representation of a physical file.
type MemoryFile struct {
Path string
Expand Down
3 changes: 2 additions & 1 deletion x-pack/functionbeat/manager/gcp/template_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ func ZipResources() map[string][]bundle.Resource {
}

func zipResources(typeName string) []bundle.Resource {
vendor := bundle.Folder(filepath.Join("pkg", typeName, "vendor"), 0655)
root := filepath.Join("pkg", typeName)
vendor := bundle.Folder(filepath.Join(root, "vendor"), root, 0655)
return append(vendor, &bundle.LocalFile{Path: filepath.Join("pkg", typeName, typeName+".go"), FileMode: 0755})
}

0 comments on commit bc3d378

Please sign in to comment.