Skip to content

Commit

Permalink
add _process_image for image:name
Browse files Browse the repository at this point in the history
  • Loading branch information
funkecoder23 authored and funkecoder23 committed May 27, 2024
1 parent 432fe6c commit 0f6f348
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
13 changes: 13 additions & 0 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,19 @@ The ``image`` node is usually necessary but, as of scuba 2.5, can be omitted
for ``.scuba.yml`` files in which only the ``aliases`` are intended to be used.


Example:

.. code-block:: yaml
# .gitlab-ci.yml
image:
name: debian:8.2
# .scuba.yml
image: !from_yaml \\.gitlab-ci.yml image
The ``image`` node can also

.. _conf_environment:

``environment``
Expand Down
36 changes: 31 additions & 5 deletions scuba/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,34 @@ def _process_environment(node: CfgNode, name: str) -> Environment:
return result


def _process_image(node: CfgNode) -> Optional[str]:
"""Process an image-type node
Args:
node: A node of image data retrieved from a YAML document.
Should be an "image schema" node as described in docs/configuration.rst.
Returns:
An image name
"""
if isinstance(node, str):
# The image is just the text itself
return node

if isinstance(node, dict):
# There must be a "name" key, which must be a string
image = node.get("name")
if not image:
raise ConfigError(f"image: must have a 'name' subkey")

if isinstance(image, str):
return image

raise ConfigError(f"image.name: must be a string")

return None


def _get_nullable_str(data: Dict[str, Any], key: str) -> Optional[str]:
# N.B. We can't use data.get() here, because that might return
# None, leading to ambiguity between the key being absent or set
Expand Down Expand Up @@ -329,13 +357,11 @@ def _get_typed_val(


@overload # When default is None, can return None (Optional).
def _get_str(data: CfgData, key: str, default: None = None) -> Optional[str]:
...
def _get_str(data: CfgData, key: str, default: None = None) -> Optional[str]: ...


@overload # When default is non-None, cannot return None.
def _get_str(data: CfgData, key: str, default: str) -> str:
...
def _get_str(data: CfgData, key: str, default: str) -> str: ...


def _get_str(data: CfgData, key: str, default: Optional[str] = None) -> Optional[str]:
Expand Down Expand Up @@ -567,7 +593,7 @@ def __init__(
+ ", ".join(extra)
)

self._image = _get_str(data, "image")
self._image = _process_image(data.get("image"))
self.shell = _get_str(data, "shell", DEFAULT_SHELL)
self.entrypoint = _get_entrypoint(data)
self.docker_args = _get_docker_args(data)
Expand Down

0 comments on commit 0f6f348

Please sign in to comment.