Sha256: 792fdc021c2a63ea010056d914a6786e9fe4fc9dbc2afc5a426683cb8f464719

Contents?: true

Size: 969 Bytes

Versions: 5

Compression:

Stored size: 969 Bytes

Contents

require 'open3'

module GitlabJanitor
  class CacheCleaner < BaseCleaner

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

    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
    
    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
    
    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

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
gitlab-janitor-1.0.5.229406 lib/gitlab_janitor/cache_cleaner.rb
gitlab-janitor-1.0.4.134297 lib/gitlab_janitor/cache_cleaner.rb
gitlab-janitor-1.0.4.134295 lib/gitlab_janitor/cache_cleaner.rb
gitlab-janitor-1.0.4.94895 lib/gitlab_janitor/cache_cleaner.rb
gitlab-janitor-1.0.4.94868 lib/gitlab_janitor/cache_cleaner.rb