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

Scuba crashes with GitLab CI image dictionary #229

Open
xanarin opened this issue Sep 20, 2023 · 2 comments
Open

Scuba crashes with GitLab CI image dictionary #229

xanarin opened this issue Sep 20, 2023 · 2 comments
Labels
bug gitlab-ci Issues related to compatibility with .gitlab-ci.yml starter-bug A good bug for new contributors

Comments

@xanarin
Copy link
Collaborator

xanarin commented Sep 20, 2023

Currently, if one specifies a .scuba.yml like this:

aliases:
  build: !from_yaml .gitlab-ci.yml build

With a GitLab CI configuration file like this:

build:
  stage: build
  image:
    name: debian:12
  script:
    - echo "Ran successfully"

When one runs scuba build, they will see the following stack trace:

$ scuba build
Traceback (most recent call last):
  File "/home/wsloan/.local/bin/scuba", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/wsloan/.local/pipx/venvs/scuba/lib/python3.11/site-packages/scuba/__main__.py", line 184, in main
    rc = run_scuba(scuba_args) or 0
         ^^^^^^^^^^^^^^^^^^^^^
  File "/home/wsloan/.local/pipx/venvs/scuba/lib/python3.11/site-packages/scuba/__main__.py", line 138, in run_scuba
    dive = ScubaDive(
           ^^^^^^^^^^
  File "/home/wsloan/.local/pipx/venvs/scuba/lib/python3.11/site-packages/scuba/scuba.py", line 104, in __init__
    self.__setup_native_run()
  File "/home/wsloan/.local/pipx/venvs/scuba/lib/python3.11/site-packages/scuba/scuba.py", line 294, in __setup_native_run
    ep = get_image_entrypoint(self.context.image)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/wsloan/.local/pipx/venvs/scuba/lib/python3.11/site-packages/scuba/dockerutil.py", line 131, in get_image_entrypoint
    return _get_image_config(image, "Entrypoint")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/wsloan/.local/pipx/venvs/scuba/lib/python3.11/site-packages/scuba/dockerutil.py", line 114, in _get_image_config
    info = docker_inspect_or_pull(image)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/wsloan/.local/pipx/venvs/scuba/lib/python3.11/site-packages/scuba/dockerutil.py", line 82, in docker_inspect_or_pull
    return docker_inspect(image)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/wsloan/.local/pipx/venvs/scuba/lib/python3.11/site-packages/scuba/dockerutil.py", line 59, in docker_inspect
    cp = _run_docker("inspect", "--type", "image", image, capture=True)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/wsloan/.local/pipx/venvs/scuba/lib/python3.11/site-packages/scuba/dockerutil.py", line 49, in _run_docker
    return subprocess.run(docker_args, **kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/subprocess.py", line 548, in run
    with Popen(*popenargs, **kwargs) as process:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/subprocess.py", line 1024, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.11/subprocess.py", line 1834, in _execute_child
    self.pid = _fork_exec(
               ^^^^^^^^^^^
TypeError: expected str, bytes or os.PathLike object, not dict

One can argue that Scuba shouldn't handle this use of image as a dictionary with multiple members, but at the very least Scuba shouldn't crash in this case and should give the user a helpful error message. I think it would also be fine for Scuba to accept this format of image, though I don't think we can correctly support the entrypoint element of the image dictionary.

@xanarin xanarin added the bug label Sep 20, 2023
@JonathonReinhart JonathonReinhart added the gitlab-ci Issues related to compatibility with .gitlab-ci.yml label Sep 21, 2023
@JonathonReinhart
Copy link
Owner

Bug

One can argue that Scuba shouldn't handle this use of image as a dictionary with multiple members, but at the very least Scuba shouldn't crash in this case and should give the user a helpful error message.

Agreed.

It looks like this is only a problem for images: in an alias because the config code uses a raw dict.get() call there. Because dict.get() returns Any, it can be assigned to the Optional[str] type which is not correct:

                image=node.get("image"),

The top-level images: probably does not exhibit this however, because the config code for that uses the _get_str() helper which raises a ConfigError at runtime if the value is not a str:

        self._image = _get_str(data, "image")

I think it would be an easy "fix" (for the crash) to make them both use the helper function.

Feature

I think it would also be fine for Scuba to accept this format of image

Would you mind opening a separate "enhancement" issue that requests adding support for the long-form images:? I think it's okay to include entrypoint (and any other crazy sub-keys they have these days) in that discussion. We can always peel it off and defer it if necessary.

though I don't think we can correctly support the entrypoint element of the image dictionary.

I don't see why not. scuba.yml already has an entrypoint configuration option, so I think it would be purely a matter of internally handling the two config schemas (and aborting if they're both set, I guess).

@JonathonReinhart JonathonReinhart added the starter-bug A good bug for new contributors label Sep 21, 2023
@xanarin
Copy link
Collaborator Author

xanarin commented Sep 26, 2023

Would you mind opening a separate "enhancement" issue that requests adding support for the long-form images:?

Opened #230. Cool, I had forgotten that Scuba supports an entrypoint configuration option. In that case I think we should support it when including a GitLab CI file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug gitlab-ci Issues related to compatibility with .gitlab-ci.yml starter-bug A good bug for new contributors
Projects
None yet
Development

No branches or pull requests

2 participants