Negroku

Negroku is an opinionated collection of recipes for capistrano.

The goal is to be able to deploy ruby on rails applications and static websites without the hassle of configuring and defining all the stuff involved in an application deployment.

All the server settings pre-defined in the configuration files generated by negroku are targeted to this server generic configuration guide. Although in most cases you can customize those settings.

Installation

Install negroku as a global gem.

shell $ gem install negroku

Add the negroku gem to your Gemfile development group to lock the version your are going to use.

ruby group :development do gem 'negroku', '1.1.4' end

You will need to add to your Gemfile these two gems:

```ruby group :assets do gem ‘therubyracer’, :platforms => :ruby end

group :production do gem ‘unicorn’ end ```

Then execute

shell $ bundle install

Note: Add the therubyracer gem only if your are going to use the assets precompile of a rails project.

Getting started

  1. Create your app executing the following command, and just follow the on-screen questions.

    $ negroku app create

    ####Give your application a name

    This will be used to create the app folder structure in the server and to name some files, for example, the log files.

    ####Please choose your repository

    You’ll need to choose the git respository where your are going to store your project. Typically a GitHub repository, it can be any repository that the server has access to.

    If you have already initializated your git repository for the project, you’ll be offered to choose the remotes of the current repo.

    ####Target servers

    You’ll need to choose the server address where the project will be deployed and the hostname that will be used by nginx to host the application. Negroku will ask this for two stage servers (staging, production)

    Note: Refer to the negroku config taks to add some default servers to the negroku configuration.

  2. The app create command will bootpstrapp your app (behind the scenes it will run the capistrano command capify . and add some customizations)

    Some files and folders will be added to your project, this is the same structure that capistrano expects when using multistage extensions

    project_root |--- Capfile # Capistrano load file +--- config |--- deploy.rb # Global setting for all environments +--- deploy |--- production.rb # Specific settings for production server +--- staging.rb # Specific settings for staging server

  3. Configure your specific settings in the files created above

    ####Common settings for all stages deploy.rb

    Here you can add all the settings that are common to all the stage severs.

    ruby #You may want to change the stages and the default stage set :stages, %w(production staging) set :default_stage, "staging"

    ####Per-stage settings staging.rb production.rb

    Here you can add all the settings that are specific to the stage.

    ruby #You may want to change the repository branch for each stage. set :branch, "production" # Optional, defaults to master

  4. Prepare the server for your application executing

    shell $ cap deploy:setup

  5. Commit and push the changes to the repository

  6. Configure all your environmental variables for your project using the negroku env taks

  7. Deploy you application for the first time executing

    shell $ cap deploy:cold # for the default stage $ cap production deploy:cold # for the production stage

    For all the next following deploys, you should execute

    shell $ cap deploy # for the default stage $ cap production deploy # for the production stage

The CLI

Negroku also provides a simple CLI that helps to initialize the deployment of your project and that wraps some tasks from its recipes collection.

App task

comming soon…

Env task

comming soon…

Config task

comming soon…

Included recipes

To achieve this goal negroku provides a set of pre-configured capistrano recipes and deploy configuration files in order to streamline the process to deploy a new application.

nginx tasks

cap nginx:reload # reload Nginx. cap nginx:restart # restart Nginx. cap nginx:setup # Setup nginx configuration for this applic... cap nginx:start # start Nginx. cap nginx:stop # stop Nginx. cap nginx:upload_ssl_certificates # Upload SSL certificates for this applicat...

unicorn tasks

cap unicorn:add_worker # Add a new worker cap unicorn:duplicate # Duplicate Unicorn cap unicorn:reload # Reload Unicorn cap unicorn:remove_worker # Remove amount of workers cap unicorn:restart # Restart Unicorn cap unicorn:setup # Setup unicorn configuration for this appl... cap unicorn:shutdown # Immediately shutdown Unicorn cap unicorn:start # Start Unicorn master process cap unicorn:stop # Stop Unicorn

logging tasks

cap log:app # Stream (tail) the application's productio... cap log:nginx_access # Stream (tail) the nginx access log. cap log:nginx_error # Stream (tail) the nginx error log. cap log:unicorn_error # Stream (tail) the unicorn error log.

rbenv task

cap rbenv:vars:add # Add rbenv vars cap rbenv:vars:show # Show current rbenv vars cap rbenv:vars:symlink # Symlink rbenv-vars file into the current ...

Customizing the recipes

Aside of predefining some ways of doing the deployments, negroku is very flexible. This flexibility is inherited from capistrano, so you can extend negroku with your recipes, overide existing ones, and modify every configuration you want.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request