forked from kyma-project/kyma
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
55 lines (45 loc) · 1.22 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"io/ioutil"
"os"
"github.com/pkg/errors"
"fmt"
"path/filepath"
"github.com/kyma-project/kyma/components/helm-broker/cmd/targz/archiver"
)
func main() {
if len(os.Args) != 3 {
fmt.Println("Usage: targz <input_directory> <output_directory>")
return
}
inDir := os.Args[1]
outDir := os.Args[2]
if err := archiveBundles(inDir, outDir); err != nil {
panic(err)
}
}
func archiveBundles(inDir, outDir string) error {
bundles, err := ioutil.ReadDir(inDir)
if err != nil {
return errors.Wrap(err, "while reading input directory")
}
for _, bundleInfo := range bundles {
if bundleInfo.IsDir() {
bundlePath := filepath.Join(inDir, bundleInfo.Name())
bundleContent, err := ioutil.ReadDir(bundlePath)
if err != nil {
return errors.Wrapf(err, "while reading bundle '%s'", bundlePath)
}
bundleFileNames := make([]string, len(bundleContent))
for i, elem := range bundleContent {
bundleFileNames[i] = filepath.Join(bundlePath, elem.Name())
}
tarGzFile := filepath.Join(outDir, bundleInfo.Name()+".tgz")
err = archiver.TarGz.Make(tarGzFile, bundleFileNames)
if err != nil {
return errors.Wrapf(err, "while creating archive '%s'", tarGzFile)
}
}
}
return nil
}