diff options
Diffstat (limited to 'scripts/review_apps/automated_cleanup.rb')
-rwxr-xr-x | scripts/review_apps/automated_cleanup.rb | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/scripts/review_apps/automated_cleanup.rb b/scripts/review_apps/automated_cleanup.rb index 5707f02d3f0..90dc0fd418e 100755 --- a/scripts/review_apps/automated_cleanup.rb +++ b/scripts/review_apps/automated_cleanup.rb @@ -95,6 +95,42 @@ class AutomatedCleanup delete_helm_releases(releases_to_delete) end + def perform_gitlab_docs_environment_cleanup!(days_for_stop:, days_for_delete:) + puts "Checking for Docs Review Apps not updated in the last #{days_for_stop} days..." + + checked_environments = [] + stop_threshold = threshold_time(days: days_for_stop) + delete_threshold = threshold_time(days: days_for_delete) + + max_delete_count = 1000 + delete_count = 0 + + gitlab.deployments(project_path, per_page: DEPLOYMENTS_PER_PAGE, sort: 'desc').auto_paginate do |deployment| + environment = deployment.environment + + next unless environment + next unless environment.name.start_with?('review-docs/') + next if checked_environments.include?(environment.slug) + + last_deploy = deployment.created_at + deployed_at = Time.parse(last_deploy) + + if deployed_at < stop_threshold + environment_state = fetch_environment(environment)&.state + stop_environment(environment, deployment) if environment_state && environment_state != 'stopped' + end + + if deployed_at < delete_threshold + delete_environment(environment, deployment) + delete_count += 1 + + break if delete_count > max_delete_count + end + + checked_environments << environment.slug + end + end + def perform_helm_releases_cleanup!(days:) puts "Checking for Helm releases that are failed or not updated in the last #{days} days..." @@ -203,6 +239,10 @@ timed('Review Apps cleanup') do automated_cleanup.perform_gitlab_environment_cleanup!(days_for_stop: 5, days_for_delete: 6) end +timed('Docs Review Apps cleanup') do + automated_cleanup.perform_gitlab_docs_environment_cleanup!(days_for_stop: 20, days_for_delete: 30) +end + puts timed('Helm releases cleanup') do |