Skip to content

Conversation

@jerm
Copy link
Member

@jerm jerm commented Apr 14, 2025

There is a failure mode in composer where if it has a connection trying to get
a dependency tarball from the github API, it will fall-back to
downloading the entire repo for the dependency and use that... and it
will cache it outside of vendor/, using a whopping 1.5G of space

that full 1.5G is then copied into vendor/

98M     league
100M	tecnickcom
133M	laravel
323M	sebastian
681M	aws

for a total of a 1.8G vendor/ directory

vs the trimmed-down version with a 552M vendor/ directory

53M	league
30M	tecnickcom
31M	laravel
70M	sebastian
241M	aws

This is still a far cry from the proper 150M version when everything
works as it should, but it's still a vast improvement

3.2M    league
14M     laravel
30M     tecnickcom
260K	sebastian
52M     aws

Ideally this never happens, but it'd be great tp avoid the bloat if/when
it does..

To wit: Our ARM/Ubuntu Docker images are currently bloated because of this
issue due builds happening on an emulated ARM environment, and the resultant
performance penalties causing composer issues

All that to say, this change sets OMPOSER_CACHE_DIR to /dev/null to
avoid the caching, and then removes vendor/*/*/.git to remove that
needless bloat if it occurs. It's a no-op in general practice.

There is a failure mode in composer where if it has a connection trying to get
a dependency tarball from the github API, it will fall-back to
downloading the entire repo for the dependency and use that... and it
will cache it outside of vendor/, using a whopping 1.5G of space

that full 1.5G is _then_ copied into vendor/

```
98M     league
100M	tecnickcom
133M	laravel
323M	sebastian
681M	aws
```

for a total of a 1.8G vendor/ directory

vs the trimmed-down version with a 552M vendor/ directory

```
53M	league
30M	tecnickcom
31M	laravel
70M	sebastian
241M	aws
```

This is still a far cry from the proper 150M version when everything
works as it should, but it's still a vast improvement

```
3.2M    league
14M     laravel
30M     tecnickcom
260K	sebastian
52M     aws
```

Ideally this never happens, but it'd be great tp avoid the bloat if/when
it does..

To wit: Our ARM/Ubuntu Docker images are currently bloated because of this
issue due builds happening on an emulated ARM environment, and the resultant
performance penalties causing composer issues

All that to say, this change sets OMPOSER_CACHE_DIR to /dev/null to
avoid the caching, and then removes vendor/*/*/.git to remove that
needless bloat if it occurs. It's a no-op in general practice.
@jerm jerm requested a review from snipe as a code owner April 14, 2025 19:32
@what-the-diff
Copy link

what-the-diff bot commented Apr 14, 2025

PR Summary

  • Modification of Docker Run Command
    The 'RUN' instruction in our Dockerfile has been tweaked to prevent unnecessary storage accumulation. By setting the COMPOSER_CACHE_DIR to /dev/null, we've successfully put an end to composer package caching which would help in maintaining lighter workloads and better processing speeds.

  • Pruning Vendor Directory
    A new command has been added that eliminates the .git directories contained in the vendor directory, following the installation of dependencies. The advantage here lies in the significantly reduced image size which in turn leads to improved performance and lower resource usage of our system.

@snipe snipe merged commit 65b9561 into develop Apr 14, 2025
9 checks passed
@snipe snipe deleted the docker-arm-size-fix branch April 14, 2025 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants