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

Added docker image test script #1733

Merged
merged 16 commits into from
Mar 6, 2021
Merged

Conversation

vfdev-5
Copy link
Collaborator

@vfdev-5 vfdev-5 commented Mar 3, 2021

Addresses #1644

Description:

  • Added docker image test python script

Check list:

  • New tests are added (if a new feature is added)
  • New doc strings: description and/or example code are in RST format
  • Documentation is updated (if required)

@trsvchn
Copy link
Collaborator

trsvchn commented Mar 3, 2021

there is python package docker? Nice!)

Since, I've started from subprocess.run :)

@vfdev-5
Copy link
Collaborator Author

vfdev-5 commented Mar 3, 2021

Yes, I tried that from my side to see if this could work. @trsvchn if you'd like to review, feel free to comment out and give a feedback.

@vfdev-5
Copy link
Collaborator Author

vfdev-5 commented Mar 3, 2021

And sorry for overlapping !

@trsvchn
Copy link
Collaborator

trsvchn commented Mar 3, 2021

No problem, sorry, I was busy yesterday. and now I know about docker python so it worth it :)

@vfdev-5
Copy link
Collaborator Author

vfdev-5 commented Mar 4, 2021

@trsvchn do you have an idea why it can't find installed docker package ?
https://github.com/pytorch/ignite/pull/1733/checks?check_run_id=2031974887#step:4:838

@trsvchn
Copy link
Collaborator

trsvchn commented Mar 4, 2021

@vfdev-5 Oh, I think I know what is happening

@trsvchn
Copy link
Collaborator

trsvchn commented Mar 4, 2021

$AGENT_TOOLSDIRECTORY is /opt/hostedtoolcache

and

  env:
    pythonLocation: /opt/hostedtoolcache/Python/3.7.10/x64
    LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.7.10/x64/lib

Thus:

sudo rm -rf "/usr/local/share/boost"
sudo rm -rf "$AGENT_TOOLSDIRECTORY"

Removes python libs and python

@vfdev-5
Copy link
Collaborator Author

vfdev-5 commented Mar 4, 2021

Oh, I see. Should we just reinstall it after building ?

@trsvchn
Copy link
Collaborator

trsvchn commented Mar 4, 2021

But, wait, pyaml works fine

@vfdev-5
Copy link
Collaborator Author

vfdev-5 commented Mar 4, 2021

pyyaml is OK as it is used only before the suppression

@trsvchn
Copy link
Collaborator

trsvchn commented Mar 4, 2021

Yes, for base images
but we reuse it in later steps

@trsvchn
Copy link
Collaborator

trsvchn commented Mar 4, 2021

Let's try

sudo rm -rf "/usr/local/share/boost"
sudo rm -rf "$AGENT_TOOLSDIRECTORY"

Just after the checkout, and before Python install actiob

@vfdev-5
Copy link
Collaborator Author

vfdev-5 commented Mar 4, 2021

@trsvchn seems like it works !

@trsvchn
Copy link
Collaborator

trsvchn commented Mar 4, 2021

Great!

@github-actions github-actions bot added the docker label Mar 5, 2021
@vfdev-5
Copy link
Collaborator Author

vfdev-5 commented Mar 6, 2021

@trsvchn I'm struggling with test_image.py script and the way how to expose details of the error when using docker python api. For example, here https://github.com/pytorch/ignite/pull/1733/checks?check_run_id=2046167278#step:6:605
import command is failing but we have no idea what is the error message.
Basically, the following code is missing something.

def run_python_cmd(cmd):
    try:
        out = client.containers.run(args.image, f"python -c '{cmd}'", auto_remove=True, stderr=True,)
        assert isinstance(out, bytes), type(out)
        out = out.decode("utf-8").strip()
    except docker.errors.ContainerError as e:
        raise RuntimeError(e)
    return out

Any ideas how to improve it ?

@trsvchn
Copy link
Collaborator

trsvchn commented Mar 6, 2021

@vfdev-5 sure! I'll test test_image.py in my sandbox

@vfdev-5
Copy link
Collaborator Author

vfdev-5 commented Mar 6, 2021

I'm thinking to do something like

def run_python_cmd(cmd):

    try_except_cmd = f"""

def main():
    {cmd}

try:
    main()
except Exception as e:
    import traceback
    print(traceback.format_exc())    
    """
    try:
        out = client.containers.run(args.image, f"python -c '{try_except_cmd}'", auto_remove=True, stderr=True,)
        assert isinstance(out, bytes), type(out)
        out = out.decode("utf-8").strip()

        if any([k in out.lower() for k in ["error", "exception"]]):
            raise RuntimeError(out)

    except docker.errors.ContainerError as e:
        raise RuntimeError(e)
    return out

but this looks like a hack...

@trsvchn
Copy link
Collaborator

trsvchn commented Mar 6, 2021

@vfdev-5 Yes!, I think the problem is in that cmd raises exceptions, since this generates exit code 1 and it forces run method to raise exception:

$ python -c 'raise RuntimeError'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
RuntimeError

$ echo $?
1
    Raises:
        :py:class:`docker.errors.ContainerError`
            If the container exits with a non-zero exit code and

we should handle this quietly

@vfdev-5
Copy link
Collaborator Author

vfdev-5 commented Mar 6, 2021

That's right. But what I'd like to have is to execute tests like import cv2 and ensure that it passes and if not say that explicitly : "ModuleNotFoundError: No module named 'cv2'".
I was just thinking if there is a proper way to get error message without 2 levels of exception trackings

@trsvchn
Copy link
Collaborator

trsvchn commented Mar 6, 2021

What about to try detach=True, with this param, run method returns container and logs:

       If ``detach`` is ``True``, a :py:class:`Container` object is returned instead.

https://github.com/docker/docker-py/blob/55f405e04a91ddbbc26aa738bd3cb41bd28f8dbd/docker/models/containers.py#L536-L541

@vfdev-5
Copy link
Collaborator Author

vfdev-5 commented Mar 6, 2021

detach or not detach this is the question :)
Well, actually, the context is that I do not understand why there is no cv2 module in msdp-apex-vision image and I can not rerpo that locally...

@trsvchn
Copy link
Collaborator

trsvchn commented Mar 6, 2021

cv or not 2cv ... or cv2

@trsvchn
Copy link
Collaborator

trsvchn commented Mar 6, 2021

It seems to work fine

@vfdev-5 vfdev-5 merged commit 4fc1edf into pytorch:master Mar 6, 2021
@vfdev-5 vfdev-5 deleted the added-docker-image-test branch March 6, 2021 22:36
@vfdev-5
Copy link
Collaborator Author

vfdev-5 commented Mar 6, 2021

Let's see if we can finally update our docker images

@vfdev-5 vfdev-5 restored the added-docker-image-test branch March 6, 2021 23:23
@vfdev-5 vfdev-5 deleted the added-docker-image-test branch March 6, 2021 23:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants