-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Remove downloaded package archives after extracting them #11640
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
Remove downloaded package archives after extracting them #11640
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Welcome to LocalStack! Thanks for raising your first Pull Request and landing in your contributions. Our team will reach out with any reviews or feedbacks that we have shortly. We recommend joining our Slack Community and share your PR on the #community channel to share your contributions with us. Please make sure you are following our contributing guidelines and our Code of Conduct.
All contributors have signed the CLA ✍️ ✅ |
I have read the CLA Document and I hereby sign the CLA |
8f12ade
to
07c0d70
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for your contribution, @kjagiello!
Your removal actually looks fine, but I think we should tackle the root cause here.
It seems like the new Java package installer (introduced with #11139) does not properly clean up after itself. /cc @viren-nadkarni
I think we should actually remove the archive here after the extraction of the newly downloaded archive here:
localstack/localstack-core/localstack/packages/core.py
Lines 108 to 128 in 958890a
def _install(self, target: InstallTarget) -> None: | |
target_directory = self._get_install_dir(target) | |
mkdir(target_directory) | |
download_url = self._get_download_url() | |
archive_name = os.path.basename(download_url) | |
download_and_extract( | |
download_url, | |
retries=3, | |
tmp_archive=os.path.join(config.dirs.tmp, archive_name), | |
target_dir=target_directory, | |
) | |
if self.extract_single_directory: | |
dir_contents = os.listdir(target_directory) | |
if len(dir_contents) != 1: | |
return | |
target_subdir = os.path.join(target_directory, dir_contents[0]) | |
if not os.path.isdir(target_subdir): | |
return | |
os.rename(target_subdir, f"{target_directory}.backup") | |
rm_rf(target_directory) | |
os.rename(f"{target_directory}.backup", target_directory) |
@viren-nadkarni, what do you think?
Great catch @kjagiello ! I agree with @alexrashed , this should happen in the packaging module right after extraction is complete. This will fix the issue not just for java but also for other packages. |
@kjagiello, do you think you could adjust your PR such that it fixes the |
Ah, that was actually the first approach I went to, then changed my mind, because I (wrongly) assumed it was intentional on your end. Should have stuck with my gut feeling 😄 I will adjust the PR shortly. |
07c0d70
to
8813bac
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks for jumping on the comment and adjusting the PR! The code is simple and clean. 💯
@viren-nadkarni Anything from your side that we should maybe keep in mind here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for the fix 🙌
Motivation
As mentioned in #11639, I have noticed that
python -m localstack.cli.lpm install
is leaving behind the downloaded package archives. This results in those files ending up in the published Docker image.Changes
This PR solves the issue by removing the archive after extracting a package. This should result in a 184 MB reduction of the localstack docker image.
Testing
IMAGE_NAME="localstack/localstack" ./bin/docker-helper.sh build
/tmp/localstack
: