Skip to content

Commit cc94545

Browse files
committed
Do not include redis by default in dev container
Rails 8 will use the solid gems by default for job queue and action cable, which do not depend on redis. So we won't include redis in the devcontainer by default. Redis will be included in the app is generated with the skip-solid option and uses active job or action cable. For existing apps, we won't use redis if either of the solid gems are in use.
1 parent 6e46b42 commit cc94545

File tree

5 files changed

+46
-18
lines changed

5 files changed

+46
-18
lines changed

railties/CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
* Do not include redis by default in generated Dev Containers.
2+
3+
Now that applications use the Solid Queue and Solid Cache gems by default, we do not need to include redis
4+
in the Dev Container. We will only include redis if `--skip-solid` is used when generating an app that uses
5+
Active Job or Action Cable.
6+
7+
When generating a Dev Container for an existing app, we will not include redis if either of the solid gems
8+
are in use.
9+
10+
*Andrew Novoselac*
11+
112
* Use [Solid Cable](https://github.com/rails/solid_cable) as the default Action Cable adapter in production, configured as a separate queue database in config/database.yml. It keeps messages in a table and continuously polls for updates. This makes it possible to drop the common dependency on Redis, if it isn't needed for any other purpose. Despite polling, the performance of Solid Cable is comparable to Redis in most situations. And in all circumstances, it makes it easier to deploy Rails when Redis is no longer a required dependency for Action Cable functionality.
213

314
*DHH*

railties/lib/rails/commands/devcontainer/devcontainer_command.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def devcontainer_options
2424
app_name: Rails.application.railtie_name.chomp("_application"),
2525
database: !!defined?(ActiveRecord) && database,
2626
active_storage: !!defined?(ActiveStorage),
27-
redis: !!(defined?(ActionCable) || defined?(ActiveJob)),
27+
redis: !!((defined?(ActionCable) && !defined?(SolidCable)) || (defined?(ActiveJob) && !defined?(SolidQueue))),
2828
system_test: File.exist?("test/application_system_test_case.rb"),
2929
node: File.exist?(".node-version"),
3030
}

railties/lib/rails/generators/rails/app/app_generator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ def config_target_version
265265
def devcontainer
266266
devcontainer_options = {
267267
database: options[:database],
268-
redis: !(options[:skip_action_cable] && options[:skip_active_job]),
268+
redis: options[:skip_solid] && !(options[:skip_action_cable] && options[:skip_active_job]),
269269
system_test: depends_on_system_test?,
270270
active_storage: !options[:skip_active_storage],
271271
dev: options[:dev],

railties/test/commands/devcontainer_test.rb

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,39 @@ class Rails::Command::DevcontainerTest < ActiveSupport::TestCase
88

99
teardown { teardown_app }
1010

11-
test "generates devcontainer for default app" do
11+
test "generates devcontainer for default app with solid gems" do
1212
build_app
1313

14+
require "solid_cable"
15+
require "solid_queue"
16+
1417
output = rails "devcontainer"
1518

1619
assert_match "app_name: app_template", output
1720
assert_match "database: sqlite3", output
1821
assert_match "active_storage: true", output
19-
assert_match "redis: true", output
22+
assert_match "redis: false", output
2023
assert_match "system_test: true", output
2124
assert_match "node: false", output
2225
end
2326

24-
test "generates devcontainer for using mysql2 app" do
27+
test "generates dev container for without solid gems" do
28+
build_app
29+
30+
output = rails "devcontainer"
31+
32+
assert_match "redis: true", output
33+
end
34+
35+
test "generates dev container for using mysql2 app" do
2536
build_app
2637

2738
Dir.chdir(app_path) do
2839
use_mysql2
2940

3041
output = rails "devcontainer"
3142

32-
assert_match "app_name: app_template", output
3343
assert_match "database: mysql", output
34-
assert_match "active_storage: true", output
35-
assert_match "redis: true", output
36-
assert_match "system_test: true", output
37-
assert_match "node: false", output
3844

3945
assert_match "ghcr.io/rails/devcontainer/features/mysql-client", read_file(".devcontainer/devcontainer.json")
4046
end

railties/test/generators/app_generator_test.rb

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,14 +1256,12 @@ def test_devcontainer
12561256

12571257
assert_devcontainer_json_file do |content|
12581258
assert_equal "my_app", content["name"]
1259-
assert_equal "redis://redis:6379/1", content["containerEnv"]["REDIS_URL"]
12601259
assert_equal "45678", content["containerEnv"]["CAPYBARA_SERVER_PORT"]
12611260
assert_equal "selenium", content["containerEnv"]["SELENIUM_HOST"]
12621261
assert_includes content["features"].keys, "ghcr.io/rails/devcontainer/features/activestorage"
12631262
assert_includes content["features"].keys, "ghcr.io/devcontainers/features/github-cli:1"
12641263
assert_includes content["features"].keys, "ghcr.io/rails/devcontainer/features/sqlite3"
12651264
assert_includes(content["forwardPorts"], 3000)
1266-
assert_includes(content["forwardPorts"], 6379)
12671265
end
12681266
assert_file(".devcontainer/Dockerfile") do |content|
12691267
assert_match(/ARG RUBY_VERSION=#{RUBY_VERSION}/, content)
@@ -1284,7 +1282,7 @@ def test_devcontainer
12841282
},
12851283
"volumes" => ["../..:/workspaces:cached"],
12861284
"command" => "sleep infinity",
1287-
"depends_on" => ["selenium", "redis"]
1285+
"depends_on" => ["selenium"]
12881286
}
12891287

