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: validate architecture before trying to pull the build image #6118

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
13 changes: 13 additions & 0 deletions samcli/local/docker/lambda_build_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,21 @@
from typing import List
from uuid import uuid4

from samcli.commands.exceptions import UserException
from samcli.lib.utils.architecture import X86_64, ARM64
from samcli.commands._utils.experimental import get_enabled_experimental_flags
from samcli.local.docker.container import Container

LOG = logging.getLogger(__name__)


class InvalidArchitectureForImage(UserException):
"""
Raised when architecture that is provided for the image is invalid
"""
pass


class LambdaBuildContainer(Container):
"""
Class to manage Build containers that are capable of building AWS Lambda functions.
Expand Down Expand Up @@ -297,4 +306,8 @@ def get_image_tag(architecture):
str
Image tag
"""
if architecture not in [X86_64, ARM64]:
raise InvalidArchitectureForImage(
f"'{architecture}' is not a valid architecture, it should be either '{X86_64}' or '{ARM64}'"
)
return f"{LambdaBuildContainer._IMAGE_TAG}-{architecture}"
6 changes: 5 additions & 1 deletion tests/unit/local/docker/test_lambda_build_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from parameterized import parameterized

from samcli.lib.utils.architecture import X86_64, ARM64
from samcli.local.docker.lambda_build_container import LambdaBuildContainer
from samcli.local.docker.lambda_build_container import LambdaBuildContainer, InvalidArchitectureForImage


class TestLambdaBuildContainer_init(TestCase):
Expand Down Expand Up @@ -217,6 +217,10 @@ class TestLambdaBuildContainer_get_image_tag(TestCase):
def test_must_get_image_tag(self, architecture, expected_image_tag):
self.assertEqual(expected_image_tag, LambdaBuildContainer.get_image_tag(architecture))

def test_must_raise_an_error_for_invalid_architecture(self):
with self.assertRaises(InvalidArchitectureForImage):
LambdaBuildContainer.get_image_tag("invalid-architecture")


class TestLambdaBuildContainer_get_entrypoint(TestCase):
def test_must_get_entrypoint(self):
Expand Down