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: Use posix path for dockerfile path passed to docker build API #5528

Merged
merged 5 commits into from
Jul 21, 2023
Merged
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
2 changes: 1 addition & 1 deletion samcli/lib/build/app_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ def _build_lambda_image(self, function_name: str, metadata: Dict, architecture:

build_args = {
"path": str(docker_context_dir),
"dockerfile": dockerfile,
"dockerfile": str(pathlib.Path(dockerfile).as_posix()),
"tag": docker_tag,
"buildargs": docker_build_args,
"platform": get_docker_platform(architecture),
Expand Down
2 changes: 1 addition & 1 deletion samcli/lib/samlib/resource_metadata_normalizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def _extract_image_asset_metadata(metadata):
asset_path = Path(metadata.get(ASSET_PATH_METADATA_KEY, ""))
dockerfile_path = Path(metadata.get(ASSET_DOCKERFILE_PATH_KEY), "")
return {
SAM_METADATA_DOCKERFILE_KEY: str(dockerfile_path),
SAM_METADATA_DOCKERFILE_KEY: str(dockerfile_path.as_posix()),
SAM_METADATA_DOCKER_CONTEXT_KEY: str(asset_path),
SAM_METADATA_DOCKER_BUILD_ARGS_KEY: metadata.get(ASSET_DOCKERFILE_BUILD_ARGS_KEY, {}),
}
Expand Down
75 changes: 75 additions & 0 deletions tests/integration/buildcmd/test_build_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,40 @@ def test_intermediate_container_deleted(self, dockerfile, expected):
_num_of_containers_before_build, _num_of_containers_after_build, "Intermediate containers are not removed"
)

@parameterized.expand(
[
("feature_phi\\Dockerfile", {"phi": "1.62"}),
("feature_pi\\Dockerfile", {"pi": "3.14"}),
]
)
@pytest.mark.flaky(reruns=3)
@skipIf(not IS_WINDOWS, "Skipping passing Windows path for dockerfile path on non Windows platform")
def test_windows_dockerfile_present_sub_dir(self, dockerfile, expected):
_tag = f"{random.randint(1, 100)}"
overrides = {
"Runtime": "3.9",
"Handler": "main.handler",
"DockerFile": dockerfile,
"Tag": _tag,
}
cmdlist = self.get_command_list(use_container=False, parameter_overrides=overrides)

LOG.info("Running Command: ")
LOG.info(cmdlist)
command_result = run_command(cmdlist, cwd=self.working_dir)
self.assertEqual(command_result.process.returncode, 0)

self._verify_image_build_artifact(
self.built_template,
self.FUNCTION_LOGICAL_ID_IMAGE,
"ImageUri",
f"{self.FUNCTION_LOGICAL_ID_IMAGE.lower()}:{_tag}",
)

self._verify_invoke_built_function(
self.built_template, self.FUNCTION_LOGICAL_ID_IMAGE, self._make_parameter_override_arg(overrides), expected
)


@skipIf(
# Hits public ECR pull limitation, move it to canary tests
Expand Down Expand Up @@ -546,6 +580,47 @@ def test_cdk_app_with_default_requirements(self):
)


@skipIf(
# Hits public ECR pull limitation, move it to canary tests
SKIP_DOCKER_TESTS,
"Skip build tests that requires Docker in CI environment",
)
@parameterized_class(
(
"template",
"FUNCTION_LOGICAL_ID",
"overrides",
"use_container",
"prop",
),
[
(
"cdk_v2_synthesized_template_image_function_shared_code.json",
"TestLambdaFunctionC089708A",
False,
False,
"Code.ImageUri",
),
],
)
class TestBuildCommandCDKPythonImageFunctionSharedCode(BuildIntegPythonBase):
@pytest.mark.flaky(reruns=3)
def test_cdk_app_with_default_requirements(self):
expected = "Hello World"
cmdlist = self.get_command_list(use_container=self.use_container)
command_result = run_command(cmdlist, cwd=self.working_dir)
self.assertEqual(command_result.process.returncode, 0)

self._verify_image_build_artifact(
self.built_template,
self.FUNCTION_LOGICAL_ID,
self.prop,
f"{self.FUNCTION_LOGICAL_ID.lower()}:latest",
)

self._verify_invoke_built_function(self.built_template, self.FUNCTION_LOGICAL_ID, {}, expected)


class TestBuildCommand_PythonFunctions_With_Specified_Architecture(BuildIntegPythonBase):
template = "template_with_architecture.yaml"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ARG BASE_RUNTIME

FROM public.ecr.aws/lambda/python:$BASE_RUNTIME

COPY myimage/main.py $FUNCTION_DIR

CMD [ "main.handler" ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def handler(event, context):
return "Hello World"
Loading
Loading