Class: Mrsk::Cli::Main
Instance Method Summary collapse
- #audit ⇒ Object
- #config ⇒ Object
- #deploy ⇒ Object
- #details ⇒ Object
- #envify ⇒ Object
- #init ⇒ Object
- #redeploy ⇒ Object
- #remove ⇒ Object
- #rollback(version) ⇒ Object
- #setup ⇒ Object
- #version ⇒ Object
Methods inherited from Base
Constructor Details
This class inherits a constructor from Mrsk::Cli::Base
Instance Method Details
#audit ⇒ Object
113 114 115 116 117 |
# File 'lib/mrsk/cli/main.rb', line 113 def audit on(MRSK.hosts) do |host| puts_by_host host, capture_with_info(*MRSK.auditor.reveal) end end |
#config ⇒ Object
120 121 122 123 124 |
# File 'lib/mrsk/cli/main.rb', line 120 def config run_locally do puts MRSK.config.to_h.to_yaml end end |
#deploy ⇒ Object
15 16 17 18 19 20 21 22 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 |
# File 'lib/mrsk/cli/main.rb', line 15 def deploy with_lock do = runtime = print_runtime do say "Ensure curl and Docker are installed...", :magenta invoke "mrsk:cli:server:bootstrap", [], say "Log into image registry...", :magenta invoke "mrsk:cli:registry:login", [], if [:skip_push] say "Pull app image...", :magenta invoke "mrsk:cli:build:pull", [], else say "Build and push app image...", :magenta invoke "mrsk:cli:build:deliver", [], end say "Ensure Traefik is running...", :magenta invoke "mrsk:cli:traefik:boot", [], say "Ensure app can pass healthcheck...", :magenta invoke "mrsk:cli:healthcheck:perform", [], invoke "mrsk:cli:app:boot", [], say "Prune old containers and images...", :magenta invoke "mrsk:cli:prune:all", [], end audit_broadcast "Deployed #{service_version} in #{runtime.round} seconds" unless [:skip_broadcast] end end |
#details ⇒ Object
106 107 108 109 110 |
# File 'lib/mrsk/cli/main.rb', line 106 def details invoke "mrsk:cli:traefik:details" invoke "mrsk:cli:app:details" invoke "mrsk:cli:accessory:details", [ "all" ] end |
#envify ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/mrsk/cli/main.rb', line 159 def envify if destination = [:destination] env_template_path = ".env.#{destination}.erb" env_path = ".env.#{destination}" else env_template_path = ".env.erb" env_path = ".env" end File.write(env_path, ERB.new(File.read(env_template_path)).result, perm: 0600) end |
#init ⇒ Object
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 |
# File 'lib/mrsk/cli/main.rb', line 128 def init require "fileutils" if (deploy_file = Pathname.new(File.("config/deploy.yml"))).exist? puts "Config file already exists in config/deploy.yml (remove first to create a new one)" else FileUtils.mkdir_p deploy_file.dirname FileUtils.cp_r Pathname.new(File.("templates/deploy.yml", __dir__)), deploy_file puts "Created configuration file in config/deploy.yml" end unless (deploy_file = Pathname.new(File.(".env"))).exist? FileUtils.cp_r Pathname.new(File.("templates/template.env", __dir__)), deploy_file puts "Created .env file" end if [:bundle] if (binstub = Pathname.new(File.("bin/mrsk"))).exist? puts "Binstub already exists in bin/mrsk (remove first to create a new one)" else puts "Adding MRSK to Gemfile and bundle..." run_locally do execute :bundle, :add, :mrsk execute :bundle, :binstubs, :mrsk end puts "Created binstub file in bin/mrsk" end end end |
#redeploy ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/mrsk/cli/main.rb', line 52 def redeploy with_lock do = runtime = print_runtime do if [:skip_push] say "Pull app image...", :magenta invoke "mrsk:cli:build:pull", [], else say "Build and push app image...", :magenta invoke "mrsk:cli:build:deliver", [], end say "Ensure app can pass healthcheck...", :magenta invoke "mrsk:cli:healthcheck:perform", [], invoke "mrsk:cli:app:boot", [], end audit_broadcast "Redeployed #{service_version} in #{runtime.round} seconds" unless [:skip_broadcast] end end |
#remove ⇒ Object
173 174 175 176 177 178 179 180 181 182 |
# File 'lib/mrsk/cli/main.rb', line 173 def remove with_lock do if [:confirmed] || ask("This will remove all containers and images. Are you sure?", limited_to: %w( y N ), default: "N") == "y" invoke "mrsk:cli:traefik:remove", [], .without(:confirmed) invoke "mrsk:cli:app:remove", [], .without(:confirmed) invoke "mrsk:cli:accessory:remove", [ "all" ], invoke "mrsk:cli:registry:logout", [], .without(:confirmed) end end end |
#rollback(version) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/mrsk/cli/main.rb', line 76 def rollback(version) with_lock do MRSK.config.version = version if container_name_available?(MRSK.config.service_with_version) say "Start version #{version}, then wait #{MRSK.config.readiness_delay}s for app to boot before stopping the old version...", :magenta cli = self old_version = nil on(MRSK.hosts) do |host| old_version = capture_with_info(*MRSK.app.current_running_version).strip.presence execute *MRSK.app.start if old_version sleep MRSK.config.readiness_delay execute *MRSK.app.stop(version: old_version), raise_on_non_zero_exit: false end end audit_broadcast "Rolled back #{service_version(Mrsk::Utils.abbreviate_version(old_version))} to #{service_version}" unless [:skip_broadcast] else say "The app version '#{version}' is not available as a container (use 'mrsk app containers' for available versions)", :red end end end |
#setup ⇒ Object
3 4 5 6 7 8 9 10 11 |
# File 'lib/mrsk/cli/main.rb', line 3 def setup with_lock do print_runtime do invoke "mrsk:cli:server:bootstrap" invoke "mrsk:cli:accessory:boot", [ "all" ] deploy end end end |