Skip to content

Commit

Permalink
Add bundler-cache feature in dev container
Browse files Browse the repository at this point in the history
  • Loading branch information
viktorianer committed Oct 3, 2024
1 parent ced8607 commit e6a825d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ services:

volumes:
- ../..:/workspaces:cached
- rbenv-data:/home/vscode/.rbenv

# Overrides default command so things don't shut down after the process ends.
command: sleep infinity
Expand Down Expand Up @@ -39,8 +40,10 @@ services:

<%- end -%>
<%= devcontainer_db_service_yaml(indentation: 4) %>
<%- if !volumes.empty? -%>

volumes:
rbenv-data:
<%- if !volumes.empty? -%>
<%- volumes.each do |volume| -%>
<%= volume %>:
<%- end -%>
Expand Down
29 changes: 21 additions & 8 deletions railties/test/generators/devcontainer_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,19 @@ def test_app_name_option
end
end

def test_app_volumes
run_generator

assert_compose_file do |compose|
expected_volumes = ["../..:/workspaces:cached", "rbenv-data:/home/vscode/.rbenv"]
actual_volumes = compose["services"]["rails-app"]["volumes"]
expected_volumes.each do |volume|
assert_includes actual_volumes, volume
end
assert_equal ["rbenv-data", "redis-data"], compose["volumes"].keys
end
end

def test_database_default_sqlite3
run_generator

Expand All @@ -84,7 +97,7 @@ def test_database_mariadb_mysql
},
}
assert_equal expected_mariadb_config, compose["services"]["mariadb"]
assert_includes compose["volumes"].keys, "mariadb-data"
assert_equal ["rbenv-data", "redis-data", "mariadb-data"], compose["volumes"].keys
assert_includes compose["services"]["rails-app"]["depends_on"], "mariadb"
end

Expand All @@ -111,7 +124,7 @@ def test_database_mariadb_trilogy
},
}
assert_equal expected_mariadb_config, compose["services"]["mariadb"]
assert_includes compose["volumes"].keys, "mariadb-data"
assert_equal ["rbenv-data", "redis-data", "mariadb-data"], compose["volumes"].keys
assert_includes compose["services"]["rails-app"]["depends_on"], "mariadb"
end

Expand All @@ -138,7 +151,7 @@ def test_database_mysql
"networks" => ["default"],
}
assert_equal expected_mysql_config, compose["services"]["mysql"]
assert_includes compose["volumes"].keys, "mysql-data"
assert_equal ["rbenv-data", "redis-data", "mysql-data"], compose["volumes"].keys
assert_includes compose["services"]["rails-app"]["depends_on"], "mysql"
end

Expand Down Expand Up @@ -172,7 +185,7 @@ def test_database_postgresql
}
}
assert_equal expected_postgres_config, compose["services"]["postgres"]
assert_includes compose["volumes"].keys, "postgres-data"
assert_equal ["rbenv-data", "redis-data", "postgres-data"], compose["volumes"].keys
assert_includes compose["services"]["rails-app"]["depends_on"], "postgres"
end

Expand Down Expand Up @@ -200,7 +213,7 @@ def test_database_trilogy
"networks" => ["default"],
}
assert_equal expected_mysql_config, compose["services"]["mysql"]
assert_includes compose["volumes"].keys, "mysql-data"
assert_equal ["rbenv-data", "redis-data", "mysql-data"], compose["volumes"].keys
assert_includes compose["services"]["rails-app"]["depends_on"], "mysql"
end

Expand Down Expand Up @@ -259,7 +272,7 @@ def test_redis_option_default
"volumes" => ["redis-data:/data"]
}
assert_equal expected_redis_config, compose["services"]["redis"]
assert_equal ["redis-data"], compose["volumes"].keys
assert_equal ["rbenv-data", "redis-data"], compose["volumes"].keys
end

assert_devcontainer_json_file do |devcontainer_json|
Expand All @@ -275,7 +288,7 @@ def test_redis_option_skip
assert_compose_file do |compose|
assert_not_includes compose["services"]["rails-app"]["depends_on"], "redis"
assert_nil compose["services"]["redis"]
assert_nil compose["volumes"]
assert_equal ["rbenv-data"], compose["volumes"].keys
end

assert_devcontainer_json_file do |devcontainer_json|
Expand Down Expand Up @@ -341,7 +354,7 @@ def test_common_config
"context" => "..",
"dockerfile" => ".devcontainer/Dockerfile"
},
"volumes" => ["../..:/workspaces:cached"],
"volumes" => ["../..:/workspaces:cached", "rbenv-data:/home/vscode/.rbenv"],
"command" => "sleep infinity"
}
actual_independent_config = compose["services"]["rails-app"].except("depends_on")
Expand Down

0 comments on commit e6a825d

Please sign in to comment.