Skip to content

Commit 47d17ed

Browse files
authored
feature(main): add .sealignore file (#3)
Signed-off-by: cuisongliu <[email protected]>
1 parent efe1e0b commit 47d17ed

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed

pkg/buildimage/images.go

+15
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,18 @@ func List(dir string) ([]string, error) {
120120
list = list.Insert(shimImgs...)
121121
return list.List(), nil
122122
}
123+
124+
func Filter(images []string, ignoreFile string) ([]string, error) {
125+
ignore, err := file.ReadLines(ignoreFile)
126+
if err != nil {
127+
return nil, err
128+
}
129+
ignoreSet := sets.NewString(ignore...)
130+
var res []string
131+
for _, img := range images {
132+
if !ignoreSet.Has(img) {
133+
res = append(res, img)
134+
}
135+
}
136+
return res, nil
137+
}

pkg/buildimage/images_test.go

+36
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package buildimage
1616

1717
import (
18+
"reflect"
1819
"testing"
1920
)
2021

@@ -26,3 +27,38 @@ func TestParseYamlImages(t *testing.T) {
2627
}
2728
t.Logf("%v", data)
2829
}
30+
31+
func TestFilter(t *testing.T) {
32+
type args struct {
33+
images []string
34+
ignoreFile string
35+
}
36+
tests := []struct {
37+
name string
38+
args args
39+
want []string
40+
wantErr bool
41+
}{
42+
{
43+
name: "filter",
44+
args: args{
45+
images: []string{"docker.io/cilium/istio_proxy", "quay.io/cilium/cilium:v1.12.0", "quay.io/cilium/operator-generic:v1.12.0"},
46+
ignoreFile: "test/ignore/.sealignore",
47+
},
48+
want: []string{"docker.io/cilium/istio_proxy", "quay.io/cilium/cilium:v1.12.0"},
49+
wantErr: false,
50+
},
51+
}
52+
for _, tt := range tests {
53+
t.Run(tt.name, func(t *testing.T) {
54+
got, err := Filter(tt.args.images, tt.args.ignoreFile)
55+
if (err != nil) != tt.wantErr {
56+
t.Errorf("Filter() error = %v, wantErr %v", err, tt.wantErr)
57+
return
58+
}
59+
if !reflect.DeepEqual(got, tt.want) {
60+
t.Errorf("Filter() got = %v, want %v", got, tt.want)
61+
}
62+
})
63+
}
64+
}
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
quay.io/cilium/operator-generic:v1.12.0

pkg/registry/commands/save.go

+9
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import (
2020
"context"
2121
"errors"
2222
"fmt"
23+
"github.com/labring/sreg/pkg/utils/file"
24+
"path"
2325

2426
"github.com/labring/sreg/pkg/registry/save"
2527

@@ -84,6 +86,13 @@ func NewRegistryImageSaveCmd(examplePrefix string) *cobra.Command {
8486
if err != nil {
8587
return err
8688
}
89+
ignore := path.Join(path.Dir(args[0]), ".sealignore")
90+
if file.IsExist(ignore) {
91+
images, err = buildimage.Filter(images, ignore)
92+
if err != nil {
93+
return err
94+
}
95+
}
8796
tars, err = buildimage.TarList(args[0])
8897
if err != nil {
8998
return err

0 commit comments

Comments
 (0)