1

We are working on a a system that uses cloud runner, where we have a tech like Spring + Gradle plus Mongo.

The system is containerized and runs on cloud-run in gcp. However, gcp has a hard limit of 2gb on container size, which we are trying to fit into, as of now.

Upon deeper investigation, I found that, the gradle wrapper that we use downloads at least 170mb extra than what we needed.

It includes following -

  1. It contains documentation, which is not needed while running a build via wrapper.
  2. It does not delete the zip file after extracting the same..

Together it counts to 270 mb, which quite big for us.. What I want to know is, Is there any wrapper configuration OOTM that will help me avoid these extra files being downloaded on our system?

TylerH
  • 20,799
  • 66
  • 75
  • 101
Anand Vaidya
  • 1,374
  • 11
  • 26

2 Answers2

1

It seems you used the Gradle distribution type "all", which includes source code and the Gradle documentation (e.g., for IDE support -- source).

Since you run the Gradle wrapper in the cloud, you probably do not require IDE support: Use distribution type "bin". At least in latest versions of Gradle (version 7) this is the default, but you can still be explicit to make sure:

# gradle wrapper --gradle-version 7.0.2 --distribution-type bin

The size difference is about 200 MB:

# du -hs ~/.gradle/wrapper/dists/gradle-7.0.2-{all,bin}                      
438M    ~/.gradle/wrapper/dists/gradle-7.0.2-all
229M    ~/.gradle/wrapper/dists/gradle-7.0.2-bin

Gradle still keeps the zip-file, so you will have to delete that manually.

0

For us, this what we went with.

  1. Although we used gradle wrapper, We also made sure that we install relavent gradle wrapper upfront on the machine, so that when we run gradlew command, we dont download it again.
  2. When you download gradle wrapper while building image, you have liberty to delete the file from the filesystem while building container image. So you can free up some space.
  3. Next step is you can squash the image to remove all unnecessary layers. How can i remove layers from my docker image?
Anand Vaidya
  • 1,374
  • 11
  • 26