Add configuration for hooks_path
This commit is contained in:
@@ -908,6 +908,8 @@ You can run custom scripts at specific points with hooks.
|
|||||||
|
|
||||||
Hooks should be stored in the .mrsk/hooks folder. Running mrsk init will build that folder and add some sample scripts.
|
Hooks should be stored in the .mrsk/hooks folder. Running mrsk init will build that folder and add some sample scripts.
|
||||||
|
|
||||||
|
You can change their location by setting `hooks_path` in the configuration file.
|
||||||
|
|
||||||
If the script returns a non-zero exit code the command will be aborted.
|
If the script returns a non-zero exit code the command will be aborted.
|
||||||
|
|
||||||
There are currently two hooks:
|
There are currently two hooks:
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
class Mrsk::Commands::Hook < Mrsk::Commands::Base
|
class Mrsk::Commands::Hook < Mrsk::Commands::Base
|
||||||
def run(hook, **details)
|
def run(hook, **details)
|
||||||
[ ".mrsk/hooks/#{hook}", env: tags(**details).env ]
|
[ hook_file(hook), env: tags(**details).env ]
|
||||||
end
|
end
|
||||||
|
|
||||||
def hook_exists?(hook)
|
def hook_exists?(hook)
|
||||||
@@ -9,6 +9,6 @@ class Mrsk::Commands::Hook < Mrsk::Commands::Base
|
|||||||
|
|
||||||
private
|
private
|
||||||
def hook_file(hook)
|
def hook_file(hook)
|
||||||
".mrsk/hooks/#{hook}"
|
"#{config.hooks_path}/#{hook}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ require "erb"
|
|||||||
require "net/ssh/proxy/jump"
|
require "net/ssh/proxy/jump"
|
||||||
|
|
||||||
class Mrsk::Configuration
|
class Mrsk::Configuration
|
||||||
delegate :service, :image, :servers, :env, :labels, :registry, :builder, :stop_wait_time, to: :raw_config, allow_nil: true
|
delegate :service, :image, :servers, :env, :labels, :registry, :builder, :stop_wait_time, :hooks_path, to: :raw_config, allow_nil: true
|
||||||
delegate :argumentize, :argumentize_env_with_secrets, :optionize, to: Mrsk::Utils
|
delegate :argumentize, :argumentize_env_with_secrets, :optionize, to: Mrsk::Utils
|
||||||
|
|
||||||
attr_accessor :destination
|
attr_accessor :destination
|
||||||
@@ -197,6 +197,10 @@ class Mrsk::Configuration
|
|||||||
raw_config.traefik || {}
|
raw_config.traefik || {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def hooks_path
|
||||||
|
raw_config.hooks_path || ".mrsk/hooks"
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
# Will raise ArgumentError if any required config keys are missing
|
# Will raise ArgumentError if any required config keys are missing
|
||||||
def ensure_required_keys_present
|
def ensure_required_keys_present
|
||||||
|
|||||||
@@ -25,8 +25,18 @@ class CommandsHookTest < ActiveSupport::TestCase
|
|||||||
], new_command.run("foo")
|
], new_command.run("foo")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "run with custom hooks_path" do
|
||||||
|
assert_equal [
|
||||||
|
"custom/hooks/path/foo",
|
||||||
|
{ env: {
|
||||||
|
"MRSK_RECORDED_AT" => @recorded_at,
|
||||||
|
"MRSK_PERFORMER" => @performer,
|
||||||
|
"MRSK_VERSION" => "123" } }
|
||||||
|
], new_command(hooks_path: "custom/hooks/path").run("foo")
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def new_command
|
def new_command(**extra_config)
|
||||||
Mrsk::Commands::Hook.new(Mrsk::Configuration.new(@config, version: "123"))
|
Mrsk::Commands::Hook.new(Mrsk::Configuration.new(@config.merge(**extra_config), version: "123"))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user