From f63d344ce955eef8a41d048b7d309ed5b4b4b0d2 Mon Sep 17 00:00:00 2001 From: Cadu Ribeiro Date: Sat, 11 May 2024 10:54:04 -0300 Subject: [PATCH] Add name to DevContainer compose file Currently when you generate a project the compose.yaml generated file does not include the top-level name property. Not having this top-level name property makes all containers / volumes started by devcontainer to be prepended with the folder name, which is `devcontainer` in the case of the .devcontainer/compose.yml` file. This is ok if you run only one project with devcontainer but starts to get problem if you run multiple projects. If you have one project that runs on postgresql 15 and a new one that runs on postgresql 16 it will fail to boot the postgresql container because both devcontainers is using the same volume: `devcontainer_postgres-data`. This commit fixes this by setting the top-lavel name property with the project name, which will make the containers and volumes to be prepended with the project name and not with `devcontainer`. --- .github/workflows/devcontainer-smoke-test.yml | 4 ++++ .../rails/app/templates/.devcontainer/compose.yaml.tt | 2 ++ railties/test/generators/app_generator_test.rb | 2 ++ 3 files changed, 8 insertions(+) diff --git a/.github/workflows/devcontainer-smoke-test.yml b/.github/workflows/devcontainer-smoke-test.yml index d088de8f67..24d6f11c34 100644 --- a/.github/workflows/devcontainer-smoke-test.yml +++ b/.github/workflows/devcontainer-smoke-test.yml @@ -33,6 +33,10 @@ jobs: - name: Generate rails app sqlite3 run: bundle exec railties/exe/rails new myapp_sqlite --database="sqlite3" --dev + - name: Remove old deprecated docker-compose + run: | + sudo rm /usr/local/bin/docker-compose + - name: Test devcontainer sqlite3 uses: devcontainers/ci@v0.3 with: diff --git a/railties/lib/rails/generators/rails/app/templates/.devcontainer/compose.yaml.tt b/railties/lib/rails/generators/rails/app/templates/.devcontainer/compose.yaml.tt index 4541cf180f..f365e30d00 100644 --- a/railties/lib/rails/generators/rails/app/templates/.devcontainer/compose.yaml.tt +++ b/railties/lib/rails/generators/rails/app/templates/.devcontainer/compose.yaml.tt @@ -1,3 +1,5 @@ +name: "<%= app_name %>" + services: rails-app: build: diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 83a6109612..59db6951cb 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -1295,6 +1295,8 @@ def test_devcontainer assert_match(/ARG RUBY_VERSION=#{RUBY_VERSION}/, content) end assert_compose_file do |compose_config| + assert_equal "my_app", compose_config["name"] + expected_rails_app_config = { "build" => { "context" => "..",