feat: remove the created intermediate containers while building the lambda functions of Image Type#3922
Conversation
…mage type lambda functions
|
Is this the right behavior we want? I ask because from https://docs.docker.com/engine/reference/commandline/images/: "Docker images have intermediate layers that increase reusability, decrease disk usage, and speed up docker build by allowing each step to be cached. These intermediate layers are not shown by default." This suggests that (at least currently) some customers may actually want this as the behavior because it saves the layers on the machine to be re-used. And I assume this leads to faster builds, if you build twice. |
|
my understanding is this change will only remove the intermediate containers, but will keep the images. This is the same behaviour we implement in By the way, this also the same behaviour of |
|
I also found this in the documentation "If you wish to keep the intermediate containers after the build is complete, you must use --rm=false. This does not affect the build cache.". So it seems this option doesn't affect the caching. https://docs.docker.com/engine/reference/commandline/build/#build-with-path There's another |
samcli/lib/build/app_builder.py
Outdated
| "decode": True, | ||
| "platform": get_docker_platform(architecture), | ||
| "rm": True, | ||
| "forcerm": True, |
There was a problem hiding this comment.
I see that here we have rm True but not forcerm: https://github.com/aws/aws-sam-cli/blob/develop/samcli/local/docker/lambda_image.py#L266
Should we keep them consistent?
There was a problem hiding this comment.
actually I was hesitated to add forcerm, I will remove it.
| @skipIf( | ||
| # Hits public ECR pull limitation, move it to canary tests | ||
| ((not RUN_BY_CANARY) or (IS_WINDOWS and RUNNING_ON_CI) and not CI_OVERRIDE), | ||
| "Skip build tests on windows when running in CI unless overridden", | ||
| ) |
There was a problem hiding this comment.
we don't want to skip anymore?
There was a problem hiding this comment.
no, it is my bad .. I removed them to run testing in my local machine, and forget to return them back :(
Which issue(s) does this change fix?
The default behaviour of docker image create API is to keep the intermediate containers created. So, when customer execute
sam buildfor an Image type Lambda Function, the customer will find some created containers exist aftersam buildcommand finish. This PR is to clean these intermediate containers, and let the docker API delete these containers after the image built process finish.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.