Skip to content
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

Allow user to replace docker repo prefix from image names #366

Merged
merged 2 commits into from
Oct 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 11 additions & 0 deletions docs/Config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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': '<prod>'
'923456789999.dkr.ecr.us-east-1.amazonaws.com': '<dev>'
```
7 changes: 7 additions & 0 deletions pkg/commands/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
12 changes: 12 additions & 0 deletions pkg/config/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
jesseduffield marked this conversation as resolved.
Show resolved Hide resolved
Replacements Replacements `yaml:"replacements,omitempty"`
}

// ThemeConfig is for setting the colors of panels and some text.
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -404,6 +413,9 @@ func GetDefaultConfig() UserConfig {
},
},
},
Replacements: Replacements{
ImageNamePrefixes: map[string]string{},
},
}
}

Expand Down