File tree Expand file tree Collapse file tree 3 files changed +30
-2
lines changed Expand file tree Collapse file tree 3 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -15,7 +15,25 @@ if [[ $disk_avail -lt $DISK_MIN_AVAILABLE ]]; then
15
15
disk_min_human=$( numfmt --to=iec-i --suffix=B --from-unit=1024 " ${DISK_MIN_AVAILABLE} " )
16
16
disk_avail_human=$( numfmt --to=iec-i --suffix=B --from-unit=1024 " ${disk_avail} " )
17
17
echo " Not enough disk space free: ${disk_avail_human} (${disk_avail} KB) available, cutoff is ${disk_min_human} (${DISK_MIN_AVAILABLE} KB) 🚨" >&2
18
- exit 1
18
+
19
+ # Last resort for clearing space with build directory cleanup (if enabled)
20
+ if [[ " ${BUILDKITE_PURGE_BUILDS_ON_DISK_FULL:- false} " == " true" ]]; then
21
+ echo " Purging all build directories to reclaim disk space..."
22
+ rm -rf " ${BUILDKITE_AGENT_BUILD_PATH:-/ var/ lib/ buildkite-agent/ builds} " /*
23
+ disk_avail=$( df -k --output=avail " $DOCKER_DIR " | tail -n1)
24
+ disk_avail_human=$( numfmt --to=iec-i --suffix=B --from-unit=1024 " ${disk_avail} " )
25
+ echo " Disk space free after build purge: ${disk_avail_human} (${disk_avail} KB)"
26
+ if [[ $disk_avail -ge $DISK_MIN_AVAILABLE ]]; then
27
+ echo " Disk space sufficient after build purge. Continuing."
28
+ exit 0
29
+ else
30
+ echo " Disk health checks failed after build purge. Terminating agent." >&2
31
+ exit 1
32
+ fi
33
+ else
34
+ echo " Disk health checks failed. Build purge not enabled. Terminating agent." >&2
35
+ exit 1
36
+ fi
19
37
fi
20
38
21
39
inodes_avail=$( df -k --output=iavail " $DOCKER_DIR " | tail -n1)
Original file line number Diff line number Diff line change @@ -135,7 +135,7 @@ set_always "BUILDKITE_AGENTS_PER_INSTANCE" "$BUILDKITE_AGENTS_PER_INSTAN
135
135
# also set via /etc/systemd/system/buildkite-agent.service.d/environment.conf
136
136
set_always "BUILDKITE_TERMINATE_INSTANCE_AFTER_JOB" "$BUILDKITE_TERMINATE_INSTANCE_AFTER_JOB "
137
137
set_always "BUILDKITE_TERMINATE_INSTANCE_ON_DISK_FULL" "$BUILDKITE_TERMINATE_INSTANCE_ON_DISK_FULL "
138
-
138
+ set_always "BUILDKITE_PURGE_BUILDS_ON_DISK_FULL" " $BUILDKITE_PURGE_BUILDS_ON_DISK_FULL "
139
139
set_always "BUILDKITE_ECR_POLICY" "${BUILDKITE_ECR_POLICY:- none} "
140
140
set_always "BUILDKITE_SECRETS_BUCKET" "$BUILDKITE_SECRETS_BUCKET "
141
141
set_always "BUILDKITE_SECRETS_BUCKET_REGION" "$BUILDKITE_SECRETS_BUCKET_REGION "
Original file line number Diff line number Diff line change @@ -55,6 +55,7 @@ Metadata:
55
55
- BuildkiteAgentCancelGracePeriod
56
56
- BuildkiteAgentSignalGracePeriod
57
57
- BuildkiteTerminateInstanceAfterJob
58
+ - BuildkitePurgeBuildsOnDiskFull
58
59
- BuildkiteAdditionalSudoPermissions
59
60
- BuildkiteWindowsAdministrator
60
61
- BuildkiteAgentScalerServerlessARN
@@ -308,6 +309,14 @@ Parameters:
308
309
- " false"
309
310
Default : " false"
310
311
312
+ BuildkitePurgeBuildsOnDiskFull :
313
+ Description : Set to "true" to purge build directories as a last resort when disk space is critically low.
314
+ Type : String
315
+ AllowedValues :
316
+ - " true"
317
+ - " false"
318
+ Default : " false"
319
+
311
320
BuildkiteAgentDisconnectAfterUptime :
312
321
Description : >
313
322
The maximum uptime in seconds before the agent stops accepting new jobs and shuts down
@@ -1800,6 +1809,7 @@ Resources:
1800
1809
BUILDKITE_TERMINATE_INSTANCE_AFTER_JOB="${BuildkiteTerminateInstanceAfterJob}" \
1801
1810
BUILDKITE_AGENT_DISCONNECT_AFTER_UPTIME="${BuildkiteAgentDisconnectAfterUptime}" \
1802
1811
BUILDKITE_TERMINATE_INSTANCE_ON_DISK_FULL="${BuildkiteTerminateInstanceOnDiskFull}" \
1812
+ BUILDKITE_PURGE_BUILDS_ON_DISK_FULL="${BuildkitePurgeBuildsOnDiskFull}" \
1803
1813
BUILDKITE_ADDITIONAL_SUDO_PERMISSIONS="${BuildkiteAdditionalSudoPermissions}" \
1804
1814
AWS_DEFAULT_REGION="${AWS::Region}" \
1805
1815
SECRETS_PLUGIN_ENABLED="${EnableSecretsPlugin}" \
You can’t perform that action at this time.
0 commit comments