class Kontena::StacksCache
Public Class Methods
base_path()
click to toggle source
# File lib/kontena/stacks_cache.rb, line 99 def base_path return @base_path if @base_path @base_path = File.join(Dir.home, '.kontena/cache/stacks') unless File.directory?(@base_path) require 'fileutils' FileUtils.mkdir_p(@base_path) end @base_path end
cache(stack_name)
click to toggle source
# File lib/kontena/stacks_cache.rb, line 68 def cache(stack_name) stack = CachedStack.new(stack_name) if stack.cached? dputs "Reading from cache: #{stack.path}" else dputs "Retrieving #{stack.stack_name} from registry" content = client.pull(stack_name) yaml = ::YAML.safe_load(content, [], [], true, stack.stack_name.to_s) new_stack_name = Kontena::Cli::Stacks::StackName.new(yaml['stack'], yaml['version']) new_stack = CachedStack.new(new_stack_name) if new_stack.cached? dputs "Already cached" stack = new_stack else dputs "Writing #{stack.path}" new_stack.write(content) dputs "#{new_stack.stack_name} cached to #{new_stack.path}" stack = new_stack end end stack end
client()
click to toggle source
# File lib/kontena/stacks_cache.rb, line 95 def client @client ||= RegistryClientFactory.new.stacks_client end
dputs(msg)
click to toggle source
# File lib/kontena/stacks_cache.rb, line 64 def dputs(msg) Kontena.logger.debug { msg } end
pull(stack_name)
click to toggle source
# File lib/kontena/stacks_cache.rb, line 60 def pull(stack_name) cache(stack_name).read end
registry_url(stack_name)
click to toggle source
# File lib/kontena/stacks_cache.rb, line 91 def registry_url(stack_name) client.full_uri(stack_name) end