Switch to cmd array so we can redact

This commit is contained in:
David Heinemeier Hansson
2023-01-08 16:20:06 +01:00
parent 4ec04f8959
commit 998525c93d
9 changed files with 81 additions and 45 deletions

View File

@@ -9,23 +9,23 @@ namespace :mrsk do
desc "Build locally and push app image to registry"
task :push do
run_locally { execute app.push } unless ENV["VERSION"]
run_locally { execute *app.push } unless ENV["VERSION"]
end
desc "Pull app image from the registry onto servers"
task :pull do
on(MRSK_CONFIG.servers) { execute app.pull }
on(MRSK_CONFIG.servers) { execute *app.pull }
end
desc "Run app on servers (or start them if they've already been run)"
task :run do
on(MRSK_CONFIG.servers) do |host|
begin
execute app.run
execute *app.run
rescue SSHKit::Command::Failed => e
if e.message =~ /already in use/
puts "Container with same version already deployed on #{host}, starting that instead"
execute app.start, host: host
execute *app.start, host: host
else
raise
end
@@ -35,12 +35,12 @@ namespace :mrsk do
desc "Start existing app on servers"
task :start do
on(MRSK_CONFIG.servers) { execute app.start, raise_on_non_zero_exit: false }
on(MRSK_CONFIG.servers) { execute *app.start, raise_on_non_zero_exit: false }
end
desc "Stop app on servers"
task :stop do
on(MRSK_CONFIG.servers) { execute app.stop, raise_on_non_zero_exit: false }
on(MRSK_CONFIG.servers) { execute *app.stop, raise_on_non_zero_exit: false }
end
desc "Start app on servers (use VERSION=<git-hash> to designate which version)"
@@ -48,14 +48,19 @@ namespace :mrsk do
desc "Display information about app containers"
task :info do
on(MRSK_CONFIG.servers) { |host| puts "App Host: #{host}\n" + capture(app.info) + "\n\n" }
on(MRSK_CONFIG.servers) { |host| puts "App Host: #{host}\n" + capture(*app.info) + "\n\n" }
end
desc "Tail logs from app containers"
task :logs do
on(MRSK_CONFIG.servers) { execute *app.logs }
end
desc "Remove app containers and images from servers"
task remove: %i[ stop ] do
on(MRSK_CONFIG.servers) do
execute app.remove_containers
execute app.remove_images
execute *app.remove_containers
execute *app.remove_images
end
end
end

View File

@@ -6,13 +6,13 @@ namespace :mrsk do
namespace :registry do
desc "Login to the registry locally and remotely"
task :login do
run_locally { execute registry.login }
on(MRSK_CONFIG.servers) { execute registry.login }
run_locally { execute *registry.login }
on(MRSK_CONFIG.servers) { execute *registry.login }
end
desc "Logout of the registry remotely"
task :logout do
on(MRSK_CONFIG.servers) { execute registry.logout }
on(MRSK_CONFIG.servers) { execute *registry.logout }
end
end
end

View File

@@ -6,3 +6,5 @@ include SSHKit::DSL
MRSK_CONFIG = Mrsk::Configuration.load_file(Rails.root.join("config/deploy.yml"))
SSHKit::Backend::Netssh.configure { |ssh| ssh.ssh_options = MRSK_CONFIG.ssh_options }
SSHKit.config.command_map[:docker] = "docker"

View File

@@ -6,17 +6,17 @@ namespace :mrsk do
namespace :traefik do
desc "Run Traefik on servers"
task :run do
on(MRSK_CONFIG.servers) { execute traefik.run, raise_on_non_zero_exit: false }
on(MRSK_CONFIG.servers) { execute *traefik.run, raise_on_non_zero_exit: false }
end
desc "Start existing Traefik on servers"
task :start do
on(MRSK_CONFIG.servers) { execute traefik.start, raise_on_non_zero_exit: false }
on(MRSK_CONFIG.servers) { execute *traefik.start, raise_on_non_zero_exit: false }
end
desc "Stop Traefik on servers"
task :stop do
on(MRSK_CONFIG.servers) { execute traefik.stop, raise_on_non_zero_exit: false }
on(MRSK_CONFIG.servers) { execute *traefik.stop, raise_on_non_zero_exit: false }
end
desc "Restart Traefik on servers"
@@ -24,14 +24,14 @@ namespace :mrsk do
desc "Display information about Traefik containers from servers"
task :info do
on(MRSK_CONFIG.servers) { |host| puts "Traefik Host: #{host}\n" + capture(traefik.info) + "\n\n" }
on(MRSK_CONFIG.servers) { |host| puts "Traefik Host: #{host}\n" + capture(*traefik.info) + "\n\n" }
end
desc "Remove Traefik container and image from servers"
task remove: %i[ stop ] do
on(MRSK_CONFIG.servers) do
execute traefik.remove_container
execute traefik.remove_image
execute *traefik.remove_container
execute *traefik.remove_image
end
end
end