require "thor" require "dddr" require "terminal-table" require "yaml" require "toml-rb" require "fileutils" require "ostruct" require "sucker_punch" require "resend" require "net/ssh" require_relative "harbr/version" require_relative "harbr/container" require_relative "harbr/host" # Harbr module for managing containers, jobs, ports, and 2s module Harbr DEFAULT_DIRECTORY = "~/.config/harbr" DEFAULT_DIRECTORY_DATA_DIR = "#{DEFAULT_DIRECTORY}/.data" Dddr.configure do |config| config.container = "harbr" end module SSH def on_ssh command = "" command = yield command hostname = "smtp.laki.zero2one.ee" username = "root" key_path = "/Users/db/.ssh/id_rsa" # Replace with the path to your private SSH key Net::SSH.start(hostname, username, keys: [key_path]) do |ssh| ssh.exec!(command) end rescue => e puts "Error: #{e.class}" puts "backtrace: #{e.backtrace.join('\n')}" puts "Error sending notification: #{e.message}" end end class Error < StandardError; end def self.send_notification(subject, body) resend_config = YAML.load_file("/etc/harbr/resend.yml") Resend.api_key = resend_config["key"] params = { from: resend_config["from"], to: resend_config["to"], subject: subject, html: body } puts "Sending notification: #{params}" Resend::Emails.send(params) rescue => e puts "Error: #{e.class}" puts "backtrace: #{e.backtrace.join('\n')}" puts "Error sending notification: #{e.message}" end def self.notifiable(name, version, env) yield if block_given? send_notification("Harbr: #{name} deployed to #{env} successfully", "

harbr: #{version} of #{name} deployed to #{env} successfully

") rescue => e html_content = <<~HTML

Error: #{e.message}

#{e.backtrace.join("
")}

harbr: #{version} of #{env} #{name} failed to deploy

HTML send_notification("Harbr: #{name} failed to deploy", html_content) end end