Skip to content

Commit

Permalink
feature(main): add .sealignore file
Browse files Browse the repository at this point in the history
Signed-off-by: cuisongliu <[email protected]>
  • Loading branch information
cuisongliu committed Oct 10, 2023
1 parent efe1e0b commit da57c27
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pkg/buildimage/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,18 @@ func List(dir string) ([]string, error) {
list = list.Insert(shimImgs...)
return list.List(), nil
}

func Filter(images []string, ignoreFile string) ([]string, error) {
ignore, err := file.ReadLines(ignoreFile)
if err != nil {
return nil, err
}
ignoreSet := sets.NewString(ignore...)
var res []string
for _, img := range images {
if !ignoreSet.Has(img) {
res = append(res, img)
}
}
return res, nil
}
36 changes: 36 additions & 0 deletions pkg/buildimage/images_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package buildimage

import (
"reflect"
"testing"
)

Expand All @@ -26,3 +27,38 @@ func TestParseYamlImages(t *testing.T) {
}
t.Logf("%v", data)
}

func TestFilter(t *testing.T) {
type args struct {
images []string
ignoreFile string
}
tests := []struct {
name string
args args
want []string
wantErr bool
}{
{
name: "filter",
args: args{
images: []string{"docker.io/cilium/istio_proxy", "quay.io/cilium/cilium:v1.12.0", "quay.io/cilium/operator-generic:v1.12.0"},
ignoreFile: "test/ignore/.sealignore",
},
want: []string{"docker.io/cilium/istio_proxy", "quay.io/cilium/cilium:v1.12.0"},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := Filter(tt.args.images, tt.args.ignoreFile)
if (err != nil) != tt.wantErr {
t.Errorf("Filter() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("Filter() got = %v, want %v", got, tt.want)
}
})
}
}
1 change: 1 addition & 0 deletions pkg/buildimage/test/ignore/.sealignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
quay.io/cilium/operator-generic:v1.12.0
9 changes: 9 additions & 0 deletions pkg/registry/commands/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"context"
"errors"
"fmt"
"github.com/labring/sreg/pkg/utils/file"
"path"

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

Expand Down Expand Up @@ -84,6 +86,13 @@ func NewRegistryImageSaveCmd(examplePrefix string) *cobra.Command {
if err != nil {
return err
}
ignore := path.Join(path.Dir(args[0]), ".sealignore")
if file.IsExist(ignore) {
images, err = buildimage.Filter(images, ignore)
if err != nil {
return err
}
}
tars, err = buildimage.TarList(args[0])
if err != nil {
return err
Expand Down

0 comments on commit da57c27

Please sign in to comment.