8000 Always ignore the scratch image even with an empty config by jhrozek · Pull Request #161 · stacklok/frizbee · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Always ignore the scratch image even with an empty config #161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 18, 2024
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 5BFA , "scratch")
}

return userConfig
}

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