From d64a92227a7b535d83586d2502c2ee4c21dc7f0a Mon Sep 17 00:00:00 2001 From: Miles Liu Date: Tue, 6 Sep 2022 13:39:08 +0800 Subject: [PATCH 1/2] allow user to replace docker repo prefix from image names Example usage: ```yaml replacements: imageNamePrefixes: '123456789012.dkr.ecr.us-east-1.amazonaws.com': '' '923456789999.dkr.ecr.us-east-1.amazonaws.com': '' ``` Closes #316 --- docs/Config.md | 11 +++++++++++ pkg/commands/image.go | 7 +++++++ pkg/config/app_config.go | 12 ++++++++++++ 3 files changed, 30 insertions(+) diff --git a/docs/Config.md b/docs/Config.md index f2388d5f8..92a8a3ed5 100644 --- a/docs/Config.md +++ b/docs/Config.md @@ -90,3 +90,14 @@ customCommands: command: 'docker exec -it {{ .Container.ID }} bash' serviceNames: [] ``` + +## Replacements + +You can add replacements like so: + +```yaml +replacements: + imageNamePrefixes: + '123456789012.dkr.ecr.us-east-1.amazonaws.com': '' + '923456789999.dkr.ecr.us-east-1.amazonaws.com': '' +``` diff --git a/pkg/commands/image.go b/pkg/commands/image.go index 796a64043..7cbb142e9 100644 --- a/pkg/commands/image.go +++ b/pkg/commands/image.go @@ -123,6 +123,13 @@ func (c *DockerCommand) RefreshImages() ([]*Image, error) { if len(nameParts) > 1 { tag = nameParts[len(nameParts)-1] name = strings.Join(nameParts[:len(nameParts)-1], ":") + + for prefix, replacement := range c.Config.UserConfig.Replacements.ImageNamePrefixes { + if strings.HasPrefix(name, prefix) { + name = strings.Replace(name, prefix, replacement, 1) + break + } + } } ownImages[i] = &Image{ diff --git a/pkg/config/app_config.go b/pkg/config/app_config.go index add2ad7d4..d3b3404ba 100644 --- a/pkg/config/app_config.go +++ b/pkg/config/app_config.go @@ -57,6 +57,9 @@ type UserConfig struct { // Stats determines how long lazydocker will gather container stats for, and // what stat info to graph Stats StatsConfig `yaml:"stats,omitempty"` + + // Replacements determines how we render a container's info + Replacements Replacements `yaml:"replacements,omitempty"` } // ThemeConfig is for setting the colors of panels and some text. @@ -258,6 +261,12 @@ type CustomCommands struct { Volumes []CustomCommand `yaml:"volumes,omitempty"` } +// Replacements contains the stuff relating to rendering a container's info +type Replacements struct { + // ImageNamePrefixes tells us how to replace a prefix in the Docker image name + ImageNamePrefixes map[string]string `yaml:"imageNamePrefixes,omitempty"` +} + // CustomCommand is a template for a command we want to run against a service or // container type CustomCommand struct { @@ -404,6 +413,9 @@ func GetDefaultConfig() UserConfig { }, }, }, + Replacements: Replacements{ + ImageNamePrefixes: map[string]string{}, + }, } } From 9c40237faeca32cb18b156be348bb2994f8a3884 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Sat, 8 Oct 2022 11:57:01 -0700 Subject: [PATCH 2/2] Update pkg/config/app_config.go --- pkg/config/app_config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/config/app_config.go b/pkg/config/app_config.go index d3b3404ba..c087675e7 100644 --- a/pkg/config/app_config.go +++ b/pkg/config/app_config.go @@ -58,7 +58,7 @@ type UserConfig struct { // what stat info to graph Stats StatsConfig `yaml:"stats,omitempty"` - // Replacements determines how we render a container's info + // Replacements determines how we render an item's info Replacements Replacements `yaml:"replacements,omitempty"` }