Skip to content

Commit f63d344

Browse files
committed
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`.
1 parent be0cb4e commit f63d344

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

.github/workflows/devcontainer-smoke-test.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ jobs:
3333
- name: Generate rails app sqlite3
3434
run: bundle exec railties/exe/rails new myapp_sqlite --database="sqlite3" --dev
3535

36+
- name: Remove old deprecated docker-compose
37+
run: |
38+
sudo rm /usr/local/bin/docker-compose
39+
3640
- name: Test devcontainer sqlite3
3741
uses: devcontainers/[email protected]
3842
with:

railties/lib/rails/generators/rails/app/templates/.devcontainer/compose.yaml.tt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
name: "<%= app_name %>"
2+
13
services:
24
rails-app:
35
build:

railties/test/generators/app_generator_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,6 +1295,8 @@ def test_devcontainer
12951295
assert_match(/ARG RUBY_VERSION=#{RUBY_VERSION}/, content)
12961296
end
12971297
assert_compose_file do |compose_config|
1298+
assert_equal "my_app", compose_config["name"]
1299+
12981300
expected_rails_app_config = {
12991301
"build" => {
13001302
"context" => "..",

0 commit comments

Comments
 (0)