Merge pull request #51518 from andrewn617/devcontainer-dev-mode

Make local rails available to devcontainer generated with `--dev`
This commit is contained in:
Rafael Mendonça França 2024-04-11 14:37:16 -03:00 committed by GitHub
commit d3b055eafd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 42 additions and 0 deletions

@ -39,6 +39,16 @@ def devcontainer_volumes
@devcontainer_volumes
end
def devcontainer_mounts
return @devcontainer_mounts if @devcontainer_mounts
@devcontainer_mounts = []
@devcontainer_mounts << local_rails_mount if options.dev?
@devcontainer_mounts
end
def devcontainer_needs_redis?
!(options.skip_action_cable? && options.skip_active_job?)
end
@ -127,6 +137,14 @@ def mariadb_service
def db_service_names
["mysql", "mariadb", "postgres"]
end
def local_rails_mount
{
type: "bind",
source: Rails::Generators::RAILS_DEV_PATH,
target: Rails::Generators::RAILS_DEV_PATH
}
end
end
end
end

@ -26,6 +26,12 @@
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root",
<%- if !devcontainer_mounts.empty? -%>
"mounts": [
<%= devcontainer_mounts.map { |mount| "{\n " + mount.map { |key, value| "\"#{key}\": \"#{value}\"" }.join(",\n ") + "\n }" }.join(",\n ") %>
],
<%- end -%>
// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "bin/setup"
}

@ -1415,6 +1415,18 @@ def test_devcontainer_no_depends_on_when_no_dependencies
end
end
def test_devcontainer_dev_flag_mounts_local_rails_repo
run_generator_using_prerelease [ destination_root, "--dev" ]
assert_devcontainer_json_file do |devcontainer_config|
rails_mount = devcontainer_config["mounts"].sole
assert_equal "bind", rails_mount["type"]
assert_equal Rails::Generators::RAILS_DEV_PATH, rails_mount["source"]
assert_equal Rails::Generators::RAILS_DEV_PATH, rails_mount["target"]
end
end
def test_skip_devcontainer
run_generator [ destination_root, "--skip-devcontainer" ]

@ -122,6 +122,12 @@ def assert_compose_file
end
end
def assert_devcontainer_json_file
assert_file ".devcontainer/devcontainer.json" do |content|
yield JSON.load(content)
end
end
private
def gemfile_locals
{