Skip to content

Commit 1cb8dbe

Browse files
authored
Merge pull request #161 from jhrozek/exclude_regex
Always ignore the scratch image even with an empty config
2 parents e41d54d + f989ea3 commit 1cb8dbe

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

pkg/replacer/replacer.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ type Replacer struct {
6161

6262
// NewGitHubActionsReplacer creates a new replacer for GitHub actions
6363
func NewGitHubActionsReplacer(cfg *config.Config) *Replacer {
64+
cfg = config.MergeUserConfig(cfg)
65+
6466
return &Replacer{
6567
cfg: *cfg,
6668
parser: actions.New(),
@@ -70,6 +72,8 @@ func NewGitHubActionsReplacer(cfg *config.Config) *Replacer {
7072

7173
// NewContainerImagesReplacer creates a new replacer for container images
7274
func NewContainerImagesReplacer(cfg *config.Config) *Replacer {
75+
cfg = config.MergeUserConfig(cfg)
76+
7377
return &Replacer{
7478
cfg: *cfg,
7579
parser: image.New(),

pkg/replacer/replacer_test.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,7 @@ func TestReplacer_ParseContainerImageString(t *testing.T) {
196196
config := &config.Config{
197197
Images: config.Images{
198198
ImageFilter: config.ImageFilter{
199-
ExcludeImages: []string{"scratch"},
200-
ExcludeTags: []string{"latest"},
199+
ExcludeTags: []string{"latest"},
201200
},
202201
},
203202
}
@@ -407,8 +406,7 @@ func TestReplacer_ParseGitHubActionString(t *testing.T) {
407406
},
408407
Images: config.Images{
409408
ImageFilter: config.ImageFilter{
410-
ExcludeImages: []string{"scratch"},
411-
ExcludeTags: []string{"latest"},
409+
ExcludeTags: []string{"latest"},
412410
},
413411
},
414412
}
@@ -728,8 +726,7 @@ CMD ["dex", "serve", "/etc/dex/config.docker.yaml"]
728726
r := NewContainerImagesReplacer(&config.Config{
729727
Images: config.Images{
730728
ImageFilter: config.ImageFilter{
731-
ExcludeImages: []string{"scratch"},
732-
ExcludeTags: []string{"latest"},
729+
ExcludeTags: []string{"latest"},
733730
},
734731
},
735732
})

pkg/utils/config/config.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"io"
2323
"os"
2424
"path/filepath"
25+
"slices"
2526

2627
"github.com/go-git/go-billy/v5"
2728
"github.com/go-git/go-billy/v5/osfs"
@@ -109,6 +110,24 @@ func DefaultConfig() *Config {
109110
}
110111
}
111112

113+
// MergeUserConfig merges the user configuration with the default configuration.
114+
// mostly making sure that we don't try to pin the scratch image
115+
func MergeUserConfig(userConfig *Config) *Config {
116+
if userConfig == nil {
117+
return DefaultConfig()
118+
}
119+
120+
if userConfig.Images.ExcludeImages == nil {
121+
userConfig.Images.ExcludeImages = []string{"scratch"}
122+
}
123+
124+
if !slices.Contains(userConfig.Images.ExcludeImages, "scratch") {
125+
userConfig.Images.ExcludeImages = append(userConfig.Images.ExcludeImages, "scratch")
126+
}
127+
128+
return userConfig
129+
}
130+
112131
// ParseConfigFileFromFS parses a configuration file from a filesystem.
113132
func ParseConfigFileFromFS(fs billy.Filesystem, configfile string) (*Config, error) {
114133
cfg := DefaultConfig()

0 commit comments

Comments
 (0)