{"id":13747434,"url":"https://github.com/mattbrictson/capistrano-mb","last_synced_at":"2025-05-09T08:32:46.538Z","repository":{"id":10193492,"uuid":"12283992","full_name":"mattbrictson/capistrano-mb","owner":"mattbrictson","description":"[unmaintained] Capistrano tasks for deploying Rails from scratch to Ubuntu 16.04 and 18.04","archived":true,"fork":false,"pushed_at":"2019-11-09T17:14:56.000Z","size":289,"stargazers_count":118,"open_issues_count":1,"forks_count":24,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-05-18T20:48:03.171Z","etag":null,"topics":["capistrano","devops","rails","ruby","systemd","ubuntu","unmaintained","vps"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mattbrictson.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-08-21T23:41:45.000Z","updated_at":"2024-02-20T05:47:47.000Z","dependencies_parsed_at":"2022-09-13T02:40:25.737Z","dependency_job_id":null,"html_url":"https://github.com/mattbrictson/capistrano-mb","commit_stats":null,"previous_names":[],"tags_count":39,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattbrictson%2Fcapistrano-mb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattbrictson%2Fcapistrano-mb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattbrictson%2Fcapistrano-mb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattbrictson%2Fcapistrano-mb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mattbrictson","download_url":"https://codeload.github.com/mattbrictson/capistrano-mb/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224732051,"owners_count":17360417,"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":["capistrano","devops","rails","ruby","systemd","ubuntu","unmaintained","vps"],"created_at":"2024-08-03T06:01:28.751Z","updated_at":"2024-11-15T20:31:45.565Z","avatar_url":"https://github.com/mattbrictson.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"⚠️ **This project is no longer maintained.** Thanks for your interest in capistrano-mb. I don't use this gem anymore and so I've chosen not to support it going forward. However, many of the lessons I've learned from building capistrano-mb I am now applying to a new project called [tomo](https://github.com/mattbrictson/tomo). Hope to see you there!\n\n---\n\n# capistrano-mb\n\n**An opinionated Capistrano task library for deploying Rails apps from scratch on Ubuntu 16.04 or 18.04 LTS.**\n\n[![Gem Version](https://badge.fury.io/rb/capistrano-mb.svg)](https://rubygems.org/gems/capistrano-mb)\n\nCapistrano is great for deploying Rails applications, but what about all the prerequisites, like Nginx and PostgreSQL? Do you have a firewall configured on your VPS? Have you installed the latest OS security updates? Is HTTPS working right?\n\nThe capistrano-mb gem adds a `cap \u003cstage\u003e provision` task to Capistrano that takes care of all that. Out of the box, `provision` will:\n\n* Install the latest `postgresql`, `node.js`, and `nginx` apt packages\n* Install all libraries needed to build Ruby\n* Lock down your VPS using `ufw` (a simple front-end to iptables)\n* Set up `logrotated` for your Rails logs\n* Schedule an automatic daily backup of your Rails database\n* Generate a self-signed SSL certificate if you need one\n* Set up ngnix with the latest SSL practices and integrate it with Unicorn for your Rails app\n* Create the `deployer` user and install an SSH public key\n* Install `rbenv` and use `ruby-build` to compile the version of Ruby required by your app (by inspecting your `.ruby-version` file)\n* And more!\n\nThe gem is named \"capistrano-mb\" because it is prescribes my ([@mattbrictson](https://github.com/mattbrictson)) personal preferences for automating deployments of Rails projects. I've worked several years as a freelance developer juggling lots of Rails codebases, so its important for me to have a good, consistent server configuration. You'll notice that capistrano-mb is opinionated and strictly uses the following stack:\n\n* Ubuntu 16.04 or 18.04 LTS\n* PostgreSQL\n* Unicorn\n* Nginx\n* rbenv\n* dotenv\n\nIn addition, capistrano-mb changes many of Capistrano's defaults, including the deployment location, Bundler behavior, and SSH keep-alive settings. (See [defaults.rake][] for details.)\n\nNot quite to your liking? Consider forking the project to meet your needs.\n\n## Roadmap\n\nI plan to continue maintaining this project for the benefit of deploying my own Rails apps for the foreseeable future. In practice, this means a new version or two per year. The behavior of capistrano-mb may change as I upgrade my apps to new versions of Rails. For example, at some point I might:\n\n* Replace Unicorn with Puma\n* Switch from dotenv to encrypted credentials\n* Add Let's Encrypt\n* Use a more robust database backup solution\n\n*Future changes in capistrano-mb are not guaranteed to have graceful migration paths, so I recommend pinning your Gemfile dependency to a specific version and upgrading with extreme care.*\n\n## Quick start\n\nPlease note that this project requires **Capistrano 3.x**, which is a complete rewrite of Capistrano 2.x. The two major versions are not compatible.\n\n### 1. Purchase an Ubuntu 16.04 or 18.04 VPS\n\nTo use capistrano-mb, you'll need a clean **Ubuntu 16.04 or 18.04** server to deploy to. The only special requirement is that your public SSH key must be installed on the server for the `root` user.\n\nTest that you can SSH to the server as `root` without being prompted for a password. If that works, capistrano-mb can take care of the rest. You're ready to proceed!\n\n### 2. .ruby-version\n\ncapistrano-mb needs to know the version of Ruby that your app requires, so that it can install Ruby during the provisioning process. Place a `.ruby-version` file in the root of your project containing the desired version, like this:\n\n```\n2.5.0\n```\n\n*If you are using `rbenv`, just run `rbenv local 2.5.0` and it will create this file for you.*\n\n### 3. Gemfile\n\ncapistrano-mb makes certain assumptions about your Rails app, namely that it uses [dotenv][] to manage Rails secrets via environment variables, and that it runs on top of PostgreSQL and [unicorn][]. Make sure they are specified in the Gemfile:\n\n```ruby\ngem \"dotenv-rails\", \"\u003e= 2.0.0\"\ngem \"pg\", \"~\u003e 0.18\"\ngem \"unicorn\"\n```\n\nThen for the capistrano-mb tools themselves, add these gems to the development group:\n\n```ruby\ngroup :development do\n  gem \"capistrano-bundler\", :require =\u003e false\n  gem \"capistrano-rails\", :require =\u003e false\n  gem \"capistrano\", \"~\u003e 3.10\", :require =\u003e false\n  gem \"capistrano-mb\", \"~\u003e 0.35.0\", :require =\u003e false\nend\n```\n\nAnd then execute:\n\n```\n$ bundle install\n```\n\n### 4. cap install\n\nIf your project doesn't yet have a `Capfile`, run `cap install` with the list of desired stages (environments). For simplicity, this installation guide will assume a single production stage:\n\n```\nbundle exec cap install STAGES=production\n```\n\n### 5. Capfile\n\nAdd these lines to the **bottom** of your app's `Capfile` (order is important!):\n\n```ruby\nrequire \"capistrano/bundler\"\nrequire \"capistrano/rails\"\nrequire \"capistrano/mb\"\n```\n\n### 6. deploy.rb\n\nModify `config/deploy.rb` to set the specifics of your Rails app. At the minimum, you'll need to set these two options:\n\n```ruby\nset :application, \"my_app_name\"\nset :repo_url, \"git@github.com:username/repository.git\"\n```\n\n### 7. production.rb\n\nModify `config/deploy/production.rb` to specify the IP address of your production server. In this example, I have a single 1GB VPS (e.g. at DigitalOcean) that plays all the roles:\n\n```ruby\nserver \"my.production.ip\",\n       :user =\u003e \"deployer\",\n       :roles =\u003e %w[app backup cron db web]\n```\n\n*Note that you must include the `backup` and `cron` roles if you want to make use of capistrano-mb's database backups and crontab features.*\n\n### 8. secrets.yml\n\nYour Rails apps may have a `config/secrets.yml` file that specifies the Rails secret key. capistrano-mb configures dotenv to provide this secret in a `RAILS_SECRET_KEY_BASE` environment variable. You'll therefore need to modify `secrets.yml` as follows:\n\n```ruby\nproduction:\n  secret_key_base: \u003c%= ENV[\"RAILS_SECRET_KEY_BASE\"] %\u003e\n```\n\n### 9. Provision and deploy!\n\nRun capistrano-mb's `provision` task. This will ask you a few questions, install Ruby, PostgreSQL, Nginx, etc., and set everything up. The entire process takes about 10 minutes (mostly due to compiling Ruby from source).\n\n```\nbundle exec cap production provision\n```\n\nOnce that's done, your app is now ready to deploy!\n\n```\nbundle exec cap production deploy\n```\n\n## Advanced usage\n\n### Choosing which recipes to auto-run\n\nMost of the capistrano-mb recipes are designed to run automatically as part of `cap \u003cstage\u003e provision`, for installing and setting up various bits of the Rails infrastructure, like nginx, unicorn, and postgres. Some recipes also contribute to the `cap \u003cstage\u003e deploy` process.\n\n*This auto-run behavior is fully under your control.*  In your `deploy.rb`, set `:mb_recipes` to an array of the desired recipes. If you don't want a recipe to execute as part of `deploy`/`provision`, simply omit it from the list.\n\nThe following list will suffice for most out-of-the-box Rails apps. The order of the list is not important.\n\n```ruby\nset :mb_recipes, %w[\n  aptitude\n  bundler\n  crontab\n  dotenv\n  logrotate\n  migrate\n  nginx\n  postgresql\n  rbenv\n  seed\n  ssl\n  ufw\n  unicorn\n  user\n  version\n]\n```\n\nEven if you don't include a recipe in the auto-run list, you can still invoke the tasks of those recipes manually at your discretion. Run `bundle exec cap -T` to see the full list of tasks.\n\n### Configuration\n\nMany of the recipes have default settings that can be overridden. Use your\n`deploy.rb` file to specify these overrides. Or, you can override per stage.\nHere is an example override:\n\n    set :mb_unicorn_workers, 8\n\nFor the full list of settings and their default values, refer to [defaults.rake][].\n\n\n## Further reading\n\nCheck out my [rails-template][] project, which generates Rails applications with capistrano-mb pre-configured and ready to go.\n\n\n## History\n\nThis gem used to be called `capistrano-fiftyfive`. If you are upgrading from capistrano-fiftyfive, refer to the [CHANGELOG entry for v0.22.0](CHANGELOG.md#0220-2015-06-22) for migration instructions.\n\nAs of 0.33.0, capistrano-mb no longer supports Ubuntu 12.04 or 14.04. If your server runs one of these older versions, use [capistrano-mb 0.32.0](https://github.com/mattbrictson/capistrano-mb/tree/v0.32.0).\n\n## Contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n\n\n[Postmark]:https://postmarkapp.com\n[cast337]:http://railscasts.com/episodes/337-capistrano-recipes\n[cast373]:http://railscasts.com/episodes/373-zero-downtime-deployment\n[defaults.rake]:lib/capistrano/tasks/defaults.rake\n[rails-template]:https://github.com/mattbrictson/rails-template/\n[dotenv]:https://github.com/bkeepers/dotenv\n[unicorn]:http://unicorn.bogomips.org/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattbrictson%2Fcapistrano-mb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmattbrictson%2Fcapistrano-mb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattbrictson%2Fcapistrano-mb/lists"}