Class: GitlabJanitor::CacheCleaner

Inherits:
BaseCleaner show all
Defined in:
lib/gitlab_janitor/cache_cleaner.rb

Instance Attribute Summary

Attributes inherited from BaseCleaner

#deadline, #delay, #logger

Instance Method Summary collapse

Methods inherited from BaseCleaner

#clean, #exiting?, #log_exception

Constructor Details

#initialize(**kwargs) ⇒ CacheCleaner

Returns a new instance of CacheCleaner.



6
7
8
# File 'lib/gitlab_janitor/cache_cleaner.rb', line 6

def initialize(**kwargs)
  super(**kwargs)
end

Instance Method Details

#do_clean(keep_size: '10G', remove: false) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/gitlab_janitor/cache_cleaner.rb', line 10

def do_clean(keep_size: '10G', remove: false)
  logger.info 'Removing cache...'
  if remove
    prune_builder(keep_size)
    prune_buildx(keep_size)
  else
    logger.info 'Skip removal due to dry run'
  end
  out, _status = Open3.capture2e('docker system df')
  logger.info(out)
end

#prune_builder(keep_size) ⇒ Object



22
23
24
25
26
27
# File 'lib/gitlab_janitor/cache_cleaner.rb', line 22

def prune_builder(keep_size)
  out, _status = Open3.capture2e("docker builder prune --keep-storage #{keep_size} -f")
  logger.info(out)
rescue StandardError =>e
  logger.warn("Unable to clean BUILDER: #{e.inspect}")
end

#prune_buildx(keep_size) ⇒ Object



29
30
31
32
33
34
# File 'lib/gitlab_janitor/cache_cleaner.rb', line 29

def prune_buildx(keep_size)
  out, _status = Open3.capture2e("docker buildx prune --keep-storage #{keep_size} -f")
  logger.info(out)
rescue StandardError =>e
  logger.warn("Unable to clean BUILDX: #{e.inspect}")
end