New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement rake proxy for rails cli #22288

Closed
wants to merge 15 commits into
base: master
from

Conversation

Projects
None yet
5 participants
@dharamgollapudi
Contributor

dharamgollapudi commented Nov 14, 2015

  • This implements a thin proxy layer for rails cli to invoke the underlying rake tasks.
  • With this change all the rake tasks can be called/invoked directly with rails. (ex: rails stats, rails db:version, etc)
  • Also included a rake subcommand with shortcut set to k which can be used to query
    version and help info of rake, which supports all three formats as -h, --help and help.
  • This addresses #18878, and #21012
@rails-bot

This comment has been minimized.

Show comment
Hide comment
@rails-bot

rails-bot Nov 14, 2015

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @pixeltrix (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

rails-bot commented Nov 14, 2015

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @pixeltrix (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@timbreitkreutz

This comment has been minimized.

Show comment
Hide comment
@timbreitkreutz

timbreitkreutz Nov 14, 2015

@dharamgollapudi Did you happen to notice all the discussion in #21254 ? I was looking at doing something for #18878 also but got overwhelmed by the discussion there.

timbreitkreutz commented Nov 14, 2015

@dharamgollapudi Did you happen to notice all the discussion in #21254 ? I was looking at doing something for #18878 also but got overwhelmed by the discussion there.

@dharamgollapudi

This comment has been minimized.

Show comment
Hide comment
@dharamgollapudi

dharamgollapudi Nov 14, 2015

Contributor

@timbreitkreutz yes I did. My understanding per #18878 as well as follow up comments by @dhh and others in #21012, is that we needed a thin layer that proxies rake tasks, as we are not going to deprecate or move over all the existing tasks as they have dependencies. That is exactly what this pull request addresses, which handles all the rake tasks through rails cli.

Also the implementation in #21254 probably may have some performance penalties as it seems to define methods that call the underlying rake tasks. As rails cli is not a service, this will happen on every run.

Contributor

dharamgollapudi commented Nov 14, 2015

@timbreitkreutz yes I did. My understanding per #18878 as well as follow up comments by @dhh and others in #21012, is that we needed a thin layer that proxies rake tasks, as we are not going to deprecate or move over all the existing tasks as they have dependencies. That is exactly what this pull request addresses, which handles all the rake tasks through rails cli.

Also the implementation in #21254 probably may have some performance penalties as it seems to define methods that call the underlying rake tasks. As rails cli is not a service, this will happen on every run.

@kaspth kaspth assigned kaspth and unassigned pixeltrix Nov 22, 2015

@kaspth

This comment has been minimized.

Show comment
Hide comment
@kaspth

kaspth Nov 22, 2015

Member

This isn't exactly what we're going for. In addition to funneling tasks through Rails, we want to deprecate running tasks with Rake (regardless of whether we use Rake to run tasks internally).

What we've been trying to do in #21254 is create a lightweight command structure to give us easier parameter parsing in the future. It's been taking longer than I've wanted, so I'm open to also move things along here. Thanks 👍

Member

kaspth commented Nov 22, 2015

This isn't exactly what we're going for. In addition to funneling tasks through Rails, we want to deprecate running tasks with Rake (regardless of whether we use Rake to run tasks internally).

What we've been trying to do in #21254 is create a lightweight command structure to give us easier parameter parsing in the future. It's been taking longer than I've wanted, so I'm open to also move things along here. Thanks 👍

@kaspth

This comment has been minimized.

Show comment
Hide comment
@kaspth

kaspth Dec 9, 2015

Member

@dharamgollapudi hey, since writing the above message I've changed my opinion and think your change is good. Let me know if you still want to work on this and I'll review it more in depth. Thanks! ❤️

Member

kaspth commented Dec 9, 2015

@dharamgollapudi hey, since writing the above message I've changed my opinion and think your change is good. Let me know if you still want to work on this and I'll review it more in depth. Thanks! ❤️

@dharamgollapudi

This comment has been minimized.

Show comment
Hide comment
@dharamgollapudi

dharamgollapudi Dec 10, 2015

Contributor

@kaspth I am a bit confused now.
Upon reviewing/following #22457, I thought that we are going in that direction.
I am more that happy to work on this, given a proper direction and input.

Contributor

dharamgollapudi commented Dec 10, 2015

@kaspth I am a bit confused now.
Upon reviewing/following #22457, I thought that we are going in that direction.
I am more that happy to work on this, given a proper direction and input.

@kaspth

This comment has been minimized.

Show comment
Hide comment
@kaspth

kaspth Dec 10, 2015

Member

Sure, I can understand. We are generally going in that direction, but I don't think we will be there in time for Rails 5*. As such I think this is a great cover that gives leverage to work on the underpinnings without a deadline. I'll go through the PR now, 👍.

  • Partly because the command API doesn't hold its own yet, and I don't think it's worth it to just force all the tasks and existing commands over.
Member

kaspth commented Dec 10, 2015

Sure, I can understand. We are generally going in that direction, but I don't think we will be there in time for Rails 5*. As such I think this is a great cover that gives leverage to work on the underpinnings without a deadline. I'll go through the PR now, 👍.

  • Partly because the command API doesn't hold its own yet, and I don't think it's worth it to just force all the tasks and existing commands over.
@kaspth

View changes

Show outdated Hide outdated railties/lib/rails/commands.rb
@kaspth

View changes

Show outdated Hide outdated railties/lib/rails/commands/commands_tasks.rb
@kaspth

View changes

Show outdated Hide outdated railties/lib/rails/commands/commands_tasks.rb
@kaspth

View changes

Show outdated Hide outdated railties/lib/rails/commands/commands_tasks.rb
@kaspth

View changes

Show outdated Hide outdated railties/lib/rails/commands/commands_tasks.rb
@kaspth

View changes

Show outdated Hide outdated railties/lib/rails/commands/commands_tasks.rb
@kaspth

View changes

Show outdated Hide outdated railties/lib/rails/commands/rake_proxy.rb
@kaspth

View changes

Show outdated Hide outdated railties/lib/rails/commands/rake_proxy.rb
@kaspth

View changes

Show outdated Hide outdated railties/lib/rails/commands/rake_proxy.rb
@kaspth

View changes

Show outdated Hide outdated railties/lib/rails/commands/rake_proxy.rb
@kaspth

View changes

Show outdated Hide outdated railties/lib/rails/commands/rake_proxy.rb
@kaspth

View changes

Show outdated Hide outdated railties/lib/rails/commands/rake_proxy.rb
@kaspth

View changes

Show outdated Hide outdated railties/lib/rails/commands/rake_proxy.rb
@dharamgollapudi

This comment has been minimized.

Show comment
Hide comment
@dharamgollapudi

dharamgollapudi Dec 11, 2015

Contributor

@kaspth Implemented the changes per the feedback.
Let me know of any further changes.

Contributor

dharamgollapudi commented Dec 11, 2015

@kaspth Implemented the changes per the feedback.
Let me know of any further changes.

@dharamgollapudi

This comment has been minimized.

Show comment
Hide comment
@dharamgollapudi

dharamgollapudi Dec 11, 2015

Contributor

By running any of the following commands within the newly generated rails app:
rails
rails -h
rails --help
rails help

following is the output:

Usage: rails COMMAND [ARGS]

The most common rails commands are:
 generate    Generate new code (short-cut alias: "g")
 console     Start the Rails console (short-cut alias: "c")
 server      Start the Rails server (short-cut alias: "s")
 test        Run tests (short-cut alias: "t")
 dbconsole   Start a console for the database specified in config/database.yml
             (short-cut alias: "db")
 new         Create a new Rails application. "rails new my_app" creates a
             new application called MyApp in "./my_app"

In addition to those, there are:
 destroy      Undo code generated with "generate" (short-cut alias: "d")
 plugin new   Generates skeleton for developing a Rails plugin
 runner       Run a piece of code in the application environment (short-cut alias: "r")

All commands can be run with -h (or --help) for more information.

In addition to those, you can run the rake tasks as rails commands:

rails about                              # List versions of all Rails frameworks and the environment
rails assets:clean[keep]                 # Remove old compiled assets
rails assets:clobber                     # Remove compiled assets
rails assets:environment                 # Load asset compile environment
rails assets:precompile                  # Compile all the assets named in config.assets.precompile
rails cache_digests:dependencies         # Lookup first-level dependencies for TEMPLATE (like messages/show or comments/_comment.html)
rails cache_digests:nested_dependencies  # Lookup nested dependencies for TEMPLATE (like messages/show or comments/_comment.html)
rails db:create                          # Creates the database from DATABASE_URL or config/database.yml for the current RAILS_ENV (use db:create:all to create all databases in the config)
rails db:drop                            # Drops the database from DATABASE_URL or config/database.yml for the current RAILS_ENV (use db:drop:all to drop all databases in the config)
rails db:fixtures:load                   # Loads fixtures into the current environment's database
rails db:migrate                         # Migrate the database (options: VERSION=x, VERBOSE=false, SCOPE=blog)
rails db:migrate:status                  # Display status of migrations
rails db:rollback                        # Rolls the schema back to the previous version (specify steps w/ STEP=n)
rails db:schema:cache:clear              # Clears a db/schema_cache.dump file
rails db:schema:cache:dump               # Creates a db/schema_cache.dump file
rails db:schema:dump                     # Creates a db/schema.rb file that is portable against any DB supported by Active Record
rails db:schema:load                     # Loads a schema.rb file into the database
rails db:seed                            # Loads the seed data from db/seeds.rb
rails db:setup                           # Creates the database, loads the schema, and initializes with the seed data (use db:reset to also drop the database first)
rails db:structure:dump                  # Dumps the database structure to db/structure.sql
rails db:structure:load                  # Recreates the databases from the structure.sql file
rails db:version                         # Retrieves the current schema version number
rails initializers                       # Print out all defined initializers in the order they are invoked by Rails
rails log:clear                          # Truncates all *.log files in log/ to zero bytes (specify which logs with LOGS=test,development)
rails middleware                         # Prints out your Rack middleware stack
rails notes                              # Enumerate all annotations (use notes:optimize, :fixme, :todo for focus)
rails notes:custom                       # Enumerate a custom annotation, specify with ANNOTATION=CUSTOM
rails rails:template                     # Applies the template supplied by LOCATION=(/path/to/template) or URL
rails rails:update                       # Update configs and some other initially generated files (or use just update:configs or update:bin)
rails restart                            # Restart app by touching tmp/restart.txt
rails riak:restart                       # Restart riak locally
rails riak:start                         # Start riak locally
rails riak:stop                          # Stop riak locally
rails routes                             # Print out all defined routes in match order, with names
rails secret                             # Generate a cryptographically secure secret key (this is typically used to generate a secret for cookie sessions)
rails stats                              # Report code statistics (KLOCs, etc) from the application or engine
rails test                               # Runs all tests in test folder
rails test:db                            # Run tests quickly, but also reset db
rails time:zones:all                     # Displays all time zones, also available: time:zones:us, time:zones:local -- filter with OFFSET parameter, e.g., OFFSET=-6
rails tmp:clear                          # Clear cache and socket files from tmp/ (narrow w/ tmp:cache:clear, tmp:sockets:clear)
rails tmp:create                         # Creates tmp directories for cache, sockets, and pids
Contributor

dharamgollapudi commented Dec 11, 2015

By running any of the following commands within the newly generated rails app:
rails
rails -h
rails --help
rails help

following is the output:

Usage: rails COMMAND [ARGS]

The most common rails commands are:
 generate    Generate new code (short-cut alias: "g")
 console     Start the Rails console (short-cut alias: "c")
 server      Start the Rails server (short-cut alias: "s")
 test        Run tests (short-cut alias: "t")
 dbconsole   Start a console for the database specified in config/database.yml
             (short-cut alias: "db")
 new         Create a new Rails application. "rails new my_app" creates a
             new application called MyApp in "./my_app"

In addition to those, there are:
 destroy      Undo code generated with "generate" (short-cut alias: "d")
 plugin new   Generates skeleton for developing a Rails plugin
 runner       Run a piece of code in the application environment (short-cut alias: "r")

All commands can be run with -h (or --help) for more information.

In addition to those, you can run the rake tasks as rails commands:

rails about                              # List versions of all Rails frameworks and the environment
rails assets:clean[keep]                 # Remove old compiled assets
rails assets:clobber                     # Remove compiled assets
rails assets:environment                 # Load asset compile environment
rails assets:precompile                  # Compile all the assets named in config.assets.precompile
rails cache_digests:dependencies         # Lookup first-level dependencies for TEMPLATE (like messages/show or comments/_comment.html)
rails cache_digests:nested_dependencies  # Lookup nested dependencies for TEMPLATE (like messages/show or comments/_comment.html)
rails db:create                          # Creates the database from DATABASE_URL or config/database.yml for the current RAILS_ENV (use db:create:all to create all databases in the config)
rails db:drop                            # Drops the database from DATABASE_URL or config/database.yml for the current RAILS_ENV (use db:drop:all to drop all databases in the config)
rails db:fixtures:load                   # Loads fixtures into the current environment's database
rails db:migrate                         # Migrate the database (options: VERSION=x, VERBOSE=false, SCOPE=blog)
rails db:migrate:status                  # Display status of migrations
rails db:rollback                        # Rolls the schema back to the previous version (specify steps w/ STEP=n)
rails db:schema:cache:clear              # Clears a db/schema_cache.dump file
rails db:schema:cache:dump               # Creates a db/schema_cache.dump file
rails db:schema:dump                     # Creates a db/schema.rb file that is portable against any DB supported by Active Record
rails db:schema:load                     # Loads a schema.rb file into the database
rails db:seed                            # Loads the seed data from db/seeds.rb
rails db:setup                           # Creates the database, loads the schema, and initializes with the seed data (use db:reset to also drop the database first)
rails db:structure:dump                  # Dumps the database structure to db/structure.sql
rails db:structure:load                  # Recreates the databases from the structure.sql file
rails db:version                         # Retrieves the current schema version number
rails initializers                       # Print out all defined initializers in the order they are invoked by Rails
rails log:clear                          # Truncates all *.log files in log/ to zero bytes (specify which logs with LOGS=test,development)
rails middleware                         # Prints out your Rack middleware stack
rails notes                              # Enumerate all annotations (use notes:optimize, :fixme, :todo for focus)
rails notes:custom                       # Enumerate a custom annotation, specify with ANNOTATION=CUSTOM
rails rails:template                     # Applies the template supplied by LOCATION=(/path/to/template) or URL
rails rails:update                       # Update configs and some other initially generated files (or use just update:configs or update:bin)
rails restart                            # Restart app by touching tmp/restart.txt
rails riak:restart                       # Restart riak locally
rails riak:start                         # Start riak locally
rails riak:stop                          # Stop riak locally
rails routes                             # Print out all defined routes in match order, with names
rails secret                             # Generate a cryptographically secure secret key (this is typically used to generate a secret for cookie sessions)
rails stats                              # Report code statistics (KLOCs, etc) from the application or engine
rails test                               # Runs all tests in test folder
rails test:db                            # Run tests quickly, but also reset db
rails time:zones:all                     # Displays all time zones, also available: time:zones:us, time:zones:local -- filter with OFFSET parameter, e.g., OFFSET=-6
rails tmp:clear                          # Clear cache and socket files from tmp/ (narrow w/ tmp:cache:clear, tmp:sockets:clear)
rails tmp:create                         # Creates tmp directories for cache, sockets, and pids
throwing an error message. If the command is valid, a method of the same name
is called.
If the command is part of the COMMAND_WHITELIST, a method of the same name is called,
if not we proxy it to rake.

This comment has been minimized.

@kaspth

kaspth Dec 11, 2015

Member

I'd rather keep the old comment, we already copy the implementation, so we don't need to add more implementation details.

@kaspth

kaspth Dec 11, 2015

Member

I'd rather keep the old comment, we already copy the implementation, so we don't need to add more implementation details.

@@ -102,6 +110,10 @@ def new
end
end
def rake

This comment has been minimized.

@kaspth

kaspth Dec 11, 2015

Member

Remove this method.

@kaspth

kaspth Dec 11, 2015

Member

Remove this method.

@@ -39,6 +44,9 @@ def run_command!(command)
if COMMAND_WHITELIST.include?(command)
send(command)
else
ARGV.unshift(command)
send(:rake)

This comment has been minimized.

@kaspth

kaspth Dec 11, 2015

Member

Let's go with:

run_rake_task(command)
@kaspth

kaspth Dec 11, 2015

Member

Let's go with:

run_rake_task(command)
EOT
private

This comment has been minimized.

@kaspth

kaspth Dec 11, 2015

Member

Remove this newline.

@kaspth

kaspth Dec 11, 2015

Member

Remove this newline.

@kaspth

This comment has been minimized.

Show comment
Hide comment
@kaspth

kaspth Dec 11, 2015

Member

It seems we should just make the rake tasks flow straight with:

In addition to those, there are:
 destroy      Undo code generated with "generate" (short-cut alias: "d")
 plugin new   Generates skeleton for developing a Rails plugin
 runner       Run a piece of code in the application environment (short-cut alias: "r")
 about        List versions of all Rails frameworks and the environment
 # Rest of the tasks...

All commands can be run with -h (or --help) for more information.

So a one space delimiter and then 3 spaces minimum. Note: this means we have to make the HELP_MESSAGE more dynamic.

Member

kaspth commented Dec 11, 2015

It seems we should just make the rake tasks flow straight with:

In addition to those, there are:
 destroy      Undo code generated with "generate" (short-cut alias: "d")
 plugin new   Generates skeleton for developing a Rails plugin
 runner       Run a piece of code in the application environment (short-cut alias: "r")
 about        List versions of all Rails frameworks and the environment
 # Rest of the tasks...

All commands can be run with -h (or --help) for more information.

So a one space delimiter and then 3 spaces minimum. Note: this means we have to make the HELP_MESSAGE more dynamic.

Rake.application.load_rakefile
Rake.application.top_level
end
end

This comment has been minimized.

@kaspth

kaspth Dec 11, 2015

Member

Should be:

def run_rake_task(task)
  ARGV.unshift(task) # Prepend the command, so Rake knows how to run it.

  Rake.application...
end
@kaspth

kaspth Dec 11, 2015

Member

Should be:

def run_rake_task(task)
  ARGV.unshift(task) # Prepend the command, so Rake knows how to run it.

  Rake.application...
end
private
def write_rake_tasks_help_message
puts RAKE_TASKS_HELP_MESSAGE

This comment has been minimized.

@kaspth

kaspth Dec 11, 2015

Member

Don't think we need this constant anymore.

@kaspth

kaspth Dec 11, 2015

Member

Don't think we need this constant anymore.

def write_rake_tasks
width = rake_tasks.map { |t| t.name_with_args.length }.max || 10
rake_tasks.each do |t|
printf("#{Rake.application.name} %-#{width}s # %s\n", t.name_with_args, t.comment)

This comment has been minimized.

@kaspth

kaspth Dec 11, 2015

Member

Since I don't think we should print Rake.application.name, can we avoid setting it?

@kaspth

kaspth Dec 11, 2015

Member

Since I don't think we should print Rake.application.name, can we avoid setting it?

@kaspth

This comment has been minimized.

Show comment
Hide comment
@kaspth

kaspth Dec 13, 2015

Member

@dharamgollapudi thanks so much for the work! We needed this in sooner, so I addressed my comment in the merge commit here: 3e65c3d.

Thanks again ❤️

Member

kaspth commented Dec 13, 2015

@dharamgollapudi thanks so much for the work! We needed this in sooner, so I addressed my comment in the merge commit here: 3e65c3d.

Thanks again ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment