Skip to content

Commit

Permalink
Bugfix to allow blank string for Artifacts
Browse files Browse the repository at this point in the history
Bugfix for removing lingering generated images
  • Loading branch information
shanejbrown committed Nov 1, 2023
1 parent 51a349a commit c9aafea
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 15 deletions.
23 changes: 12 additions & 11 deletions buildrunner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,18 @@ def run(self): # pylint: disable=too-many-statements,too-many-branches,too-many
self._write_artifact_manifest()

_docker_client = docker.new_client(timeout=self.docker_timeout)

# cleanup the source image
if self._source_image:
self.log.write(
f"Destroying source image {self._source_image}\n"
)
_docker_client.remove_image(
self._source_image,
noprune=False,
force=True,
)

if self.cleanup_images:
self.log.write(
'Removing local copy of generated images\n'
Expand All @@ -715,17 +727,6 @@ def run(self): # pylint: disable=too-many-statements,too-many-branches,too-many
self.log.write(
'Keeping generated images\n'
)

# cleanup the source image
if self._source_image:
self.log.write(
f"Destroying source image {self._source_image}\n"
)
_docker_client.remove_image(
self._source_image,
noprune=False,
force=True,
)
if self._source_archive:
self.log.write(
"Destroying source archive\n"
Expand Down
19 changes: 15 additions & 4 deletions buildrunner/validation/step.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,21 @@
with the terms of the Adobe license agreement accompanying it.
"""

from typing import Any, Dict, List, Optional, Union
from typing import Any, Annotated, Dict, List, Optional, TypeVar, Union

# pylint: disable=no-name-in-module
from pydantic import BaseModel, Field
from pydantic import BaseModel, BeforeValidator, Field

T = TypeVar('T')


def _validate_artifact_type(value) -> T:
if value and not Artifact.model_validate(value):
raise ValueError(f'Invalid artifact type: {value}')
return value


AnnotatedArtifact = Annotated[T, BeforeValidator(_validate_artifact_type)]


class StepPypiPush(BaseModel, extra='forbid'):
Expand Down Expand Up @@ -82,7 +93,7 @@ class StepRun(RunAndServicesBase, extra='forbid'):
services: Optional[Dict[str, Service]] = None
cmds: Optional[List[str]] = None
ssh_keys: Optional[List[str]] = Field(alias='ssh-keys', default=None)
artifacts: Optional[Dict[str, Union[Artifact, None]]] = None
artifacts: Optional[Dict[str, Optional[AnnotatedArtifact]]] = None
platform: Optional[str] = None
cap_add: Optional[Union[str, List[str]]] = None
privileged: Optional[bool] = None
Expand All @@ -95,7 +106,7 @@ class StepRemote(BaseModel, extra='forbid'):
# Not sure if host is optional or required
host: Optional[str] = None
cmd: str
artifacts: Optional[Dict[str, Optional[Artifact]]] = None
artifacts: Optional[Dict[str, Optional[AnnotatedArtifact]]] = None


class StepPushCommitDict(BaseModel, extra='forbid'):
Expand Down
15 changes: 15 additions & 0 deletions tests/test_config_validation/test_validation_artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def test_step_type_valid():


def test_push_invalid():
# Push must be a boolean
config_yaml = """
steps:
build-run:
Expand All @@ -110,6 +111,20 @@ def test_push_invalid():
assert errors.count() == 1


def test_valid_artifacts_blank_string():
config_yaml = """
steps:
build-run:
run:
artifacts:
bogus/path/to/artifacts/*: ''
bogus/path/to/this_thing: ''
"""
config = yaml.load(config_yaml, Loader=yaml.Loader)
errors = validate_config(**config)
assert errors is None


def test_push_valid():
config_yaml = """
steps:
Expand Down
1 change: 1 addition & 0 deletions tests/test_config_validation/test_validation_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def test_push_valid():


def test_push_invalid():
# Push must be a boolean
config_yaml = """
steps:
build-run:
Expand Down

0 comments on commit c9aafea

Please sign in to comment.