Workaround for Running out of Disk Space

Running out of Disk Space

Sometimes your builds fail because you are running out of disk space. This is a tricky problem because we do not necessary limit the amount of disk that you are able to use. In addition, the total amount of disk space that is available during a build depends on the underlying VM. Since this is a variable number there can be significant differences in total available disk space across builds.

One solution is to simply delete files that you are not using at the start of your build. I went through and found some good candidates for deleting. The two largest directories in our containers are:

/usr/local is 20GB 
/home/ubuntu is 19GB 

Using du -sch .[!.]* * |sort -rh | head -10 we can see that within these directories, the top 10 largest directories are:

/usr/local

13G	android-sdk-linux
3.4G	go
3.4G	android-ndk
193M	lib
90M	bin
50M	share
44M	gradle-1.10
38M	phantomjs-1.9.8-linux-x86_64
16M	go_workspac

/home/ubuntu

5.8G	.rvm
5.3G	.phpenv
3.0G	.pyenv
2.4G	nvm
1.1G	.android
235M	.cabal
215M	.composer
156M	.play
103M	virtualenvs

Using this information, you can now make some decisions. You can get a bunch of disk space back if you are not using android, go, node, ruby, php, etc… by removing these from the container at the start of the build with the following addition to your circle.yml command:

For instance, if we were not using android, go, or node we could remove the following files:

machine:
    pre:
      - sudo rm -rf /usr/local/android-sdk-linux
      - sudo rm -rf /usr/local/go
      - sudo rm -rf /usr/local/android-ndk
      - sudo rm -rf /home/ubuntu/nvm
      - sudo rm -rf /home/ubuntu/.android

This is a pretty brute force solution, but it should give you enough disk back to prevent the out of disk space build failures.

3 Likes