Skip to content

Commit

Permalink
Don't include depends_on in dockercompose if no dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewn617 committed Jan 29, 2024
1 parent e18de91 commit 759e261
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
14 changes: 14 additions & 0 deletions railties/lib/rails/generators/rails/app/app_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,20 @@ def after_bundle(&block) # :doc:
def get_builder_class
defined?(::AppBuilder) ? ::AppBuilder : Rails::AppBuilder
end

def devcontainer_dependencies
return @devcontainer_dependencies if @devcontainer_dependencies

@devcontainer_dependencies = []

@devcontainer_dependencies << "selenium" if depends_on_system_test?
@devcontainer_dependencies << "redis" unless options.skip_action_cable? && options.skip_active_job?
@devcontainer_dependencies << "postgres" if options.database == "postgresql"
@devcontainer_dependencies << "mysql" if options.database == "mysql"
@devcontainer_dependencies << "mariadb" if options.database == "trilogy"

@devcontainer_dependencies
end
end

# This class handles preparation of the arguments before the AppGenerator is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,11 @@ services:
# (Adding the "ports" property to this file will not forward from a Codespace.)
ports:
- 45678:45678
<%- if !devcontainer_dependencies.empty? -%>
depends_on:
<%- if depends_on_system_test? -%>
- selenium
<%- end -%>
<%- unless options.skip_active_job? && options.skip_action_cable? -%>
- redis
<%- end -%>
<%- if options.database == "postgresql" -%>
- postgres
<%- end -%>
<%- if options.database == "mysql" -%>
- mysql
<%- devcontainer_dependencies.each do |dependency| -%>
- <%= dependency %>
<%- end -%>
<%- if options.database == "trilogy" -%>
- mariadb
<%- end -%>

<%- if depends_on_system_test? -%>
Expand Down
9 changes: 9 additions & 0 deletions railties/test/generators/app_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,7 @@ def test_devcontainer
end
assert_file(".devcontainer/Dockerfile")
assert_file(".devcontainer/docker-compose.yml") do |content|
assert_match /depends_on:/, content
assert_match /- selenium/, content
assert_match /selenium:/, content
assert_match /redis:/, content
Expand Down Expand Up @@ -1349,6 +1350,14 @@ def test_devcontainer_no_selenium_when_skipping_system_test
end
end

def test_devcontainer_no_depends_on_when_no_dependencies
run_generator [ destination_root, "--minimal" ]

assert_file(".devcontainer/docker-compose.yml") do |content|
assert_no_match /depends_on:/, content
end
end

private
def assert_node_files
assert_file ".node-version" do |content|
Expand Down

0 comments on commit 759e261

Please sign in to comment.