Fail fast in image generation if not enough disk space for customers (#767)

* added checking free disk space
Co-authored-by: Nikita Bykov <v-nibyko@microsoft.com>
This commit is contained in:
Nikita Bykov
2020-04-30 09:26:06 +03:00
committed by GitHub
parent 612ed30d53
commit b58720bb05
6 changed files with 52 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
#!/bin/bash
################################################################################
## File: validate-disk-space.sh
## Desc: Validate free disk space
################################################################################
availableSpaceMB=$(df / -hm | sed 1d | awk '{ print $4}')
minimumFreeSpaceMB=$(( 18*1024 ))
echo "Available disk space: $availableSpaceMB MB"
if [ $availableSpaceMB -le $minimumFreeSpaceMB ]; then
echo "Not enough disk space on the image (minimum available space: $minimumFreeSpaceMB MB)"
exit 1
fi

View File

@@ -324,6 +324,12 @@
], ],
"execute_command": "sudo sh -c '{{ .Vars }} {{ .Path }}'" "execute_command": "sudo sh -c '{{ .Vars }} {{ .Path }}'"
}, },
{
"type": "shell",
"scripts":[
"{{template_dir}}/scripts/installers/validate-disk-space.sh"
]
},
{ {
"type": "file", "type": "file",
"source": "{{user `metadata_file`}}", "source": "{{user `metadata_file`}}",

View File

@@ -328,6 +328,12 @@
], ],
"execute_command": "sudo sh -c '{{ .Vars }} {{ .Path }}'" "execute_command": "sudo sh -c '{{ .Vars }} {{ .Path }}'"
}, },
{
"type": "shell",
"scripts":[
"{{template_dir}}/scripts/installers/validate-disk-space.sh"
]
},
{ {
"type": "file", "type": "file",
"source": "{{user `metadata_file`}}", "source": "{{user `metadata_file`}}",

View File

@@ -883,6 +883,12 @@
"{{ template_dir }}/scripts/Installers/Validate-Kind.ps1" "{{ template_dir }}/scripts/Installers/Validate-Kind.ps1"
] ]
}, },
{
"type": "powershell",
"scripts":[
"{{ template_dir }}/scripts/Installers/Validate-DiskSpace.ps1"
]
},
{ {
"type": "file", "type": "file",
"source": "C:\\InstalledSoftware.md", "source": "C:\\InstalledSoftware.md",

View File

@@ -886,6 +886,12 @@
"{{ template_dir }}/scripts/Installers/Validate-AliyunCli.ps1" "{{ template_dir }}/scripts/Installers/Validate-AliyunCli.ps1"
] ]
}, },
{
"type": "powershell",
"scripts":[
"{{ template_dir }}/scripts/Installers/Validate-DiskSpace.ps1"
]
},
{ {
"type": "file", "type": "file",
"source": "C:\\InstalledSoftware.md", "source": "C:\\InstalledSoftware.md",

View File

@@ -0,0 +1,14 @@
################################################################################
## File: Validate-DiskSpace.ps1
## Desc: Validate free disk space
################################################################################
$availableSpaceMB = [math]::Round((Get-PSDrive -Name C).Free / 1MB)
$minimumFreeSpaceMB = 15 * 1024
Write-Host "Available disk space: $availableSpaceMB MB"
if ($availableSpaceMB -le $minimumFreeSpaceMB)
{
Write-Host "Not enough disk space on the image (minimum available space: $minimumFreeSpaceMB MB)"
exit 1
}