Don’t configure Kamal storage volume if not needed

Configuring a persistent storage volume in Kamal
is needed only for sqlite or Active Storage. If
using a different database or the
--skip-active-storage option, this configuration
can be skipped.
This commit is contained in:
Jerome Dalbert 2024-05-14 18:49:58 -07:00
parent 965b8c372a
commit 3156e50838
No known key found for this signature in database
GPG Key ID: 9B5649166FBD33E5
3 changed files with 35 additions and 1 deletions

View File

@ -366,6 +366,10 @@ module Rails
options[:skip_active_storage]
end
def skip_storage? # :doc:
skip_active_storage? && !sqlite3?
end
def skip_action_cable? # :doc:
options[:skip_action_cable]
end
@ -784,7 +788,7 @@ module Rails
def dockerfile_chown_directories
directories = %w(log tmp)
directories << "storage" unless skip_active_storage? && !sqlite3?
directories << "storage" unless skip_storage?
directories << "db" unless skip_active_record?
directories.sort

View File

@ -31,11 +31,13 @@ env:
# clear:
# DB_HOST: 192.168.0.2
<% unless skip_storage? %>
# Use a persistent storage volume for sqlite database files and local Active Storage files.
# Recommended to change this to a mounted volume path that is backed up off server.
volumes:
- "<%= app_name %>_storage:/rails/storage"
<% end %>
# Bridge fingerprinted assets, like JS and CSS, between versions to avoid
# hitting 404 on in-flight requests. Combines all files from new and old
# version inside the asset_path.

View File

@ -668,6 +668,34 @@ class AppGeneratorTest < Rails::Generators::TestCase
assert_no_file ".env.erb"
end
def test_inclusion_of_kamal_storage_volume
run_generator_and_bundler [destination_root]
assert_file "config/deploy.yml" do |content|
assert_match(%r{storage:/rails/storage}, content)
end
end
def test_inclusion_of_kamal_storage_volume_if_only_skip_active_storage_is_given
run_generator_and_bundler [destination_root, "--skip-active-storage"]
assert_file "config/deploy.yml" do |content|
assert_match(%r{storage:/rails/storage}, content)
end
end
def test_kamal_storage_volume_is_skipped_if_required
run_generator_and_bundler [
destination_root,
"--skip-active-storage",
"--database=postgresql"
]
assert_file "config/deploy.yml" do |content|
assert_no_match(%r{storage:/rails/storage}, content)
end
end
def test_usage_read_from_file
assert_called(File, :read, returns: "USAGE FROM FILE") do
assert_equal "USAGE FROM FILE", Rails::Generators::AppGenerator.desc