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

Adding OCI image and a respective test class #734

Closed
wants to merge 1 commit into from
Closed

Adding OCI image and a respective test class #734

wants to merge 1 commit into from

Conversation

mukultaneja
Copy link
Contributor

Following commit adds a class to read OCI images
along with tests to validate its functionality.

Work towards: #678

Signed-off-by: mukultaneja [email protected]

@mukultaneja
Copy link
Contributor Author

@rnjudge should I update this config file under setup section to add an instruction to install skopeo utility?

tern/classes/oci_image.py Outdated Show resolved Hide resolved
@rnjudge
Copy link
Contributor

rnjudge commented Jun 17, 2020

@rnjudge should I update this config file under setup section to add an instruction to install skopeo utility?

From what I can tell, circleci only supports ubuntu 1604 hosts for the test and skopeo needs 1804, correct? If this is the case, we should disable circleci tests and only use github actions to run the tests since github hosts use ubuntu 1804 as the default latest linux image. I think we should address this in a separate PR, though.

@rnjudge
Copy link
Contributor

rnjudge commented Jun 17, 2020

In general, some comments in your code would be nice :) This is helpful as we review the PR and also for future contributors. Note that for comments describing the functionality of a function we use the three backticks enclosures (''' coment ''') instead of # . # is used for single line comments in-line with the code. docker_image.py is a nice example of well-commented code for a new class.

@mukultaneja
Copy link
Contributor Author

@rnjudge should I update this config file under setup section to add an instruction to install skopeo utility?

From what I can tell, circleci only supports ubuntu 1604 hosts for the test and skopeo needs 1804, correct? If this is the case, we should disable circleci tests and only use github actions to run the tests since github hosts use ubuntu 1804 as the default latest linux image. I think we should address this in a separate PR, though.

Yes, I checked and it uses 18.04.

@rnjudge
Copy link
Contributor

rnjudge commented Jun 17, 2020

@rnjudge should I update this config file under setup section to add an instruction to install skopeo utility?

From what I can tell, circleci only supports ubuntu 1604 hosts for the test and skopeo needs 1804, correct? If this is the case, we should disable circleci tests and only use github actions to run the tests since github hosts use ubuntu 1804 as the default latest linux image. I think we should address this in a separate PR, though.

Yes, I checked and it uses 18.04.

Ok, then let me disable circleci testing. Can you plan to open a separate PR to enable tests for images in the github config file (.github/workflows/pull_request.yml)?

@mukultaneja
Copy link
Contributor Author

mukultaneja commented Jun 17, 2020

@rnjudge should I update this config file under setup section to add an instruction to install skopeo utility?

From what I can tell, circleci only supports ubuntu 1604 hosts for the test and skopeo needs 1804, correct? If this is the case, we should disable circleci tests and only use github actions to run the tests since github hosts use ubuntu 1804 as the default latest linux image. I think we should address this in a separate PR, though.

Yes, I checked and it uses 18.04.

Ok, then let me disable circleci testing. Can you plan to open a separate PR to enable tests for images in the github config file (.github/workflows/pull_request.yml)?

@rnjudge , can I raise an issue for this change?

@rnjudge
Copy link
Contributor

rnjudge commented Jun 17, 2020

@rnjudge should I update this config file under setup section to add an instruction to install skopeo utility?

From what I can tell, circleci only supports ubuntu 1604 hosts for the test and skopeo needs 1804, correct? If this is the case, we should disable circleci tests and only use github actions to run the tests since github hosts use ubuntu 1804 as the default latest linux image. I think we should address this in a separate PR, though.

Yes, I checked and it uses 18.04.

Ok, then let me disable circleci testing. Can you plan to open a separate PR to enable tests for images in the github config file (.github/workflows/pull_request.yml)?

@rnjudge , can I raise an issue for this change?

Please!

@mukultaneja
Copy link
Contributor Author

