{"id":17228644,"url":"https://github.com/njonsson/cape","last_synced_at":"2025-04-05T12:06:44.464Z","repository":{"id":1939885,"uuid":"2869068","full_name":"njonsson/cape","owner":"njonsson","description":"Dynamically generates Capistrano recipes for Rake tasks","archived":false,"fork":false,"pushed_at":"2021-01-03T02:01:03.000Z","size":715,"stargazers_count":179,"open_issues_count":5,"forks_count":5,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-29T11:08:36.198Z","etag":null,"topics":["api","capistrano","deployment","fluid","rake","ruby"],"latest_commit_sha":null,"homepage":"http://njonsson.github.io/cape","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/njonsson.png","metadata":{"files":{"readme":"README.markdown","changelog":"History.markdown","contributing":null,"funding":null,"license":"License.markdown","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-11-28T18:11:33.000Z","updated_at":"2025-02-23T12:13:00.000Z","dependencies_parsed_at":"2022-08-06T11:16:06.787Z","dependency_job_id":null,"html_url":"https://github.com/njonsson/cape","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/njonsson%2Fcape","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/njonsson%2Fcape/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/njonsson%2Fcape/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/njonsson%2Fcape/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/njonsson","download_url":"https://codeload.github.com/njonsson/cape/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247332606,"owners_count":20921853,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","capistrano","deployment","fluid","rake","ruby"],"created_at":"2024-10-15T04:44:40.279Z","updated_at":"2025-04-05T12:06:44.442Z","avatar_url":"https://github.com/njonsson.png","language":"Ruby","readme":"                    _____     __\n                   / ___/___ / /_  __ _____ __ ______\n                  / (_ // -_) __/ / // / _ | // / __/\n                  \\___/ \\__/\\__/  \\_, /\\___|_,_/_/\n          '-(+++++...            /___/ ............  s++++++++.\n       .(++++++++++++(      -+++~~~~~  'N++++++++++= B++++++++s\n      '+++++++++++++++(     DN=++++++\u003c -NB+++++++++s Bz++++++++\n      +++++++++++++++++.   'NNN=++++++(-BNB+++++++++'BN========-\n     =B=+++++++++sDBBBBs\u003c. +NNNN=+++++(\u003cNNNBDBDBNNNNDBNNBBBBBBBz\n    'NN+s+++++=BBBh=+((+sB=DNNNNNBBBNNDhNNNN'   ..  -BNs      (z\n    sN+N+z+++sBs-        .hNNNNBNh(-'   NNNN.  .NB-  \u003cNs   +BBBz\n    D+N+N+z=Bs.   .~.     'NNNNNB~      DNNN   .NN+  (Ns   =B+~\n    BN+N+NNB+    ~NBD      BNNNBN   h'  hNNN   .Bs\u003c  \u003cNs   =Dz~\n    BNNNN+ND     +BhB      DNNNBz  'N~  sNNN   'ND'  hNs    -(z-\n    NNNNNNB(     sDDN      hNNNB(  +N~  +NNN    ..-\u003chBNs    ~=h-\n    NNNNNNB-     sDBN     'DNNNN.  DN~  \u003cBNN   'NNhs(NNs   =NN-\n    NNNNNNB'     zNNN(+sDNNBNNNz  .NB(  ~BNN   'D    NNs   =Bh~\n    NNNNNNN.     zNNNBNBBNNNNNB(  \u003cNB~  'BNB   'D    \u003cBs   =NNNN\n    NNNNNNN.     zNNNNNNNNNNBNN.  .     .NDB   -D     hs       N\n    NNNNNNN.     zNNNNNhBNBN=+z   +BN-   NDB  '(D     \u003cBhhhhhhhN\n    BNNNNNN.     zNNNh=\u003c~. h-s\u003c   D~D'.-~B\u003cNBNBDs     ''``\n    DNNNNNN.     zNNN      D-B-~(+B DNBDzs-`\n    sNNNNNN.     zNNN      B(NDhs=(  ''`\n    (BNNNNN'     zNDB     ~D.\n     sNNNNB-     +hsz     h\u003c                             O___\n      \u003cNNNB(     -=s'   'hz      ___  ___              \u003c s \u003e \\____\n        ~BNh          .+B+      / _ \\/ _ \\               = \\    /\n          ~Dz~.   .~+zB='       \\___/_//_/              / \\ \\__/\n            \u003chNNBNBh=(.                                /   \\   `\n               ..\n\n# Cape\n\n[![Travis CI build status]](http://travis-ci.org/njonsson/cape          \"Travis CI build status\")\n[![Gemnasium build status]](http://gemnasium.com/njonsson/cape          \"Gemnasium build status\")\n[![Code Climate report]   ](http://codeclimate.com/github/njonsson/cape \"Code Climate report\")\n[![Inline docs]           ](http://inch-pages.github.io/github/njonsson/cape \"Inline docs\")\n[![RubyGems release]      ](http://rubygems.org/gems/cape               \"RubyGems release\")\n\nIf\n\n* **You use [Capistrano](http://capistranorb.com)** to deploy your application, and\n* **You have [Rake](http://rake.rubyforge.org) tasks that you want to execute remotely** — but you don’t want to hand-code Capistrano recipes for each Rake task —\n\nThen\n\n* **You can use the [Cape](http://njonsson.github.io/cape) DSL** within Capistrano recipes to dynamically add recipes for your application’s Rake tasks, and\n* **You can execute your Rake tasks on your deployed servers,** friction-free, and look like a superhero. _[cue fanfare]_\n\n## Features\n\n* **Mirror Rake tasks** as Capistrano recipes, optionally filtered by namespace or name\n* **Embed Rake tasks** in Capistrano namespaces\n* **Pass arguments** to Rake tasks by setting environment variables with the same names\n* **Specify the Rake executable** for local and remote Rake installations\n* **Enumerate Rake tasks** for your own purposes\n\nSee what’s changed lately by reading the [project history](http://github.com/njonsson/cape/blob/master/History.markdown).\n\n## Installation — get your Cape on\n\nInstall [the RubyGem](http://rubygems.org/gems/cape \"Cape at RubyGems.org\").\n\n    $ gem install cape\n\nOr you may want to make Cape a dependency of your project by using [Bundler](http://gembundler.com).\n\n    # Gemfile\n\n    source 'http://rubygems.org'\n\n    gem 'cape', '~\u003e 1'\n\n## Compatibility\n\nCape [runs](http://travis-ci.org/njonsson/cape) on the following Ruby versions:\n\n* MRI v1.8.7, v1.9.2, v1.9.3, v2.0.0\n* REE v1.8.7\n\nCape integrates with the following RubyGems:\n\n* Capistrano v2.x\n* Rake v0.8.7 and later\n\n**A Rake task that lacks a description can be mirrored or enumerated only if Rake v0.9.3 or newer is installed.** Older versions of Rake did not support enumerating such tasks. You may want to make Rake v0.9.3 a dependency of your project.\n\n    # Gemfile\n\n    source 'http://rubygems.org'\n\n    gem 'rake', '\u003e= 0.9.3'\n\n## Examples\n\nAssume the following Rake tasks are defined.\n\n    desc 'Rakes the leaves'\n    task :leaves do\n      $stdout.puts \"Raking the leaves\"\n    end\n\n    desc 'Rakes and bags the leaves'\n    task :bag_leaves, [:paper_or_plastic] =\u003e :leaves do |task, arguments|\n      $stdout.puts \"Putting the leaves in a #{arguments[:paper_or_plastic]} bag\"\n    end\n\nRake lists these tasks in the expected fashion.\n\n    $ rake --tasks\n    rake bag_leaves[paper_or_plastic]  # Rakes and bags the leaves\n    rake leaves                        # Rakes the leaves\n\n    $ rake --describe bag_leaves\n    rake bag_leaves[paper_or_plastic]\n        Rakes and bags the leaves\n\n### Simply mirror all Rake tasks as Capistrano recipes\n\nAdd the following to your Capistrano recipes. Note that Cape statements must be contained in a `Cape` block.\n\n    # config/deploy.rb\n\n    require 'cape'\n\n    Cape do\n      # Create Capistrano recipes for all Rake tasks.\n      mirror_rake_tasks\n    end\n\nNow all your Rake tasks appear alongside your Capistrano recipes.\n\n    $ cap --tasks\n    cap deploy               # Deploys your project.\n    ...\n    [other built-in Capistrano recipes]\n    ...\n    cap bag_leaves           # Rakes and bags the leaves.\n    cap leaves               # Rakes the leaves.\n    Some tasks were not listed, either because they have no description,\n    or because they are only used internally by other tasks. To see all\n    tasks, type `cap -vT'.\n\n    Extended help may be available for these tasks.\n    Type `cap -e taskname' to view it.\n\nLet’s use Capistrano to view the unabbreviated description of a Rake task recipe, including instructions for how to pass arguments to it. Note that Rake task parameters are automatically converted to environment variables.\n\n    $ cap --explain bag_leaves\n    ------------------------------------------------------------\n    cap bag_leaves\n    ------------------------------------------------------------\n    Bags the leaves.\n\n    Set environment variable PAPER_OR_PLASTIC if you want to pass a Rake task argument.\n\nHere’s how to invoke a task/recipe with arguments. On the local computer, via Rake:\n\n    $ rake bag_leaves[plastic]\n    (in /current/working/directory)\n    Raking the leaves\n    Putting the leaves in a plastic bag\n\nOn remote computers, via Capistrano:\n\n    $ cap bag_leaves PAPER_OR_PLASTIC=plastic\n      * executing `bag_leaves'\n      * executing \"cd /path/to/currently/deployed/version/of/your/app \u0026\u0026 /usr/bin/env `/usr/bin/env bundle check \u003e/dev/null 2\u003e\u00261; case $? in 0|1 ) echo bundle exec ;; esac` rake bag_leaves[plastic]\"\n        servers: [\"your.server.name\"]\n        [your.server.name] executing command\n     ** [out :: your.server.name] (in /path/to/currently/deployed/version/of/your/app)\n     ** [out :: your.server.name] Raking the leaves\n     ** [out :: your.server.name] Putting the leaves in a plastic bag\n        command finished in 1000ms\n\n### Mirror some Rake tasks, but not others\n\nCape lets you filter the Rake tasks to be mirrored. Note that Cape statements must be contained in a `Cape` block.\n\n    # config/deploy.rb\n\n    require 'cape'\n\n    Cape do\n      # Create Capistrano recipes for the Rake task 'foo' and/or for the tasks in\n      # the 'foo' namespace.\n      mirror_rake_tasks :foo\n    end\n\n### Mirror Rake tasks that require renaming, Capistrano recipe options, path switching, and/or environment variables\n\nCape lets you customize mirrored Rake tasks to suit your needs. Note that Cape statements must be contained in a `Cape` block, and references to Capistrano variables such as `rails_env` and `release_path` must be contained in an inner block, lambda, or other callable object.\n\n    # config/deploy.rb\n\n    require 'cape'\n\n    Cape do\n      # Display defined Rails routes on application server remote machines only.\n      mirror_rake_tasks :routes do |recipes|\n        recipes.options[:roles] = :app\n      end\n\n      # Execute database migration on application server remote machines only,\n      # and set the 'RAILS_ENV' environment variable to the value of the\n      # Capistrano variable 'rails_env'.\n      mirror_rake_tasks 'db:migrate' do |recipes|\n        recipes.options[:roles] = :app\n        recipes.env['RAILS_ENV'] = lambda { rails_env }\n      end\n\n      # Support a Rake task that must be run on application server remote\n      # machines only, and in the remote directory 'release_path' instead of the\n      # default, 'current_path'.\n      before 'deploy:symlink', :spec\n      mirror_rake_tasks :spec do |recipes|\n        recipes.cd { release_path }\n        recipes.options[:roles] = :app\n      end\n\n      # Avoid collisions with the existing Ruby method #test, run tests on\n      # application server remote machines only, and set the 'RAILS_ENV'\n      # environment variable to the value of the Capistrano variable\n      # 'rails_env'.\n      mirror_rake_tasks :test do |recipes|\n        recipes.rename do |rake_task_name|\n          \"#{rake_task_name}_task\"\n        end\n        recipes.options[:roles] = :app\n        recipes.env['RAILS_ENV'] = lambda { rails_env }\n      end\n    end\n\nThe above is equivalent to the following manually-defined Capistrano recipes.\n\n    # config/deploy.rb\n\n    # These translations to Capistrano are just for illustration.\n\n    RAKE = '/usr/bin/env '                                +\n           '`'                                            +\n            '/usr/bin/env bundle check \u003e/dev/null 2\u003e\u00261; ' +\n            'case $? in '                                 +\n               # Exit code 0: bundle is defined and installed\n               # Exit code 1: bundle is defined but not installed\n              '0|1 ) '                                    +\n                'echo bundle exec '                       +\n                ';; '                                     +\n            'esac'                                        +\n           '` '                                           +\n           'rake'\n\n    task :routes, :roles =\u003e :app do\n      run \"cd #{current_path} \u0026\u0026 #{RAKE} routes\"\n    end\n\n    namespace :db do\n      task :migrate, :roles =\u003e :app do\n        run \"cd #{current_path} \u0026\u0026 #{RAKE} db:migrate RAILS_ENV=#{rails_env}\"\n      end\n    end\n\n    before 'deploy:symlink', :spec\n    task :spec, :roles =\u003e :app do\n      run \"cd #{release_path} \u0026\u0026 #{RAKE} routes\"\n    end\n\n    task :test_task, :roles =\u003e :app do\n      run \"cd #{current_path} \u0026\u0026 #{RAKE} test RAILS_ENV=#{rails_env}\"\n    end\n\n### Mirror Rake tasks into a Capistrano namespace\n\nCape plays friendly with the Capistrano DSL for organizing Rake tasks in Capistrano namespaces. Note that Cape statements must be contained in a `Cape` block.\n\n    # config/deploy.rb\n\n    require 'cape'\n\n    namespace :rake_tasks do\n      # Use an argument with the Cape block, if you want to or need to.\n      Cape do |cape|\n        cape.mirror_rake_tasks\n      end\n    end\n\n### Iterate over available Rake tasks\n\nCape lets you enumerate Rake tasks, optionally filtering them by task name or namespace. Note that Cape statements must be contained in a `Cape` block.\n\n    # config/deploy.rb\n\n    require 'cape'\n\n    Cape do\n      # Enumerate all Rake tasks.\n      each_rake_task do |t|\n        # Do something interesting with this hash:\n        # * t[:name] -- the full name of the task\n        # * t[:parameters] -- the names of task arguments\n        # * t[:description] -- documentation on the task, including parameters\n      end\n\n      # Enumerate the Rake task 'foo' and/or the tasks in the 'foo' namespace.\n      each_rake_task 'foo' do |t|\n        # ...\n      end\n    end\n\n### Configure Rake execution\n\nCape lets you specify how Rake should be run on the local computer and on remote computers. But the default behavior is most likely just right for your needs:\n\n* It detects whether Bundler is installed on the computer\n* It detects whether the project uses Bundler to manage its dependencies\n* It runs Rake via Bundler if the above conditions are true; otherwise, it runs Rake directly\n\nNote that Cape statements must be contained in a `Cape` block.\n\n    # config/deploy.rb\n\n    require 'cape'\n\n    # Configure Cape never to run Rake via Bundler, neither locally nor remotely.\n    Cape.local_rake_executable  = '/usr/bin/env rake'\n    Cape.remote_rake_executable = '/usr/bin/env rake'\n\n    Cape do\n      # Create Capistrano recipes for all Rake tasks.\n      mirror_rake_tasks\n    end\n\n## Contributing\n\nReport defects and feature requests on [GitHub Issues](http://github.com/njonsson/cape/issues).\n\nYour patches are welcome, and you will receive attribution here for good stuff.\n\n## License\n\nReleased under the [MIT License](http://github.com/njonsson/cape/blob/master/License.markdown).\n\n[Travis CI build status]: https://secure.travis-ci.org/njonsson/cape.png?branch=master\n[Gemnasium build status]: https://gemnasium.com/njonsson/cape.png\n[Code Climate report]:    https://codeclimate.com/github/njonsson/cape.png\n[Inline docs]:            http://inch-pages.github.io/github/njonsson/cape.png\n[RubyGems release]:       https://badge.fury.io/rb/cape.png\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnjonsson%2Fcape","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnjonsson%2Fcape","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnjonsson%2Fcape/lists"}