Skip to content
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
1 change: 1 addition & 0 deletions samcli/lib/build/app_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ def _build_lambda_image(self, function_name: str, metadata: Dict, architecture:
"buildargs": docker_build_args,
"decode": True,
"platform": get_docker_platform(architecture),
"rm": True,
}
if docker_build_target:
build_args["target"] = cast(str, docker_build_target)
Expand Down
7 changes: 7 additions & 0 deletions tests/integration/buildcmd/build_integ_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ def verify_docker_container_cleanedup(self, runtime):
)
self.assertFalse(bool(samcli_containers), "Build containers have not been removed")

def get_number_of_created_containers(self):
if IS_WINDOWS:
time.sleep(1)
docker_client = docker.from_env()
containers = docker_client.containers.list(all=True)
return len(containers)

def verify_pulled_image(self, runtime, architecture=X86_64):
docker_client = docker.from_env()
image_name = f"{LambdaBuildContainer._IMAGE_URI_PREFIX}-{runtime}"
Expand Down
34 changes: 34 additions & 0 deletions tests/integration/buildcmd/test_build_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,40 @@ def test_with_default_requirements(self, runtime, use_container):
self.built_template, self.FUNCTION_LOGICAL_ID_IMAGE, self._make_parameter_override_arg(overrides), expected
)

@pytest.mark.flaky(reruns=3)
def test_intermediate_container_deleted(self):
_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)

_num_of_containers_before_build = self.get_number_of_created_containers()
run_command(cmdlist, cwd=self.working_dir)
_num_of_containers_after_build = self.get_number_of_created_containers()

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

expected = {"pi": "3.14"}
self._verify_invoke_built_function(
self.built_template, self.FUNCTION_LOGICAL_ID_IMAGE, self._make_parameter_override_arg(overrides), expected
)

self.assertEqual(
_num_of_containers_before_build, _num_of_containers_after_build, "Intermediate containers are not removed"
)


@skipIf(
# Hits public ECR pull limitation, move it to canary tests
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/lib/build_module/test_app_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,7 @@ def test_can_build_image_function_under_debug(self, mock_os):
buildargs={"a": "b", "SAM_BUILD_MODE": "debug"},
decode=True,
platform="linux/amd64",
rm=True,
),
)

Expand Down Expand Up @@ -1173,6 +1174,7 @@ def test_can_build_image_function_under_debug_with_target(self, mock_os):
decode=True,
target="stage",
platform="linux/amd64",
rm=True,
),
)

Expand Down