-
Notifications
You must be signed in to change notification settings - Fork 24
image-mapper: helm chart support #256
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
ribbybibby
merged 2 commits into
chainguard-dev:main
from
ribbybibby:image-mapper-helm-chart
Jan 5, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
|
|
||
| "github.com/chainguard-dev/customer-success/scripts/image-mapper/internal/mapper" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| func init() { | ||
| rootCmd.AddCommand( | ||
| MapCommand(), | ||
| ) | ||
| } | ||
|
|
||
| func MapCommand() *cobra.Command { | ||
| opts := struct { | ||
| OutputFormat string | ||
| IgnoreTiers []string | ||
| IgnoreIamguarded bool | ||
| Repo string | ||
| }{} | ||
| cmd := &cobra.Command{ | ||
| Use: "map", | ||
| Short: "Map upstream image references to Chainguard images.", | ||
| Args: cobra.MinimumNArgs(1), | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| output, err := mapper.NewOutput(opts.OutputFormat) | ||
| if err != nil { | ||
| return fmt.Errorf("constructing output: %w", err) | ||
| } | ||
|
|
||
| var ignoreFns []mapper.IgnoreFn | ||
| if len(opts.IgnoreTiers) > 0 { | ||
| ignoreFns = append(ignoreFns, mapper.IgnoreTiers(opts.IgnoreTiers)) | ||
| } | ||
| if opts.IgnoreIamguarded { | ||
| ignoreFns = append(ignoreFns, mapper.IgnoreIamguarded()) | ||
| } | ||
| m, err := mapper.NewMapper(cmd.Context(), mapper.WithRepository(opts.Repo), mapper.WithIgnoreFns(ignoreFns...)) | ||
| if err != nil { | ||
| return fmt.Errorf("creating mapper: %w", err) | ||
| } | ||
|
|
||
| it := mapper.NewArgsIterator(args) | ||
| if args[0] == "-" { | ||
| it = mapper.NewReaderIterator(os.Stdin) | ||
| } | ||
|
|
||
| mappings, err := m.MapAll(it) | ||
| if err != nil { | ||
| return fmt.Errorf("mapping images: %w", err) | ||
| } | ||
|
|
||
| return output(os.Stdout, mappings) | ||
| }, | ||
| } | ||
|
|
||
| rootCmd.Flags().StringVarP(&opts.OutputFormat, "output", "o", "text", "Output format (csv, json, text, customer-yaml)") | ||
| rootCmd.Flags().StringSliceVar(&opts.IgnoreTiers, "ignore-tiers", []string{}, "Ignore Chainguard repos of specific tiers (PREMIUM, APPLICATION, BASE, FIPS, AI)") | ||
| rootCmd.Flags().BoolVar(&opts.IgnoreIamguarded, "ignore-iamguarded", false, "Ignore iamguarded images") | ||
| rootCmd.Flags().StringVar(&opts.Repo, "repository", "cgr.dev/chainguard", "Modifies the repository URI in the mappings. For instance, registry.internal.dev/chainguard would result in registry.internal.dev/chainguard/<image> in the output.") | ||
|
|
||
| cmd.AddCommand( | ||
| MapHelmChartCommand(), | ||
| MapHelmValuesCommand(), | ||
| ) | ||
|
|
||
| return cmd | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "io" | ||
| "os" | ||
|
|
||
| "github.com/chainguard-dev/customer-success/scripts/image-mapper/internal/helm" | ||
| "github.com/chainguard-dev/customer-success/scripts/image-mapper/internal/mapper" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| func MapHelmChartCommand() *cobra.Command { | ||
| opts := struct { | ||
| Repo string | ||
| ChartRepo string | ||
| ChartVersion string | ||
| }{} | ||
| cmd := &cobra.Command{ | ||
| Use: "helm-chart", | ||
| Short: "Extract image related values from a Helm chart and map them to Chainguard.", | ||
| Example: ` | ||
| # Map a Helm chart. This requires that the Chart repo has been added with 'helm repo add' beforehand. | ||
| image-mapper map helm-chart argocd/argo-cd | ||
|
|
||
| # Override the repository in the mappings with your own mirror or proxy. For instance, cgr.dev/chainguard/<image> would become registry.internal/cgr/<image> in the output. | ||
| image-mapper map helm-chart argocd/argo-cd --repository=registry.internal/cgr | ||
|
|
||
| # Map a specific version of a Helm chart. | ||
| image-mapper map helm-chart argocd/argo-cd --chart-version=9.0.0 | ||
|
|
||
| # Specify a remote Chart repostory. This means the repository doesn't need to be added with 'helm repo add'. | ||
| image-mapper map helm-chart argo-cd --chart-repo=https://argoproj.github.io/argo-helm | ||
|
|
||
| # Specify a specific version of a remote Chart. | ||
| image-mapper map helm-chart argo-cd --chart-repo=https://argoproj.github.io/argo-helm --chart-version=9.0.0 | ||
| `, | ||
| Args: cobra.MinimumNArgs(1), | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| chart := helm.ChartDescriptor{ | ||
| Name: args[0], | ||
| Repository: opts.ChartRepo, | ||
| Version: opts.ChartVersion, | ||
| } | ||
| output, err := helm.MapChart(cmd.Context(), chart, mapper.WithRepository(opts.Repo)) | ||
| if err != nil { | ||
| return fmt.Errorf("mapping values: %w", err) | ||
| } | ||
|
|
||
| if _, err := os.Stdout.Write(output); err != nil { | ||
| return fmt.Errorf("writing output: %w", err) | ||
| } | ||
|
|
||
| return nil | ||
| }, | ||
| } | ||
|
|
||
| cmd.Flags().StringVar(&opts.Repo, "repository", "cgr.dev/chainguard", "Modifies the repository URI in the mappings. For instance, registry.internal.dev/chainguard would result in registry.internal.dev/chainguard/<image> in the output.") | ||
| cmd.Flags().StringVar(&opts.ChartRepo, "chart-repo", "", "The chart repository url to locate the requested chart.") | ||
| cmd.Flags().StringVar(&opts.ChartVersion, "chart-version", "", "A version constraint for the chart version.") | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| func MapHelmValuesCommand() *cobra.Command { | ||
| opts := struct { | ||
| Repo string | ||
| }{} | ||
| cmd := &cobra.Command{ | ||
| Use: "helm-values", | ||
| Short: "Extract image related values from a Helm values file and map them to Chainguard.", | ||
| Example: ` | ||
| # Map images in the values returned by 'helm show values' | ||
| helm show values argocd/argo-cd | image-mapper map helm-values - | ||
|
|
||
| # Map images in a values file on disk. | ||
| helm show values argocd/argo-cd > values.yaml | ||
| image-mapper map helm-values values.yaml | ||
|
|
||
| # Override the repository in the mappings with your own mirror or proxy. For instance, cgr.dev/chainguard/<image> would become registry.internal/cgr/<image> in the output. | ||
| image-mapper map helm-values values.yaml --repository=registry.internal/cgr | ||
| `, | ||
| Args: cobra.MinimumNArgs(1), | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| var ( | ||
| input []byte | ||
| err error | ||
| ) | ||
| switch args[0] { | ||
| case "-": | ||
| input, err = io.ReadAll(os.Stdin) | ||
| if err != nil { | ||
| return fmt.Errorf("reading stdin: %w", err) | ||
| } | ||
| default: | ||
| input, err = os.ReadFile(args[0]) | ||
| if err != nil { | ||
| return fmt.Errorf("reading file: %s: %w", args[0], err) | ||
| } | ||
| } | ||
|
|
||
| output, err := helm.MapValues(cmd.Context(), input, mapper.WithRepository(opts.Repo)) | ||
| if err != nil { | ||
| return fmt.Errorf("mapping values: %w", err) | ||
| } | ||
|
|
||
| if _, err := os.Stdout.Write(output); err != nil { | ||
| return fmt.Errorf("writing output: %w", err) | ||
| } | ||
|
|
||
| return nil | ||
| }, | ||
| } | ||
|
|
||
| cmd.Flags().StringVar(&opts.Repo, "repository", "cgr.dev/chainguard", "Modifies the repository URI in the mappings. For instance, registry.internal.dev/chainguard would result in registry.internal.dev/chainguard/<image> in the output.") | ||
|
|
||
| return cmd | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.