Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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