Class: Kamal::Cli::Main
Instance Method Summary collapse
- #audit ⇒ Object
- #config ⇒ Object
- #deploy ⇒ Object
- #details ⇒ Object
- #docs(section = nil) ⇒ Object
- #downgrade ⇒ 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 Kamal::Cli::Base
Instance Method Details
#audit ⇒ Object
117 118 119 120 121 |
# File 'lib/kamal/cli/main.rb', line 117 def audit on(KAMAL.hosts) do |host| puts_by_host host, capture_with_info(*KAMAL.auditor.reveal) end end |
#config ⇒ Object
124 125 126 127 128 |
# File 'lib/kamal/cli/main.rb', line 124 def config run_locally do puts Kamal::Utils.redacted(KAMAL.config.to_h).to_yaml end end |
#deploy ⇒ Object
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 |
# File 'lib/kamal/cli/main.rb', line 24 def deploy runtime = print_runtime do = say "Log into image registry...", :magenta invoke "kamal:cli:registry:login", [], .merge(skip_local: [:skip_push]) if [:skip_push] say "Pull app image...", :magenta invoke "kamal:cli:build:pull", [], else say "Build and push app image...", :magenta invoke "kamal:cli:build:deliver", [], end with_lock do run_hook "pre-deploy" say "Ensure Traefik is running...", :magenta invoke "kamal:cli:traefik:boot", [], say "Detect stale containers...", :magenta invoke "kamal:cli:app:stale_containers", [], .merge(stop: true) invoke "kamal:cli:app:boot", [], say "Prune old containers and images...", :magenta invoke "kamal:cli:prune:all", [], end end run_hook "post-deploy", runtime: runtime.round end |
#details ⇒ Object
110 111 112 113 114 |
# File 'lib/kamal/cli/main.rb', line 110 def details invoke "kamal:cli:traefik:details" invoke "kamal:cli:app:details" invoke "kamal:cli:accessory:details", [ "all" ] end |
#docs(section = nil) ⇒ Object
131 132 133 134 135 136 137 138 139 140 |
# File 'lib/kamal/cli/main.rb', line 131 def docs(section = nil) case section when NilClass puts Kamal::Configuration.validation_doc else puts Kamal::Configuration.const_get(section.titlecase.to_sym).validation_doc end rescue NameError puts "No documentation found for #{section}" end |
#downgrade ⇒ Object
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/kamal/cli/main.rb', line 223 def downgrade confirming "This will replace Traefik with kamal-proxy and restart all accessories" do with_lock do if [:rolling] (KAMAL.hosts | KAMAL.accessory_hosts).each do |host| KAMAL.with_specific_hosts(host) do say "Downgrading #{host}...", :magenta if KAMAL.hosts.include?(host) invoke "kamal:cli:traefik:downgrade", [], .merge(confirmed: true, rolling: false) reset_invocation(Kamal::Cli::Traefik) end if KAMAL.accessory_hosts.include?(host) invoke "kamal:cli:accessory:downgrade", [ "all" ], .merge(confirmed: true, rolling: false) reset_invocation(Kamal::Cli::Accessory) end say "Downgraded #{host}", :magenta end end else say "Downgrading all hosts...", :magenta invoke "kamal:cli:traefik:downgrade", [], .merge(confirmed: true) invoke "kamal:cli:accessory:downgrade", [ "all" ], .merge(confirmed: true) say "Downgraded all hosts", :magenta end end end end |
#envify ⇒ Object
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/kamal/cli/main.rb', line 184 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 if Pathname.new(File.(env_template_path)).exist? # Ensure existing env doesn't pollute template evaluation content = with_original_env { ERB.new(File.read(env_template_path), trim_mode: "-").result } File.write(env_path, content, perm: 0600) unless [:skip_push] reload_env invoke "kamal:cli:env:push", end else puts "Skipping envify (no #{env_template_path} exist)" end end |
#init ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/kamal/cli/main.rb', line 144 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 unless (hooks_dir = Pathname.new(File.(".kamal/hooks"))).exist? hooks_dir.mkpath Pathname.new(File.("templates/sample_hooks", __dir__)).each_child do |sample_hook| FileUtils.cp sample_hook, hooks_dir, preserve: true end puts "Created sample hooks in .kamal/hooks" end if [:bundle] if (binstub = Pathname.new(File.("bin/kamal"))).exist? puts "Binstub already exists in bin/kamal (remove first to create a new one)" else puts "Adding Kamal to Gemfile and bundle..." run_locally do execute :bundle, :add, :kamal execute :bundle, :binstubs, :kamal end puts "Created binstub file in bin/kamal" end end end |
#redeploy ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/kamal/cli/main.rb', line 60 def redeploy runtime = print_runtime do = if [:skip_push] say "Pull app image...", :magenta invoke "kamal:cli:build:pull", [], else say "Build and push app image...", :magenta invoke "kamal:cli:build:deliver", [], end with_lock do run_hook "pre-deploy" say "Detect stale containers...", :magenta invoke "kamal:cli:app:stale_containers", [], .merge(stop: true) invoke "kamal:cli:app:boot", [], end end run_hook "post-deploy", runtime: runtime.round end |
#remove ⇒ Object
209 210 211 212 213 214 215 216 217 218 |
# File 'lib/kamal/cli/main.rb', line 209 def remove confirming "This will remove all containers and images. Are you sure?" do with_lock do invoke "kamal:cli:traefik:remove", [], .without(:confirmed) invoke "kamal:cli:app:remove", [], .without(:confirmed) invoke "kamal:cli:accessory:remove", [ "all" ], invoke "kamal:cli:registry:logout", [], .without(:confirmed).merge(skip_local: true) end end end |
#rollback(version) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/kamal/cli/main.rb', line 86 def rollback(version) rolled_back = false runtime = print_runtime do with_lock do = KAMAL.config.version = version old_version = nil if container_available?(version) run_hook "pre-deploy" invoke "kamal:cli:app:boot", [], .merge(version: version) rolled_back = true else say "The app version '#{version}' is not available as a container (use 'kamal app containers' for available versions)", :red end end end run_hook "post-deploy", runtime: runtime.round if rolled_back end |
#setup ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/kamal/cli/main.rb', line 4 def setup print_runtime do with_lock do = say "Ensure Docker is installed...", :magenta invoke "kamal:cli:server:bootstrap", [], say "Evaluate and push env files...", :magenta invoke "kamal:cli:main:envify", [], invoke "kamal:cli:env:push", [], invoke "kamal:cli:accessory:boot", [ "all" ], deploy end end end |
#version ⇒ Object
252 253 254 |
# File 'lib/kamal/cli/main.rb', line 252 def version puts Kamal::VERSION end |