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

fix: Add error handling for provided runtime layer building #5733

Merged
merged 7 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion samcli/lib/build/app_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
BuildError,
BuildInsideContainerError,
UnsupportedBuilderLibraryVersionError,
MissingCompatibleRuntimesException,
)
from samcli.lib.build.workflow_config import (
get_workflow_config,
Expand All @@ -62,6 +63,8 @@

LOG = logging.getLogger(__name__)

FIRST_COMPATIBLE_RUNTIME_INDEX = 0


class ApplicationBuildResult(NamedTuple):
"""
Expand Down Expand Up @@ -546,7 +549,12 @@ def _build_layer(
)
# Only set to this value if specified workflow is makefile
# which will result in config language as provided
build_runtime = compatible_runtimes[0]
if not compatible_runtimes:
mildaniel marked this conversation as resolved.
Show resolved Hide resolved
raise MissingCompatibleRuntimesException(
"The 'CompatibleRuntimes' field in the Layer Version configuration is "
"missing and is required for building provided runtimes using a container."
)
build_runtime = compatible_runtimes[FIRST_COMPATIBLE_RUNTIME_INDEX]
global_image = self._build_images.get(None)
image = self._build_images.get(layer_name, global_image)
# pass to container only when specified workflow is supported to overwrite runtime to get image
Expand Down
5 changes: 5 additions & 0 deletions samcli/lib/build/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ def __init__(self, msg: str) -> None:
BuildError.__init__(self, "MissingBuildMethodException", msg)


class MissingCompatibleRuntimesException(BuildError):
def __init__(self, msg: str) -> None:
BuildError.__init__(self, "MissingCompatibleRuntimesException", msg)


class InvalidBuildGraphException(Exception):
def __init__(self, msg: str) -> None:
Exception.__init__(self, msg)
25 changes: 25 additions & 0 deletions tests/unit/lib/build_module/test_app_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from parameterized import parameterized

from samcli.lib.build.exceptions import MissingCompatibleRuntimesException
from samcli.lib.build.workflow_config import UnsupportedRuntimeException
from samcli.lib.providers.provider import ResourcesToBuildCollector, Function, FunctionBuildInfo
from samcli.lib.build.app_builder import (
Expand Down Expand Up @@ -571,6 +572,30 @@ def test_must_build_layer_in_process(self, get_layer_subfolder_mock, osutils_moc
is_building_layer=True,
)

@parameterized.expand([([],), (None,)])
@patch("samcli.lib.build.app_builder.get_workflow_config")
@patch("samcli.lib.build.app_builder.get_layer_subfolder")
def test_must_handle_layer_build_compatible_runtimes_missing(
self, compatible_runtimes, get_layer_subfolder_mock, get_workflow_config_mock
):
get_layer_subfolder_mock.return_value = "layer"
config_mock = Mock()
config_mock.manifest_name = "manifest_name"
config_mock.language = "provided"

get_workflow_config_mock.return_value = config_mock

self.builder._container_manager = Mock()

with self.assertRaises(MissingCompatibleRuntimesException) as ex:
self.builder._build_layer("layer_name", "code_uri", "provided", compatible_runtimes, ARM64, "full_path")

self.assertEqual(
str(ex.exception),
"The 'CompatibleRuntimes' field in the Layer Version configuration is "
"missing and is required for building provided runtimes using a container.",
)

@patch("samcli.lib.build.app_builder.get_workflow_config")
@patch("samcli.lib.build.app_builder.osutils")
@patch("samcli.lib.build.app_builder.get_layer_subfolder")
Expand Down
Loading