class DPL::Provider::Snap
Public Class Methods
snap(name, command = name, classic: false, channel: nil)
click to toggle source
Support installing snaps
# File lib/dpl/provider/snap.rb, line 7 def self.snap(name, command = name, classic: false, channel: nil) install_command = "sudo snap install #{name}" if classic install_command += " --classic" end unless channel.nil? install_command += " --channel=#{channel}" end context.shell(install_command, retry: true) if `which #{command}`.chop.empty? end
Public Instance Methods
channel()
click to toggle source
Users can specify the channel into which they'd like to release this snap. It defaults to the 'edge' channel.
# File lib/dpl/provider/snap.rb, line 55 def channel options.fetch(:channel, 'edge') end
check_auth()
click to toggle source
# File lib/dpl/provider/snap.rb, line 30 def check_auth log "Attemping to login" stdout, stderr, status = Open3.capture3( "snapcraft login --with -", stdin_data: login_token) if status == 0 log stdout else error "Failed to authenticate: #{stderr}" end end
install_deploy_dependencies()
click to toggle source
# File lib/dpl/provider/snap.rb, line 24 def install_deploy_dependencies # Snapcraft may already be installed, but in case we installed # the snap, we need to add /snap/bin to the PATH. ENV["PATH"] += ':/snap/bin' end
login_token()
click to toggle source
Users must specify their login token, either explicitly in the YAML or via the $SNAP_TOKEN enironment variable.
# File lib/dpl/provider/snap.rb, line 61 def login_token options[:token] || context.env['SNAP_TOKEN'] || error("Missing token") end
needs_key?()
click to toggle source
No SSH keys needed
# File lib/dpl/provider/snap.rb, line 43 def needs_key? false end
push_app()
click to toggle source
# File lib/dpl/provider/snap.rb, line 65 def push_app snaps = Dir.glob(snap) case snaps.length when 0 error "No snap found matching '#{snap}'" when 1 snap_path = snaps.first context.fold("Pushing snap") do context.shell "snapcraft push #{snap_path} --release=#{channel}" end else snap_list = snaps.join(', ') error "Multiple snaps found matching '#{snap}': #{snap_list}" end end
snap()
click to toggle source
Users must specify the path to the snap they want pushed (globbing is supported).
# File lib/dpl/provider/snap.rb, line 49 def snap option(:snap) end