Skip to content
This repository was archived by the owner on Mar 27, 2024. It is now read-only.

Conversation

vrothberg
Copy link
Contributor

The RPMAnalyzer runs all analyses in a container, which requires not
only to unpack the tarball, but also to pull the referenced image into
the daemon in case it's not present.

Signed-off-by: Valentin Rothberg vrothberg@suse.com
Fixes: #162

@vrothberg
Copy link
Contributor Author

Ping @nkubala

Copy link
Contributor

@nkubala nkubala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a few comments but this looks good

}
if err := client.PullImage(pullOpts, godocker.AuthConfiguration{}); err != nil {
return packages, fmt.Errorf("Error pulling remote image: %s", err)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we do a logrus.Debug(buf.String()) here? otherwise why pass a buffer to the OutputStream?

type ImageType int

const (
ImageTypeTar ImageType = iota
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice usage of iota 👍

@@ -123,6 +123,20 @@ func rpmDataFromContainer(image pkgutil.Image) (map[string]util.PackageInfo, err

defer client.RemoveImage(imageName)
defer logrus.Infof("Removing image %s", imageName)
} else if image.IsCloud() {
// if it's a remote image and not in the daemon, we need to pull it
if _, err := client.InspectImage(imageName); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if err == nil here, we should probably log and exit yeah? otherwise we have an invalid image and this will fail somewhere else down the line

Copy link
Contributor Author

@vrothberg vrothberg Jan 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you elaborate on why the image would be invalid in such case? If err == nil then I would expect the tool to use the already present image. I agree that it should be logged.

update: Another option could be to pull unconditionally, which would update the local images in case they're outdated. I can imagine this to be especially useful in automation. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping @nkubala

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sorry, I confused myself with the error cases here. Disregard my original comment.

I think it might make sense to specify an option to users (through a flag or something) to always pull, but I don't think we want to do that by default. One of the major use cases is comparing locally built images with their remote counterparts, and I don't think we should assume that users will always use image tags appropriately :) either way this is outside the scope of this PR imo, but feel free to file a separate issue to track this

The RPMAnalyzer runs all analyses in a container, which requires not
only to unpack the tarball, but also to pull the referenced image into
the daemon in case it's not present.  However, we cannot blindly pull
a remote image as the Docker daemon would overwrite a potentially
present image with the same tag.  Instead, pull the image via its sha256
digest, which is computed via the OCI libs, just as Skopeo does.

Signed-off-by: Valentin Rothberg <vrothberg@suse.com>
Fixes: #162
@vrothberg
Copy link
Contributor Author

vrothberg commented Jan 5, 2018

@nkubala I went a slightly different path. Now, we can unconditionally pull a remote image. To avoid a tag/name conflict with an already present image, we cannot use docker pull image:tag but instead use the image's sha256 digest (e.g., docker pull opensuse:sha256@...). As some might expect, docker doesn't support inspecting the digest of a remote image, but we can use OCI libs just as Skopeo does for skopeo inspect. Those libs are already used to download the blobs, so there's no big vendoring change.

However, I am still not a 100 percent satisfied with the current state, as we are now downloading an RPM remote image two times. Once for unpacking it into /tmp and another time to load it into the daemon. Instead, it would be nicer to just download the entire image as a docker tar archive (which can then be loaded into the daemon) and unpack this archive in a separate step into /tmp - unconditionally if it's an RPM remote image or of any other kind. Skopeo has all code to do that but sadly it doesn't expose it as an API we can use. I suggest to keep this idea on the radar for future releases.

// log PullImage() output in debug mode
if logrus.GetLevel() == logrus.DebugLevel {
// log each line separately for consistency
for _, out := range strings.Split(buf.String(), "\n") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does the output stream not already have newlines in it? just wondering why this is necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the output stream has newlines. The issue here is that logrus will not prepend the log prefix to a new line, so only logging buf.String() would look like:

[level][counter] first line
second line
third line...

I find that very confusing as it looks broken, so I usually split strings to print each array entry separately.

@nkubala
Copy link
Contributor

nkubala commented Jan 9, 2018

@vrothberg thanks for all your work on this. Pulling all images by digest should be fine as far as tags in the local daemon go, so this approach looks good. I agree that pulling the image twice for RPM diffs isn't optimal, but I don't think it'll be too much an issue right now; let's go ahead and open an issue to rework the image pulling at a later date. I suspect we should be able to use the containers/image library (what skopeo is built on and what container-diff uses in a few places) to do this.

@vrothberg
Copy link
Contributor Author

@nkubala Thanks, I totally agree with you.

@nkubala nkubala merged commit f92bed7 into GoogleContainerTools:master Jan 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants