add ability to specify source as a URL scheme
This commit is contained in:
parent
e39e646191
commit
14a349343b
@ -64,7 +64,11 @@ Analyze and image and get a pass/fail result based on the image efficiency and w
|
|||||||
**With Multiple Image Sources and Container Engines Supported**
|
**With Multiple Image Sources and Container Engines Supported**
|
||||||
With the `--source` option, you can select where to fetch the container image from:
|
With the `--source` option, you can select where to fetch the container image from:
|
||||||
```bash
|
```bash
|
||||||
dive <your-image-tag> --source podman
|
dive <your-image> --source <source>
|
||||||
|
```
|
||||||
|
or
|
||||||
|
```bash
|
||||||
|
dive <source>://<your-image>
|
||||||
```
|
```
|
||||||
|
|
||||||
With valid `source` options as such:
|
With valid `source` options as such:
|
||||||
|
@ -39,16 +39,26 @@ func doAnalyzeCmd(cmd *cobra.Command, args []string) {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
engine, err := cmd.PersistentFlags().GetString("source")
|
var sourceType dive.ImageSource
|
||||||
if err != nil {
|
var imageStr string
|
||||||
fmt.Printf("unable to determine engine: %v\n", err)
|
|
||||||
os.Exit(1)
|
sourceType, imageStr = dive.DeriveImageSource(userImage)
|
||||||
|
|
||||||
|
if sourceType == dive.SourceUnknown {
|
||||||
|
sourceStr, err := cmd.PersistentFlags().GetString("source")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("unable to determine image source: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceType = dive.ParseImageSource(sourceStr)
|
||||||
|
imageStr = userImage
|
||||||
}
|
}
|
||||||
|
|
||||||
runtime.Run(runtime.Options{
|
runtime.Run(runtime.Options{
|
||||||
Ci: isCi,
|
Ci: isCi,
|
||||||
Source: dive.ParseImageSource(engine),
|
Source: sourceType,
|
||||||
Image: userImage,
|
Image: imageStr,
|
||||||
ExportFile: exportFile,
|
ExportFile: exportFile,
|
||||||
CiConfig: ciConfig,
|
CiConfig: ciConfig,
|
||||||
})
|
})
|
||||||
|
@ -5,6 +5,8 @@ import (
|
|||||||
"github.com/wagoodman/dive/dive/image"
|
"github.com/wagoodman/dive/dive/image"
|
||||||
"github.com/wagoodman/dive/dive/image/docker"
|
"github.com/wagoodman/dive/dive/image/docker"
|
||||||
"github.com/wagoodman/dive/dive/image/podman"
|
"github.com/wagoodman/dive/dive/image/podman"
|
||||||
|
"net/url"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -24,11 +26,11 @@ func (r ImageSource) String() string {
|
|||||||
|
|
||||||
func ParseImageSource(r string) ImageSource {
|
func ParseImageSource(r string) ImageSource {
|
||||||
switch r {
|
switch r {
|
||||||
case "docker":
|
case SourceDockerEngine.String():
|
||||||
return SourceDockerEngine
|
return SourceDockerEngine
|
||||||
case "podman":
|
case SourcePodmanEngine.String():
|
||||||
return SourcePodmanEngine
|
return SourcePodmanEngine
|
||||||
case "docker-archive":
|
case SourceDockerArchive.String():
|
||||||
return SourceDockerArchive
|
return SourceDockerArchive
|
||||||
case "docker-tar":
|
case "docker-tar":
|
||||||
return SourceDockerArchive
|
return SourceDockerArchive
|
||||||
@ -37,6 +39,28 @@ func ParseImageSource(r string) ImageSource {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DeriveImageSource(image string) (ImageSource, string) {
|
||||||
|
u, err := url.Parse(image)
|
||||||
|
if err != nil {
|
||||||
|
return SourceUnknown, ""
|
||||||
|
}
|
||||||
|
|
||||||
|
imageSource := strings.TrimPrefix(image, u.Scheme+"://")
|
||||||
|
|
||||||
|
switch u.Scheme {
|
||||||
|
case SourceDockerEngine.String():
|
||||||
|
return SourceDockerEngine, imageSource
|
||||||
|
case SourcePodmanEngine.String():
|
||||||
|
return SourcePodmanEngine, imageSource
|
||||||
|
case SourceDockerArchive.String():
|
||||||
|
return SourceDockerArchive, imageSource
|
||||||
|
case "docker-tar":
|
||||||
|
return SourceDockerArchive, imageSource
|
||||||
|
|
||||||
|
}
|
||||||
|
return SourceUnknown, ""
|
||||||
|
}
|
||||||
|
|
||||||
func GetImageResolver(r ImageSource) (image.Resolver, error) {
|
func GetImageResolver(r ImageSource) (image.Resolver, error) {
|
||||||
switch r {
|
switch r {
|
||||||
case SourceDockerEngine:
|
case SourceDockerEngine:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user