Skip to content

Commit

Permalink
Use the same DockerContext and Dockerfile paths as the CDK is using
Browse files Browse the repository at this point in the history
  • Loading branch information
i18n-tribe committed Jul 21, 2022
1 parent bdb8b96 commit a8a5775
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 2 additions & 4 deletions samcli/lib/samlib/resource_metadata_normalizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,9 @@ def _extract_image_asset_metadata(metadata):
"""
asset_path = Path(metadata.get(ASSET_PATH_METADATA_KEY, ""))
dockerfile_path = Path(metadata.get(ASSET_DOCKERFILE_PATH_KEY), "")
dockerfile, path_from_asset = dockerfile_path.stem, dockerfile_path.parent
dockerfile_context = str(Path(asset_path.joinpath(path_from_asset)))
return {
SAM_METADATA_DOCKERFILE_KEY: dockerfile,
SAM_METADATA_DOCKER_CONTEXT_KEY: dockerfile_context,
SAM_METADATA_DOCKERFILE_KEY: str(dockerfile_path),
SAM_METADATA_DOCKER_CONTEXT_KEY: str(asset_path),
SAM_METADATA_DOCKER_BUILD_ARGS_KEY: metadata.get(ASSET_DOCKERFILE_BUILD_ARGS_KEY, {}),
}

Expand Down
10 changes: 6 additions & 4 deletions tests/unit/lib/samlib/test_resource_metadata_normalizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,13 @@ def test_replace_all_resources_that_contain_image_metadata(self):

ResourceMetadataNormalizer.normalize(template_data)

expected_docker_context_path = str(pathlib.Path("/path", "to", "asset", "path", "to"))
expected_docker_context_path = str(pathlib.Path("/path", "to", "asset"))
self.assertEqual("function1", template_data["Resources"]["Function1"]["Properties"]["Code"]["ImageUri"])
self.assertEqual(
expected_docker_context_path, template_data["Resources"]["Function1"]["Metadata"]["DockerContext"]
)
self.assertEqual("Dockerfile", template_data["Resources"]["Function1"]["Metadata"]["Dockerfile"])
expected_dockerfile_path = str(pathlib.Path("path", "to", "Dockerfile"))
self.assertEqual(expected_dockerfile_path, template_data["Resources"]["Function1"]["Metadata"]["Dockerfile"])
self.assertEqual(docker_build_args, template_data["Resources"]["Function1"]["Metadata"]["DockerBuildArgs"])
self.assertEqual("Function1", template_data["Resources"]["Function1"]["Metadata"]["SamResourceId"])

Expand Down Expand Up @@ -138,12 +139,13 @@ def test_replace_all_resources_that_contain_image_metadata_windows_paths(self):

ResourceMetadataNormalizer.normalize(template_data)

expected_docker_context_path = str(pathlib.Path("C:\\path\\to\\asset").joinpath(pathlib.Path("rel/path/to")))
expected_docker_context_path = str(pathlib.Path("C:\\path\\to\\asset"))
self.assertEqual("function1", template_data["Resources"]["Function1"]["Properties"]["Code"]["ImageUri"])
self.assertEqual(
expected_docker_context_path, template_data["Resources"]["Function1"]["Metadata"]["DockerContext"]
)
self.assertEqual("Dockerfile", template_data["Resources"]["Function1"]["Metadata"]["Dockerfile"])
expected_dockerfile_path = str(pathlib.Path("rel/path/to/Dockerfile"))
self.assertEqual(expected_dockerfile_path, template_data["Resources"]["Function1"]["Metadata"]["Dockerfile"])
self.assertEqual(docker_build_args, template_data["Resources"]["Function1"]["Metadata"]["DockerBuildArgs"])
self.assertEqual("Function1", template_data["Resources"]["Function1"]["Metadata"]["SamResourceId"])

Expand Down

0 comments on commit a8a5775

Please sign in to comment.