Extract executions into separate concern
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
require "mrsk/commands/base"
|
||||
require "mrsk/commands/concerns/repository"
|
||||
require "mrsk/commands/concerns"
|
||||
|
||||
class Mrsk::Commands::App < Mrsk::Commands::Base
|
||||
include Mrsk::Commands::Concerns::Repository
|
||||
include Mrsk::Commands::Concerns::Executions,
|
||||
Mrsk::Commands::Concerns::Repository
|
||||
|
||||
def run(role: :web)
|
||||
role = config.role(role)
|
||||
@@ -42,32 +43,6 @@ class Mrsk::Commands::App < Mrsk::Commands::Base
|
||||
("grep '#{grep}'" if grep)
|
||||
end
|
||||
|
||||
def execute_in_existing_container(*command, interactive: false)
|
||||
docker :exec,
|
||||
("-it" if interactive),
|
||||
config.service_with_version,
|
||||
*command
|
||||
end
|
||||
|
||||
def execute_in_new_container(*command, interactive: false)
|
||||
docker :run,
|
||||
("-it" if interactive),
|
||||
"--rm",
|
||||
*rails_master_key_arg,
|
||||
*config.env_args,
|
||||
*config.volume_args,
|
||||
config.absolute_image,
|
||||
*command
|
||||
end
|
||||
|
||||
def execute_in_existing_container_over_ssh(*command, host:)
|
||||
run_over_ssh execute_in_existing_container(*command, interactive: true).join(" "), host: host
|
||||
end
|
||||
|
||||
def execute_in_new_container_over_ssh(*command, host:)
|
||||
run_over_ssh execute_in_new_container(*command, interactive: true).join(" "), host: host
|
||||
end
|
||||
|
||||
def follow_logs(host:, grep: nil)
|
||||
run_over_ssh pipe(
|
||||
current_container_id,
|
||||
|
||||
5
lib/mrsk/commands/concerns.rb
Normal file
5
lib/mrsk/commands/concerns.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
module Mrsk::Commands::Concerns
|
||||
end
|
||||
|
||||
require "mrsk/commands/concerns/executions"
|
||||
require "mrsk/commands/concerns/repository"
|
||||
27
lib/mrsk/commands/concerns/executions.rb
Normal file
27
lib/mrsk/commands/concerns/executions.rb
Normal file
@@ -0,0 +1,27 @@
|
||||
module Mrsk::Commands::Concerns::Executions
|
||||
def execute_in_existing_container(*command, interactive: false)
|
||||
docker :exec,
|
||||
("-it" if interactive),
|
||||
config.service_with_version,
|
||||
*command
|
||||
end
|
||||
|
||||
def execute_in_new_container(*command, interactive: false)
|
||||
docker :run,
|
||||
("-it" if interactive),
|
||||
"--rm",
|
||||
*rails_master_key_arg,
|
||||
*config.env_args,
|
||||
*config.volume_args,
|
||||
config.absolute_image,
|
||||
*command
|
||||
end
|
||||
|
||||
def execute_in_existing_container_over_ssh(*command, host:)
|
||||
run_over_ssh execute_in_existing_container(*command, interactive: true).join(" "), host: host
|
||||
end
|
||||
|
||||
def execute_in_new_container_over_ssh(*command, host:)
|
||||
run_over_ssh execute_in_new_container(*command, interactive: true).join(" "), host: host
|
||||
end
|
||||
end
|
||||
@@ -1,21 +1,19 @@
|
||||
module Mrsk::Commands::Concerns
|
||||
module Repository
|
||||
def container_id_for(container_name:)
|
||||
docker :container, :ls, "-a", "-f", "name=#{container_name}", "-q"
|
||||
end
|
||||
module Mrsk::Commands::Concerns::Repository
|
||||
def container_id_for(container_name:)
|
||||
docker :container, :ls, "-a", "-f", "name=#{container_name}", "-q"
|
||||
end
|
||||
|
||||
def current_running_version
|
||||
# FIXME: Find more graceful way to extract the version from "app-version" than using sed and tail!
|
||||
pipe \
|
||||
docker(:ps, "--filter", "label=service=#{config.service}", "--format", '"{{.Names}}"'),
|
||||
%(sed 's/-/\\n/g'),
|
||||
"tail -n 1"
|
||||
end
|
||||
def current_running_version
|
||||
# FIXME: Find more graceful way to extract the version from "app-version" than using sed and tail!
|
||||
pipe \
|
||||
docker(:ps, "--filter", "label=service=#{service_name}", "--format", '"{{.Names}}"'),
|
||||
%(sed 's/-/\\n/g'),
|
||||
"tail -n 1"
|
||||
end
|
||||
|
||||
def most_recent_version_from_available_images
|
||||
pipe \
|
||||
docker(:image, :ls, "--format", '"{{.Tag}}"', config.repository),
|
||||
"head -n 1"
|
||||
end
|
||||
def most_recent_version_from_available_images
|
||||
pipe \
|
||||
docker(:image, :ls, "--format", '"{{.Tag}}"', config.repository),
|
||||
"head -n 1"
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user