Class: Publisher::Dweb
- Inherits:
-
Object
- Object
- Publisher::Dweb
- Defined in:
- lib/depengine/publisher/dweb.rb
Instance Attribute Summary collapse
-
#siteid ⇒ Object
Returns the value of attribute siteid.
-
#ssh_key_file ⇒ Object
Returns the value of attribute ssh_key_file.
-
#staging_host ⇒ Object
Returns the value of attribute staging_host.
Instance Method Summary collapse
- #remote_symlink(source, symlink, options = {}) ⇒ Object
-
#send_command(command, options = {}) ⇒ Object
debug with: ssh -i apps/deploy_engine/etc/ssh/id_rsa.deployadmin dwebuser@dei2s.dweb.intranet.db.com > ‘enter command’.
- #upload(source, target, options = {}) ⇒ Object
Instance Attribute Details
#siteid ⇒ Object
Returns the value of attribute siteid.
5 6 7 |
# File 'lib/depengine/publisher/dweb.rb', line 5 def siteid @siteid end |
#ssh_key_file ⇒ Object
Returns the value of attribute ssh_key_file.
4 5 6 |
# File 'lib/depengine/publisher/dweb.rb', line 4 def ssh_key_file @ssh_key_file end |
#staging_host ⇒ Object
Returns the value of attribute staging_host.
3 4 5 |
# File 'lib/depengine/publisher/dweb.rb', line 3 def staging_host @staging_host end |
Instance Method Details
#remote_symlink(source, symlink, options = {}) ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/depengine/publisher/dweb.rb', line 164 def remote_symlink(source, symlink, = {}) Helper.validates_presence_of staging_host, 'Staging Host not set' Helper.validates_presence_of ssh_key_file, 'SSH keyfile not set' joined_filename = File.join(File.dirname($exec_file_path), ssh_key_file) ssh_key_file = joined_filename # overwrite siteid for multi target deployments self.siteid = [:siteid] if [:siteid] Helper.validates_presence_of siteid, 'Siteid not set' # check ssh keyfile unless File.file? ssh_key_file $log.writer.error "Can not find SSH keyfile #{ssh_key_file}" exit 1 end begin Net::SFTP.start(staging_host, siteid + 'f', \ auth_methods: ['publickey'], \ forward_agent: false, \ keys: ssh_key_file, \ timeout: 90) do |session| begin if session.lstat!(symlink).type == Net::SFTP::Protocol::V01::Attributes::T_SYMLINK $log.writer.debug "Delete already existing link #{symlink}" session.remove!(symlink) end rescue $log.writer.warn 'Maybe the link does not exist yet, or the remove faild. Anyway, we try to create it.' end session.symlink!(source, symlink) end rescue => e $log.writer.error "Can not create remote symlink #{symlink} to #{source}" $log.writer.error e. $log.writer.error e.backtrace.join("\n") exit 1 end true end |
#send_command(command, options = {}) ⇒ Object
debug with: ssh -i apps/deploy_engine/etc/ssh/id_rsa.deployadmin dwebuser@dei2s.dweb.intranet.db.com > ‘enter command’
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/depengine/publisher/dweb.rb', line 23 def send_command(command, = {}) Helper.validates_presence_of staging_host, 'Staging Host not set' Helper.validates_presence_of ssh_key_file, 'SSH keyfile not set' Helper.validates_presence_of siteid, 'Siteid not set' result = '' joined_filename = File.join(File.dirname($exec_file_path), ssh_key_file) ssh_key_file = joined_filename # overwrite siteid for multi target deployments self.siteid = [:siteid] if [:siteid] # check ssh keyfile unless File.file? ssh_key_file $log.writer.error "Can not find SSH keyfile #{ssh_key_file}" fail "Can not find SSH keyfile #{ssh_key_file}" end ### Probleme auf UAT und PROD return result if command.include? 'list' Net::SSH.start(staging_host, 'dwebuser', \ auth_methods: ['publickey'], \ forward_agent: false, \ keys: ssh_key_file, \ timeout: 90) do |session| session.open_channel do |channel| channel.exec "/scripts/dwebuser #{siteid}" do |ch, success| unless success $log.writer.error 'Can not execute dwebuser command' exit 1 end ch.on_data do |_ch, data| unless data.empty? result << data if command.include? 'list' result_a = result.split("\n") test = result_a.last if not test.nil? and test.length > 0 $log.writer.info "Deployment Status: #{test}" end end end end # something on stderr? ch.on_extended_data do |_ch, _type, data| # dirty filter for non critical return messages if data =~ /^ERROR.*/ $log.writer.error \ "Received error from dwebuser command: #{data}" exit 1 else $log.writer.debug \ "Received output from dwebuser command: #{data}" end end ch.on_close do |_ch| result << 'all done, closing ssh channel!' end ch.send_data command + "\n" end channel.wait end end $log.writer.debug result result end |
#upload(source, target, options = {}) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/depengine/publisher/dweb.rb', line 98 def upload(source, target, = {}) Helper.validates_presence_of staging_host, 'Staging Host not set' Helper.validates_presence_of ssh_key_file, 'SSH keyfile not set' joined_filename = File.join(File.dirname($exec_file_path), ssh_key_file) ssh_key_file = joined_filename # overwrite siteid for multi target deployments self.siteid = [:siteid] if [:siteid] Helper.validates_presence_of siteid, 'Siteid not set' # check ssh keyfile unless File.file? ssh_key_file $log.writer.error "Can not find SSH keyfile #{ssh_key_file}" fail "Can not find SSH keyfile #{ssh_key_file}" end # first connection to delete files begin unless [:cleanup] == false Net::SFTP.start(staging_host, siteid + 'f', \ auth_methods: ['publickey'], \ forward_agent: false, \ keys: ssh_key_file, \ timeout: 90) do |session| # delete all files in target, but not the target-dir itself $log.writer.debug "Cleaning remote directory #{target}" session.rm_r!(target) end end # second connection to upload files processing_file = '' Net::SCP.start(staging_host, siteid + 'f', \ auth_methods: ['publickey'], \ forward_agent: false, \ keys: ssh_key_file, \ timeout: 90) do |session| Dir.glob(File.join(source, '/*'), File::FNM_DOTMATCH) do |entry| unless entry =~ /\.$/ processing_file = entry if not [:excludes].nil? if [:excludes].any? { |term| entry.include? term } $log.writer.debug "Exclude #{entry} from upload" else $log.writer.debug "Upload #{entry}" session.upload!(entry, File.join(target, '/'), \ recursive: true) end else $log.writer.debug "Upload #{entry}" session.upload!(entry, File.join(target, '/'), \ recursive: true) end end end end rescue => e $log.writer.error "Can not upload file #{processing_file} to #{target}" $log.writer.error e. $log.writer.error e.backtrace.join("\n") exit 1 end end |