diff --git a/README.md b/README.md index efa1ad5f..38bd277b 100644 --- a/README.md +++ b/README.md @@ -244,6 +244,14 @@ ARG RUBY_VERSION FROM ruby:$RUBY_VERSION-slim as base ``` +### Using without RAILS_MASTER_KEY + +If you're using MRSK with older Rails apps that predate RAILS_MASTER_KEY, or with a non-Rails app, you can skip the default usage and reference: + +```yaml +skip_master_key: true +``` + ### Using accessories for database, cache, search services You can manage your accessory services via MRSK as well. The services will build off public images, and will not be automatically updated when you deploy: diff --git a/lib/mrsk/commands/app.rb b/lib/mrsk/commands/app.rb index fa5e02af..9ca79482 100644 --- a/lib/mrsk/commands/app.rb +++ b/lib/mrsk/commands/app.rb @@ -98,6 +98,10 @@ class Mrsk::Commands::App < Mrsk::Commands::Base end def rails_master_key_arg - [ "-e", redact("RAILS_MASTER_KEY=#{config.master_key}") ] + if master_key = config.master_key + [ "-e", redact("RAILS_MASTER_KEY=#{master_key}") ] + else + [] + end end end diff --git a/lib/mrsk/configuration.rb b/lib/mrsk/configuration.rb index 66d982fb..4055f4c8 100644 --- a/lib/mrsk/configuration.rb +++ b/lib/mrsk/configuration.rb @@ -115,7 +115,9 @@ class Mrsk::Configuration end def master_key - ENV["RAILS_MASTER_KEY"] || File.read(Pathname.new(File.expand_path("config/master.key"))) + unless raw_config.skip_master_key + ENV["RAILS_MASTER_KEY"] || File.read(Pathname.new(File.expand_path("config/master.key"))) + end end def to_h diff --git a/test/commands/app_test.rb b/test/commands/app_test.rb index 75be5aa6..51ee7b3a 100644 --- a/test/commands/app_test.rb +++ b/test/commands/app_test.rb @@ -2,14 +2,18 @@ require "test_helper" require "mrsk/configuration" require "mrsk/commands/app" -ENV["RAILS_MASTER_KEY"] = "456" - class CommandsAppTest < ActiveSupport::TestCase setup do + ENV["RAILS_MASTER_KEY"] = "456" + @config = { service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, servers: [ "1.1.1.1" ] } @app = Mrsk::Commands::App.new Mrsk::Configuration.new(@config) end + teardown do + ENV["RAILS_MASTER_KEY"] = nil + end + test "run" do assert_equal \ [:docker, :run, "-d", "--restart unless-stopped", "--name", "app-missing", "-e", "RAILS_MASTER_KEY=456", "--label", "service=app", "--label", "role=web", "--label", "traefik.http.routers.app.rule='PathPrefix(`/`)'", "--label", "traefik.http.services.app.loadbalancer.healthcheck.path=/up", "--label", "traefik.http.services.app.loadbalancer.healthcheck.interval=1s", "--label", "traefik.http.middlewares.app.retry.attempts=3", "--label", "traefik.http.middlewares.app.retry.initialinterval=500ms", "dhh/app:missing"], @app.run @@ -27,4 +31,11 @@ class CommandsAppTest < ActiveSupport::TestCase [ :docker, :run, "--rm", "-e", "RAILS_MASTER_KEY=456", "dhh/app:missing", "bin/rails", "db:setup" ], @app.run_exec("bin/rails", "db:setup") end + + test "run without master key" do + ENV["RAILS_MASTER_KEY"] = nil + @app = Mrsk::Commands::App.new Mrsk::Configuration.new(@config.tap { |c| c[:skip_master_key] = true }) + + assert @app.run.exclude?("RAILS_MASTER_KEY=456") + end end diff --git a/test/configuration_test.rb b/test/configuration_test.rb index 09e64fa2..21f9c92e 100644 --- a/test/configuration_test.rb +++ b/test/configuration_test.rb @@ -1,10 +1,10 @@ require "test_helper" require "mrsk/configuration" -ENV["RAILS_MASTER_KEY"] = "456" - class ConfigurationTest < ActiveSupport::TestCase setup do + ENV["RAILS_MASTER_KEY"] = "456" + @deploy = { service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, @@ -21,6 +21,10 @@ class ConfigurationTest < ActiveSupport::TestCase @config_with_roles = Mrsk::Configuration.new(@deploy_with_roles) end + teardown do + ENV["RAILS_MASTER_KEY"] = nil + end + test "ensure valid keys" do assert_raise(ArgumentError) do Mrsk::Configuration.new(@deploy.tap { _1.delete(:service) }) @@ -134,6 +138,11 @@ class ConfigurationTest < ActiveSupport::TestCase assert_equal "456", @config.master_key end + test "skip master key" do + config = Mrsk::Configuration.new(@deploy.tap { |c| c[:skip_master_key] = true }) + assert_nil @config.master_key + end + test "volume_args" do assert_equal ["--volume", "/local/path:/container/path"], @config.volume_args end