In general, some comments in your code would be nice :) This is helpful as we review the PR and also for future contributors. Note that for comments describing the functionality of a function we use the three backticks enclosures (''' coment ''') instead of # . # is used for single line comments in-line with the code. docker_image.py is a nice example of well-commented code for a new class.

Done! Apologies for missing them at first place :)

@mukultaneja mukultaneja requested a review from rnjudge June 22, 2020 18:00
@nishakm
Copy link
Contributor

nishakm commented Jun 25, 2020

@mukultaneja I've triggered rerunning the builds so we will see if all the tests pass in a bit

Copy link
Contributor

@nishakm nishakm left a comment

Choose a reason for hiding this comment

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

@mukultaneja it looks like you've just copied over the functionality in the DockerImage class. The only thing you will need to do in this class is to implement load_image. Here you will need to look at the tarball created with podman save --format oci-archive -o debian.tar debian:latest. You can use any extra functions to help with that.

to_dict: return a dict representation of the object
'''

def __init__(self, repotag=None, image_id=None, image_name=None):
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we will have to use repotag here only. I will file an issue for that change to go through first.

Copy link
Contributor

Choose a reason for hiding this comment

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

The second may be to see if we can use the registry API to get the image. I can look at this further.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we will have to use repotag here only. I will file an issue for that change to go through first.

@nishakm I have resolved this comment in the commit.

tern/classes/oci_image.py Outdated Show resolved Hide resolved
@mukultaneja
Copy link
Contributor Author

@mukultaneja it looks like you've just copied over the functionality in the DockerImage class. The only thing you will need to do in this class is to implement load_image. Here you will need to look at the tarball created with podman save --format oci-archive -o debian.tar debian:latest. You can use any extra functions to help with that.

Could you please give me a little bit idea behind podman here? I am using below command to convert a docker image into OCI layout. Is the use of podman creating only one file which is index.json?

skopeo copy docker://<image_name> oci://<dir_name>/<image_name>:<tag_name>

tern/classes/oci_image.py Outdated Show resolved Hide resolved
tern/classes/oci_image.py Outdated Show resolved Hide resolved
tern/classes/oci_image.py Outdated Show resolved Hide resolved
tern/classes/oci_image.py Outdated Show resolved Hide resolved
tern/classes/oci_image.py Outdated Show resolved Hide resolved
tern/classes/oci_image.py Outdated Show resolved Hide resolved
@mukultaneja
Copy link
Contributor Author

mukultaneja commented Jul 6, 2020

@nishakm I have updated the code and tried to address all the given comments. Now in ths commit,

  1. I am loading index.json only one time and reading all the other information such as manifest, config and layers from it. I am using image_path property for it.
  2. Earlier, I was copying all the files inside working_dir location but now I am copying only layers and using the rest of the functionality as it is similar to docker images.
  3. I have written a helper utility helpers.validate_image_path to validate the OCI image directory layout given as the input to the executable.
  4. I am supporting two ways of image input oci:<image_location>:<image_tag> and oci:<image_name>:<image_tag> for example oci:/root/debian:latest and oci:debian:latest. In case of latter, I am assuming debain image layout is present in the current directory. I have already written method to check_image_string and parse_image_string similar to docker image.

Please review it once and share your feedback. I have also gone through the example you shared and if I understand it correctly then I think the architecture information is the key here to load the specific manifest. If it is correct then how should we get this information?

@mukultaneja mukultaneja requested a review from nishakm July 6, 2020 19:29
checksum_type = self.get_diff_checksum_type(image_index_data)
while layer_paths:
layer = ImageLayer(None, layer_paths.pop(0))
layer.set_checksum(checksum_type, layer.diff_id)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

here layer.diff_id will be None

Copy link
Contributor

Choose a reason for hiding this comment

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

Turns out, if you are using a tool to convert from a docker image to an OCI image, you may be able to get the layer's diff_id. But in this case, the layer's checksum can be found from the manifest's layers list.

@nishakm
Copy link
Contributor

nishakm commented Jul 10, 2020

Hi @mukultaneja, can you try to rebase your commit? I think your build will pass then. Sorry for the delay in replying.

Following commit adds a class to read OCI images
along with tests to validate its functionality.

Work towards: #678

Signed-off-by: mukultaneja <[email protected]>
@mukultaneja
Copy link
Contributor Author

Hi @mukultaneja, can you try to rebase your commit? I think your build will pass then. Sorry for the delay in replying.

Hi @nishakm, no issues :). I just did rebase my branch and now I am only getting issues for importing missing modules import-error / Unable to import 'tern.analyze.oci' and I think it makes sense as of now.

Copy link
Contributor

@nishakm nishakm left a comment

Choose a reason for hiding this comment

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

It looks like a couple of file changes are missing from this PR and the tests are referencing unknown modules.

Another thing I have found out from my experiments is that querying the Dockerhub API may get you an OCI image format. I still need to poke at that direction. So I am going to hold off on providing feedback on this PR until I have something concrete for you.

raise NameError("Image object initialized with no repotag")

# parse the repotag
repo_dict = general.parse_oci_image_string(self._repotag)
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess I am expecting an addition of a function in general.py?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah

Comment on lines +33 to +36
self._name = repo_dict.get('name')
self._tag = repo_dict.get('tag')
self._image_path = repo_dict.get('path')

Copy link
Contributor

Choose a reason for hiding this comment

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

I think what would be better is if this functionality got moved to the Image class so the DockerImage class can also take advantage of it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, I think self._name and self._tag are common so we can move it to Image class but self._image_path we have to keep it in oci_image.

def load_image(self):
'''Load OCI image metadata using manifest'''
try:
# validate OCI iamge's directory layout
Copy link
Contributor

Choose a reason for hiding this comment

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

s/iamge's/image's

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure. its a typo. my bad!

'''Load OCI image metadata using manifest'''
try:
# validate OCI iamge's directory layout
helpers.validate_image_path(self.image_path)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can put this function in here instead of helpers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok. I am neutral to keep it here as well.

checksum_type = self.get_diff_checksum_type(image_index_data)
while layer_paths:
layer = ImageLayer(None, layer_paths.pop(0))
layer.set_checksum(checksum_type, layer.diff_id)
Copy link
Contributor

Choose a reason for hiding this comment

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

Turns out, if you are using a tool to convert from a docker image to an OCI image, you may be able to get the layer's diff_id. But in this case, the layer's checksum can be found from the manifest's layers list.

@mukultaneja
Copy link
Contributor Author

mukultaneja commented Jul 11, 2020

@nishakm, I remember last time we discussed that we are not concerned to get diff_id for OCI images as primarily it is a docker image property. I think that is why you gave a comment to remove the method from the class.

@mukultaneja
Copy link
Contributor Author

It looks like a couple of file changes are missing from this PR and the tests are referencing unknown modules.

Another thing I have found out from my experiments is that querying the Dockerhub API may get you an OCI image format. I still need to poke at that direction. So I am going to hold off on providing feedback on this PR until I have something concrete for you.

Sure. Please let me know if I can help with the experiment. Just one thing here to ask, is it going to change the oci image input to tern? If no, then cant we go with skopeo and avail the OCI image analysis first and keep updating it for better.

@nishakm
Copy link
Contributor

nishakm commented Jul 13, 2020

It looks like a couple of file changes are missing from this PR and the tests are referencing unknown modules.
Another thing I have found out from my experiments is that querying the Dockerhub API may get you an OCI image format. I still need to poke at that direction. So I am going to hold off on providing feedback on this PR until I have something concrete for you.

Sure. Please let me know if I can help with the experiment. Just one thing here to ask, is it going to change the oci image input to tern? If no, then cant we go with skopeo and avail the OCI image analysis first and keep updating it for better.

It probably will in the sense that we don't need skopeo to do any of the conversion, but I will have to find out if that is true or not and how we can implement it. So stay tuned!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants