This commit is contained in:
David Heinemeier Hansson
2023-01-07 15:32:25 +01:00
commit f7f61f697f
20 changed files with 522 additions and 0 deletions

31
lib/tasks/mrsk/app.rake Normal file
View File

@@ -0,0 +1,31 @@
require_relative "setup"
app = Mrsk::Commands::App.new(MRSK_CONFIG)
namespace :mrsk do
namespace :app do
desc "Build and push app image to servers"
task :push do
run_locally { execute app.push }
on(MRSK_CONFIG.servers) { execute app.pull }
end
desc "Start app on servers"
task :start do
on(MRSK_CONFIG.servers) { execute app.start }
end
desc "Stop app on servers"
task :stop do
on(MRSK_CONFIG.servers) { execute app.stop, raise_on_non_zero_exit: false }
end
desc "Restart app on servers"
task restart: %i[ stop start ]
desc "Display information about app containers"
task :info do
on(MRSK_CONFIG.servers) { |host| puts "Host: #{host}\n" + capture(app.info) + "\n\n" }
end
end
end

12
lib/tasks/mrsk/mrsk.rake Normal file
View File

@@ -0,0 +1,12 @@
namespace :mrsk do
desc "Push the latest version of the app, ensure Traefik is running, then restart app"
task deploy: [ "app:push", "traefik:start", "app:restart" ]
desc "Display information about Traefik and app containers"
task info: [ "traefik:info", "app:info" ]
desc "Create config stub"
task :init do
Rails.root.join("config/deploy.yml")
end
end

View File

@@ -0,0 +1,17 @@
require_relative "setup"
registry = Mrsk::Commands::Registry.new
namespace :mrsk do
namespace :registry do
desc "Login to the registry using ENV['DOCKER_USER'] and ENV['DOCKER_PASSWORD']"
task :login do
if ENV["DOCKER_USER"].present? && ENV["DOCKER_PASSWORD"].present?
run_locally { execute registry.login }
on(MRSK_CONFIG.servers) { execute registry.login }
else
puts "Skipping login due to missing ENV['DOCKER_USER'] and ENV['DOCKER_PASSWORD']"
end
end
end
end

10
lib/tasks/mrsk/setup.rb Normal file
View File

@@ -0,0 +1,10 @@
require "sshkit"
require "sshkit/dsl"
include SSHKit::DSL
MRSK_CONFIG = Mrsk::Configuration.load_file(Rails.root.join("config/deploy.yml"))
SSHKit::Backend::Netssh.configure do |ssh|
ssh.ssh_options = { user: MRSK_CONFIG.ssh_user, auth_methods: [ "publickey" ] }
end

View File

@@ -0,0 +1,25 @@
require_relative "setup"
traefik = Mrsk::Commands::Traefik.new
namespace :mrsk do
namespace :traefik do
desc "Start Traefik"
task :start do
on(MRSK_CONFIG.servers) { execute traefik.start, raise_on_non_zero_exit: false }
end
desc "Stop Traefik"
task :stop do
on(MRSK_CONFIG.servers) { execute traefik.stop, raise_on_non_zero_exit: false }
end
desc "Restart Traefik"
task restart: %i[ stop start ]
desc "Display information about Traefik containers"
task :info do
on(MRSK_CONFIG.servers) { |host| puts "Host: #{host}\n" + capture(traefik.info) + "\n\n" }
end
end
end