forked from rails/rails
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
05b9cdb
commit e8f4266
Showing
7 changed files
with
148 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
railties/lib/rails/generators/rails/devcontainer/devcontainer_generator.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails/generators" | ||
|
||
module Rails | ||
module Generators | ||
module Devcontainer | ||
class DevcontainerGenerator < Base # :nodoc: | ||
class_option :database, enum: Database::DATABASES, type: :string, | ||
desc: "Database" | ||
|
||
class_option :redis, type: :boolean, default: true, | ||
desc: "Redis" | ||
|
||
class_option :system_test, type: :boolean, default: true, | ||
desc: "System" | ||
|
||
class_option :active_storage, type: :boolean, default: true, | ||
desc: "System" | ||
|
||
class_option :node, type: :boolean, default: false, | ||
desc: "System" | ||
|
||
class_option :dev, type: :boolean, default: false, | ||
desc: "Dev" | ||
|
||
class_option :app_name, type: :string, default: "Rails app", desc: "Name" | ||
|
||
def generate | ||
empty_directory ".devcontainer" | ||
|
||
template ".devcontainer/devcontainer.json" | ||
template ".devcontainer/Dockerfile" | ||
template ".devcontainer/compose.yaml" | ||
end | ||
|
||
private | ||
def devcontainer_dependencies | ||
return @devcontainer_dependencies if @devcontainer_dependencies | ||
|
||
@devcontainer_dependencies = [] | ||
|
||
@devcontainer_dependencies << "selenium" if options[:system_test] | ||
@devcontainer_dependencies << "redis" if options[:redis] | ||
@devcontainer_dependencies << database.name if database.service | ||
@devcontainer_dependencies | ||
end | ||
|
||
def devcontainer_variables | ||
return @devcontainer_variables if @devcontainer_variables | ||
|
||
@devcontainer_variables = {} | ||
|
||
@devcontainer_variables["CAPYBARA_SERVER_PORT"] = "45678" if options[:system_test] | ||
@devcontainer_variables["SELENIUM_HOST"] = "selenium" if options[:system_test] | ||
@devcontainer_variables["REDIS_URL"] = "redis://redis:6379/1" if options[:redis] | ||
@devcontainer_variables["DB_HOST"] = database.name if database.service | ||
|
||
@devcontainer_variables | ||
end | ||
|
||
def devcontainer_volumes | ||
return @devcontainer_volumes if @devcontainer_volumes | ||
|
||
@devcontainer_volumes = [] | ||
|
||
@devcontainer_volumes << "redis-data" if options[:redis] | ||
@devcontainer_volumes << database.volume if database.volume | ||
|
||
@devcontainer_volumes | ||
end | ||
|
||
def devcontainer_features | ||
return @devcontainer_features if @devcontainer_features | ||
|
||
@devcontainer_features = { | ||
"ghcr.io/devcontainers/features/github-cli:1" => {} | ||
} | ||
|
||
@devcontainer_features["ghcr.io/rails/devcontainer/features/activestorage"] = {} if options[:active_storage] | ||
@devcontainer_features["ghcr.io/devcontainers/features/node:1"] = {} if options[:node] | ||
|
||
@devcontainer_features.merge!(database.feature) if database.feature | ||
|
||
@devcontainer_features | ||
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_forward_ports | ||
return @devcontainer_forward_ports if @devcontainer_forward_ports | ||
|
||
@devcontainer_forward_ports = [3000] | ||
@devcontainer_forward_ports << database.port if database.port | ||
@devcontainer_forward_ports << 6379 if options[:redis] | ||
|
||
@devcontainer_forward_ports | ||
end | ||
|
||
def database | ||
@database ||= Database.build(options[:database]) | ||
end | ||
|
||
def devcontainer_db_service_yaml(**options) | ||
return unless service = database.service | ||
|
||
{ database.name => service }.to_yaml(**options)[4..-1] | ||
end | ||
|
||
def local_rails_mount | ||
{ | ||
type: "bind", | ||
source: Rails::Generators::RAILS_DEV_PATH, | ||
target: Rails::Generators::RAILS_DEV_PATH | ||
} | ||
end | ||
end | ||
end | ||
end | ||
end |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...plates/.devcontainer/devcontainer.json.tt → ...plates/.devcontainer/devcontainer.json.tt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters