Add command execution

This commit is contained in:
David Heinemeier Hansson
2023-01-09 14:36:33 +01:00
parent 9641ce0edd
commit fe52ce6547
3 changed files with 82 additions and 1 deletions

View File

@@ -36,6 +36,14 @@ class Mrsk::Commands::App < Mrsk::Commands::Base
[ "docker ps -q #{service_filter.join(" ")} | xargs docker logs -f" ]
end
def exec(*command)
docker :exec,
"-e", redact("RAILS_MASTER_KEY=#{config.master_key}"),
*config.envs,
config.service_with_version,
*command
end
def list_containers
docker :container, :ls, "-a", *service_filter
end

View File

@@ -51,6 +51,30 @@ namespace :mrsk do
on(MRSK_CONFIG.servers) { |host| puts "App Host: #{host}\n" + capture(*app.info) + "\n\n" }
end
desc "Execute a custom task on servers passed in as CMD='bin/rake some:task'"
task :exec do
on(MRSK_CONFIG.servers) { |host| puts "App Host: #{host}\n" + capture(*app.exec(ENV["CMD"])) + "\n\n" }
end
namespace :exec do
desc "Execute Rails command on servers, like CMD='runner \"puts %(Hello World)\""
task :rails do
on(MRSK_CONFIG.servers) { |host| puts "App Host: #{host}\n" + capture(*app.exec("bin/rails", ENV["CMD"])) + "\n\n" }
end
desc "Execute a custom task on the first defined server"
task :once do
on(MRSK_CONFIG.servers.first) { |host| puts capture(*app.exec(ENV["CMD"])) }
end
namespace :once do
desc "Execute Rails command on the first defined server, like CMD='runner \"puts %(Hello World)\""
task :rails do
on(MRSK_CONFIG.servers.first) { puts capture(*app.exec("bin/rails", ENV["CMD"])) }
end
end
end
desc "List all the app containers currently on servers"
task :containers do
on(MRSK_CONFIG.servers) { |host| puts "App Host: #{host}\n" + capture(*app.list_containers) + "\n\n" }