Class: DPL::Provider::Snap
- Inherits:
-
DPL::Provider
- Object
- DPL::Provider
- DPL::Provider::Snap
- Defined in:
- lib/dpl/provider/snap.rb
Class Method Summary collapse
-
.snap(name, command = name, classic: false, channel: nil) ⇒ Object
Support installing snaps.
Instance Method Summary collapse
-
#channel ⇒ Object
Users can specify the channel into which they’d like to release this snap.
- #check_auth ⇒ Object
- #install_deploy_dependencies ⇒ Object
-
#login_token ⇒ Object
Users must specify their login token, either explicitly in the YAML or via the $SNAP_TOKEN enironment variable.
-
#needs_key? ⇒ Boolean
No SSH keys needed.
- #push_app ⇒ Object
-
#snap ⇒ Object
Users must specify the path to the snap they want pushed (globbing is supported).
Class Method Details
.snap(name, command = name, classic: false, channel: nil) ⇒ Object
Support installing snaps
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# 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 |
Instance Method Details
#channel ⇒ Object
Users can specify the channel into which they’d like to release this snap. It defaults to the ‘edge’ channel.
55 56 57 |
# File 'lib/dpl/provider/snap.rb', line 55 def channel .fetch(:channel, 'edge') end |
#check_auth ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# 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 ⇒ Object
24 25 26 27 28 |
# 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 ⇒ Object
Users must specify their login token, either explicitly in the YAML or via the $SNAP_TOKEN enironment variable.
61 62 63 |
# File 'lib/dpl/provider/snap.rb', line 61 def login_token [:token] || context.env['SNAP_TOKEN'] || error("Missing token") end |
#needs_key? ⇒ Boolean
No SSH keys needed
43 44 45 |
# File 'lib/dpl/provider/snap.rb', line 43 def needs_key? false end |
#push_app ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# 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 ⇒ Object
Users must specify the path to the snap they want pushed (globbing is supported).
49 50 51 |
# File 'lib/dpl/provider/snap.rb', line 49 def snap option(:snap) end |