diff --git a/providers/os/connection/docker_container.go b/providers/os/connection/docker_container.go index e9e91a574d..c9328f82a2 100644 --- a/providers/os/connection/docker_container.go +++ b/providers/os/connection/docker_container.go @@ -174,8 +174,16 @@ func (c *DockerContainerConnection) RunCommand(command string) (*shared.Command, return res, err } +type DockerRegistryImageConnection struct { + *TarConnection +} + +func (c *DockerRegistryImageConnection) Type() shared.ConnectionType { + return shared.Type_RegistryImage +} + // NewContainerRegistryImage loads a container image from a remote registry -func NewContainerRegistryImage(id uint32, conf *inventory.Config, asset *inventory.Asset) (*TarConnection, error) { +func NewContainerRegistryImage(id uint32, conf *inventory.Config, asset *inventory.Asset) (*DockerRegistryImageConnection, error) { ref, err := name.ParseReference(conf.Host, name.WeakValidation) if err == nil { log.Debug().Str("ref", ref.Name()).Msg("found valid container registry reference") @@ -235,7 +243,7 @@ func NewContainerRegistryImage(id uint32, conf *inventory.Config, asset *invento conn.Metadata.Labels = labels asset.Labels = labels - return conn, err + return &DockerRegistryImageConnection{TarConnection: conn}, err } log.Debug().Str("image", conf.Host).Msg("Could not detect a valid repository url") return nil, err @@ -285,7 +293,15 @@ func NewDockerEngineContainer(id uint32, conf *inventory.Config, asset *inventor } } -func NewDockerContainerImageConnection(id uint32, conf *inventory.Config, asset *inventory.Asset) (*TarConnection, error) { +type DockerImageConnection struct { + *TarConnection +} + +func (c *DockerImageConnection) Type() shared.ConnectionType { + return shared.Type_DockerImage +} + +func NewDockerContainerImageConnection(id uint32, conf *inventory.Config, asset *inventory.Asset) (shared.Connection, error) { disableInmemoryCache := false if _, ok := conf.Options["disable-cache"]; ok { var err error @@ -310,7 +326,11 @@ func NewDockerContainerImageConnection(id uint32, conf *inventory.Config, asset asset.Name = resolvedAssets[0].Name asset.PlatformIds = resolvedAssets[0].PlatformIds asset.Labels = resolvedAssets[0].Labels - return NewContainerRegistryImage(id, conf, asset) + conn, err := NewContainerRegistryImage(id, conf, asset) + if err != nil { + return nil, err + } + return conn, nil } // could be an image id/name, container id/name or a short reference to an image in docker engine @@ -357,7 +377,7 @@ func NewDockerContainerImageConnection(id uint32, conf *inventory.Config, asset tarConn.PlatformIdentifier = identifier tarConn.Metadata.Name = ii.Name tarConn.Metadata.Labels = ii.Labels - return tarConn, nil + return &DockerImageConnection{TarConnection: tarConn}, nil } // based on the target, try and find out what kind of connection we are dealing with, this can be either a diff --git a/providers/os/connection/tar.go b/providers/os/connection/tar.go index 4236563aad..d0382bed78 100644 --- a/providers/os/connection/tar.go +++ b/providers/os/connection/tar.go @@ -185,6 +185,7 @@ func NewTarConnectionForContainer(id uint32, conf *inventory.Config, asset *inve asset: asset, Fs: provider_tar.NewFs(""), fetchFn: func() (string, error) { + log.Warn().Msg("loading container image into tar connection") err = cache.StreamToTmpFile(mutate.Extract(img), f) if err != nil { os.Remove(f.Name()) diff --git a/providers/os/detector/platform_resolver.go b/providers/os/detector/platform_resolver.go index 8ff1d0be01..f6d25bc3e4 100644 --- a/providers/os/detector/platform_resolver.go +++ b/providers/os/detector/platform_resolver.go @@ -25,11 +25,15 @@ func (r *PlatformResolver) Resolve(conn shared.Connection) (*inventory.Platform, di.Family = make([]string, 0) // start recursive platform resolution - pi, resolved := r.resolvePlatform(di, conn) + pi := &inventory.Platform{} + resolved := conn.Type() == shared.Type_RegistryImage + if conn.Type() != shared.Type_RegistryImage { + pi, resolved = r.resolvePlatform(di, conn) + } // if we have a container image use the architecture specified in the transport as it is resolved // using the container image properties - tarConn, ok := conn.(*connection.TarConnection) + tarConn, ok := conn.(*connection.DockerRegistryImageConnection) if resolved && ok { pi.Arch = tarConn.PlatformArchitecture di.Runtime = "docker-image"