Add role concern with specialized cmds for job running

This commit is contained in:
David Heinemeier Hansson
2023-01-10 17:27:56 +01:00
parent 1cee87d440
commit e8beb362d0
8 changed files with 273 additions and 62 deletions

View File

@@ -19,15 +19,17 @@ namespace :mrsk do
desc "Run app on servers (or start them if they've already been run)"
task :run do
on(MRSK_CONFIG.hosts) do |host|
begin
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
else
raise
MRSK_CONFIG.roles.each do |role|
on(MRSK_CONFIG.role(role).hosts) do |host|
begin
execute *app.run(role: role)
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
else
raise
end
end
end
end
@@ -64,13 +66,13 @@ namespace :mrsk do
desc "Execute a custom task on the first defined server"
task :once do
on(MRSK_CONFIG.hosts.first) { |host| puts capture(*app.exec(ENV["CMD"])) }
on(MRSK_CONFIG.primary_host) { |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.hosts.first) { puts capture(*app.exec("bin/rails", ENV["CMD"])) }
on(MRSK_CONFIG.primary_host) { puts capture(*app.exec("bin/rails", ENV["CMD"])) }
end
end
end

View File

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