From cf9a402ad826677d6ce8ec619dd0df5bd06cd0ef Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sat, 4 Feb 2023 15:26:59 +0100 Subject: [PATCH] Stop treating RAILS_MASTER_KEY as special --- README.md | 13 ++++--------- lib/mrsk/commands/app.rb | 10 ---------- lib/mrsk/configuration.rb | 6 ------ test/commands/app_test.rb | 9 +-------- test/configuration_test.rb | 9 --------- 5 files changed, 5 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index e34db4ff..613981bd 100644 --- a/README.md +++ b/README.md @@ -15,12 +15,15 @@ servers: registry: username: registry-user-name password: <%= ENV.fetch("MRSK_REGISTRY_PASSWORD") %> +env: + secret: + - RAILS_MASTER_KEY ``` Now you're ready to deploy a multi-arch image to the servers: ``` -MRSK_REGISTRY_PASSWORD=pw mrsk deploy +RAILS_MASTER_KEY=123 MRSK_REGISTRY_PASSWORD=pw mrsk deploy ``` This will: @@ -265,14 +268,6 @@ 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 7dd66503..9c8407ac 100644 --- a/lib/mrsk/commands/app.rb +++ b/lib/mrsk/commands/app.rb @@ -6,7 +6,6 @@ class Mrsk::Commands::App < Mrsk::Commands::Base "-d", "--restart unless-stopped", "--name", service_with_version, - *rails_master_key_arg, *role.env_args, *config.volume_args, *role.label_args, @@ -56,7 +55,6 @@ class Mrsk::Commands::App < Mrsk::Commands::Base docker :run, ("-it" if interactive), "--rm", - *rails_master_key_arg, *config.env_args, *config.volume_args, config.absolute_image, @@ -130,12 +128,4 @@ class Mrsk::Commands::App < Mrsk::Commands::Base def service_filter [ "--filter", "label=service=#{config.service}" ] end - - def rails_master_key_arg - 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 6e7dff38..c2dfc188 100644 --- a/lib/mrsk/configuration.rb +++ b/lib/mrsk/configuration.rb @@ -110,12 +110,6 @@ class Mrsk::Configuration { user: ssh_user, auth_methods: [ "publickey" ] } end - def 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 valid? ensure_required_keys_present && ensure_env_available diff --git a/test/commands/app_test.rb b/test/commands/app_test.rb index d6a398e0..aaa0e751 100644 --- a/test/commands/app_test.rb +++ b/test/commands/app_test.rb @@ -4,7 +4,7 @@ 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" ] } + @config = { service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, servers: [ "1.1.1.1" ], env: { "secret" => [ "RAILS_MASTER_KEY" ] } } @app = Mrsk::Commands::App.new Mrsk::Configuration.new(@config).tap { |c| c.version = "999" } end @@ -26,13 +26,6 @@ class CommandsAppTest < ActiveSupport::TestCase @app.run.join(" ") 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 - test "start" do assert_equal \ "docker start app-999", diff --git a/test/configuration_test.rb b/test/configuration_test.rb index 7cbebabd..5146d516 100644 --- a/test/configuration_test.rb +++ b/test/configuration_test.rb @@ -143,15 +143,6 @@ class ConfigurationTest < ActiveSupport::TestCase assert_equal "app", @config.ssh_options[:user] end - test "master key" do - 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