Stop treating RAILS_MASTER_KEY as special

This commit is contained in:
David Heinemeier Hansson
2023-02-04 15:26:59 +01:00
parent 64a5a790a7
commit cf9a402ad8
5 changed files with 5 additions and 42 deletions

View File

@@ -15,12 +15,15 @@ servers:
registry: registry:
username: registry-user-name username: registry-user-name
password: <%= ENV.fetch("MRSK_REGISTRY_PASSWORD") %> password: <%= ENV.fetch("MRSK_REGISTRY_PASSWORD") %>
env:
secret:
- RAILS_MASTER_KEY
``` ```
Now you're ready to deploy a multi-arch image to the servers: 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: This will:
@@ -265,14 +268,6 @@ ARG RUBY_VERSION
FROM ruby:$RUBY_VERSION-slim as base 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 ### 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: 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:

View File

@@ -6,7 +6,6 @@ class Mrsk::Commands::App < Mrsk::Commands::Base
"-d", "-d",
"--restart unless-stopped", "--restart unless-stopped",
"--name", service_with_version, "--name", service_with_version,
*rails_master_key_arg,
*role.env_args, *role.env_args,
*config.volume_args, *config.volume_args,
*role.label_args, *role.label_args,
@@ -56,7 +55,6 @@ class Mrsk::Commands::App < Mrsk::Commands::Base
docker :run, docker :run,
("-it" if interactive), ("-it" if interactive),
"--rm", "--rm",
*rails_master_key_arg,
*config.env_args, *config.env_args,
*config.volume_args, *config.volume_args,
config.absolute_image, config.absolute_image,
@@ -130,12 +128,4 @@ class Mrsk::Commands::App < Mrsk::Commands::Base
def service_filter def service_filter
[ "--filter", "label=service=#{config.service}" ] [ "--filter", "label=service=#{config.service}" ]
end end
def rails_master_key_arg
if master_key = config.master_key
[ "-e", redact("RAILS_MASTER_KEY=#{master_key}") ]
else
[]
end
end
end end

View File

@@ -110,12 +110,6 @@ class Mrsk::Configuration
{ user: ssh_user, auth_methods: [ "publickey" ] } { user: ssh_user, auth_methods: [ "publickey" ] }
end 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? def valid?
ensure_required_keys_present && ensure_env_available ensure_required_keys_present && ensure_env_available

View File

@@ -4,7 +4,7 @@ class CommandsAppTest < ActiveSupport::TestCase
setup do setup do
ENV["RAILS_MASTER_KEY"] = "456" 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" } @app = Mrsk::Commands::App.new Mrsk::Configuration.new(@config).tap { |c| c.version = "999" }
end end
@@ -26,13 +26,6 @@ class CommandsAppTest < ActiveSupport::TestCase
@app.run.join(" ") @app.run.join(" ")
end 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 test "start" do
assert_equal \ assert_equal \
"docker start app-999", "docker start app-999",

View File

@@ -143,15 +143,6 @@ class ConfigurationTest < ActiveSupport::TestCase
assert_equal "app", @config.ssh_options[:user] assert_equal "app", @config.ssh_options[:user]
end 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 test "volume_args" do
assert_equal ["--volume", "/local/path:/container/path"], @config.volume_args assert_equal ["--volume", "/local/path:/container/path"], @config.volume_args
end end