12901288
assert_equal expected_rails_app_config, compose_config["services"]["rails-app"]
@@ -1295,6 +1293,19 @@ def test_devcontainer
12951293
}
12961294

12971295
assert_equal expected_selenium_conifg, compose_config["services"]["selenium"]
1296+
end
1297+
end
1298+
1299+
def test_devcontainer_include_redis_skipping_solid
1300+
run_generator [destination_root, "--devcontainer", "--name=my-app", "--skip-solid"]
1301+
1302+
assert_devcontainer_json_file do |content|
1303+
assert_equal "redis://redis:6379/1", content["containerEnv"]["REDIS_URL"]
1304+
assert_includes content["forwardPorts"], 6379
1305+
end
1306+
1307+
assert_compose_file do |compose_config|
1308+
assert_includes compose_config["services"]["rails-app"]["depends_on"], "redis"
12981309

12991310
expected_redis_config = {
13001311
"image" => "redis:7.2",
@@ -1303,12 +1314,12 @@ def test_devcontainer
13031314
}
13041315

13051316
assert_equal expected_redis_config, compose_config["services"]["redis"]
1306-
assert_equal ["redis-data"], compose_config["volumes"].keys
1317+
assert_includes compose_config["volumes"].keys, "redis-data"
13071318
end
13081319
end
13091320

1310-
def test_devcontainer_no_redis_skipping_action_cable_and_active_job
1311-
run_generator [ destination_root, "--devcontainer", "--skip-action-cable", "--skip-active-job" ]
1321+
def test_devcontainer_no_redis_skipping_solid_action_cable_and_active_job
1322+
run_generator [ destination_root, "--devcontainer", "--skip-action-cable", "--skip-active-job", "--skip-solid" ]
13121323

13131324
assert_compose_file do |compose_config|
13141325
assert_not_includes compose_config["services"]["rails-app"]["depends_on"], "redis"
@@ -1468,11 +1479,11 @@ def test_devcontainer_no_selenium_when_skipping_system_test
14681479
run_generator [ destination_root, "--devcontainer", "--skip-system-test" ]
14691480

14701481
assert_compose_file do |compose_config|
1471-
assert_not_includes compose_config["services"]["rails-app"]["depends_on"], "selenium"
1482+
assert_nil compose_config["services"]["rails-app"]["depends_on"]
14721483
assert_not_includes compose_config["services"].keys, "selenium"
14731484
end
14741485
assert_devcontainer_json_file do |content|
1475-
assert_nil content["containerEnv"]["CAPYBARA_SERVER_PORT"]
1486+
assert_nil content["containerEnv"]
14761487
end
14771488
end
14781489

0 commit comments

Comments
 (0)