• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1name: Cleans up diskspace
2
3description: Cleans up diskspace if the root directory has used more than seventy percent of your diskspace.
4
5inputs:
6    diskspace-cutoff:
7        description: The percent amount after which docker prune is run.
8        required: true
9        default: 70
10
11runs:
12  using: composite
13  steps:
14    - name: Cleans up diskspace
15      shell: bash
16      run: |
17        set -ex
18        diskspace_cutoff=${{ inputs.diskspace-cutoff }}
19        docker_root_dir=$(docker info -f '{{.DockerRootDir}}')
20        diskspace=$(df -H --output=pcent ${docker_root_dir} | sed -n 2p | sed 's/%//' | sed 's/ //')
21        msg="Please file an issue on pytorch/pytorch reporting the faulty runner. Include a link to the runner logs so the runner can be identified"
22        if [[ "$diskspace" -ge "$diskspace_cutoff" ]] ; then
23            docker system prune -af
24            diskspace_new=$(df -H --output=pcent ${docker_root_dir} | sed -n 2p | sed 's/%//' | sed 's/ //')
25            if [[ "$diskspace_new" -gt "$diskspace_cutoff" ]] ; then
26                echo "Error: Available diskspace is less than $diskspace_cutoff percent. Not enough diskspace."
27                echo "$msg"
28                exit 1
29            else
30                difference=$((diskspace - diskspace_new))
31                echo "Diskspace saved: $difference percent"
32            fi
33        fi
34