Skip to content

Commit

Permalink
Merge pull request #161 from jhrozek/exclude_regex
Browse files Browse the repository at this point in the history
Always ignore the scratch image even with an empty config
  • Loading branch information
jhrozek committed Jun 18, 2024
2 parents e41d54d + f989ea3 commit 1cb8dbe
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
4 changes: 4 additions & 0 deletions pkg/replacer/replacer.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ type Replacer struct {

// NewGitHubActionsReplacer creates a new replacer for GitHub actions
func NewGitHubActionsReplacer(cfg *config.Config) *Replacer {
cfg = config.MergeUserConfig(cfg)

return &Replacer{
cfg: *cfg,
parser: actions.New(),
Expand All @@ -70,6 +72,8 @@ func NewGitHubActionsReplacer(cfg *config.Config) *Replacer {

// NewContainerImagesReplacer creates a new replacer for container images
func NewContainerImagesReplacer(cfg *config.Config) *Replacer {
cfg = config.MergeUserConfig(cfg)

return &Replacer{
cfg: *cfg,
parser: image.New(),
Expand Down
9 changes: 3 additions & 6 deletions pkg/replacer/replacer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,7 @@ func TestReplacer_ParseContainerImageString(t *testing.T) {
config := &config.Config{
Images: config.Images{
ImageFilter: config.ImageFilter{
ExcludeImages: []string{"scratch"},
ExcludeTags: []string{"latest"},
ExcludeTags: []string{"latest"},
},
},
}
Expand Down Expand Up @@ -407,8 +406,7 @@ func TestReplacer_ParseGitHubActionString(t *testing.T) {
},
Images: config.Images{
ImageFilter: config.ImageFilter{
ExcludeImages: []string{"scratch"},
ExcludeTags: []string{"latest"},
ExcludeTags: []string{"latest"},
},
},
}
Expand Down Expand Up @@ -728,8 +726,7 @@ CMD ["dex", "serve", "/etc/dex/config.docker.yaml"]
r := NewContainerImagesReplacer(&config.Config{
Images: config.Images{
ImageFilter: config.ImageFilter{
ExcludeImages: []string{"scratch"},
ExcludeTags: []string{"latest"},
ExcludeTags: []string{"latest"},
},
},
})
Expand Down
19 changes: 19 additions & 0 deletions pkg/utils/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"io"
"os"
"path/filepath"
"slices"

"github.com/go-git/go-billy/v5"
"github.com/go-git/go-billy/v5/osfs"
Expand Down Expand Up @@ -109,6 +110,24 @@ func DefaultConfig() *Config {
}
}

// MergeUserConfig merges the user configuration with the default configuration.
// mostly making sure that we don't try to pin the scratch image
func MergeUserConfig(userConfig *Config) *Config {
if userConfig == nil {
return DefaultConfig()
}

if userConfig.Images.ExcludeImages == nil {
userConfig.Images.ExcludeImages = []string{"scratch"}
}

if !slices.Contains(userConfig.Images.ExcludeImages, "scratch") {
userConfig.Images.ExcludeImages = append(userConfig.Images.ExcludeImages, "scratch")
}

return userConfig
}

// ParseConfigFileFromFS parses a configuration file from a filesystem.
func ParseConfigFileFromFS(fs billy.Filesystem, configfile string) (*Config, error) {
cfg := DefaultConfig()
Expand Down

0 comments on commit 1cb8dbe

Please sign in to comment.