Shared utilities for managing and deploying OpsWorks apps at Artsy.
Add this line to your application's Gemfile, probably in the :development
group:
gem 'momentum', require: false
In your application's Rakefile, add this line above the load_tasks
command:
begin
require 'momentum' # necessary b/c tasks from gems in :development group aren't loaded automatically
Momentum.configure do |conf|
conf[:app_base_name] = 'your_app_name'
end
rescue LoadError
# momentum should only be installed in development
end
And then execute:
$ bundle
$ gem install librarian-chef # ideally this would be in the bundle, but has conflicts
$ bundle exec rake momentum:init
It's assumed that stacks are named with an app name and modifier, such as todo-production. The modifier is usually an environment, but might also be a developer name or some other label, such todo-joey.
This gem adds a few useful rake tasks to your project. By default, the aws_id
and aws_secret
arguments are taken from AWS_ID
and AWS_SECRET
ENV variables. The to
argument refers to the modifier mentioned above (e.g., production). It's appended to the configured app_base_name
to form the stack name.
Initialize a default librarian-chef config.
Print the custom configuration values for the given stack. E.g.:
bundle exec rake ow:config[joey]
Add the given stack's custom configuration values to the current task's ENV. Can be prepended to other rake tasks that depend on the ENV, e.g.:
bundle exec rake ow:config:from_env[production] some:migration
Start a rails console on the given remote OpsWorks stack. Chooses an instance of the rails-app layer by default, or the configured rails_console_layer
if provided. E.g.:
bundle exec rake ow:console[production]
For stacks with labels not matching the Rails environment (e.g., reflection-joey), provide a 2nd argument with the desired environment:
bundle exec rake ow:console[joey,staging]
Zip, upload, and propagate custom cookbooks to the given stack. Or, more concisely:
bundle exec rake ow:cookbooks:update[staging]
# or just:
bundle exec rake ow:cookbooks:update:staging
Trigger an OpsWorks deploy to the given stack. By default, deploys app to all running instances of the rails-app layer, or the list configured in app_layers
. E.g.:
bundle exec rake ow:deploy[staging]
# or just:
bundle exec rake ow:deploy:staging
# if you want to trigger database migrations at the same time, add the additional flag
bundle exec rake ow:deploy:migrations[staging]
Execute a tail -f (follow) command against a remote log path on the given remote OpsWorks instance and stack. The path may include wildcards. E.g.:
bundle exec rake ow:logs[staging,rails-app1,/srv/www/myapp/shared/log/staging.log]
SSH to an OpsWorks instance. If the layer_or_instance
argument is a layer, an online instance is chosen randomly from the layer. Otherwise, the name of an online instance is expected. E.g.:
bundle exec rake ow:ssh[staging,memcached]
# or...
bundle exec rake ow:ssh[staging,rails-app1]
- app_base_name - Your app's name. Stacks are assumed to be named like appbasename-env (e.g., gravity-staging or reflection-joey).
- app_layers - Array of OpsWorks layer names to which this rails app should be deployed. Default:
['rails-app']
- cookbooks_install_path - Local path where librarian-chef will install cookbooks. Default: tmp/cookbooks
- custom_cookbooks_bucket - Bucket to which custom cookbooks are uploaded. Default: artsy-cookbooks
- rails_console_layer - The OpsWorks layer used for SSH-ing and starting a rails console. Default: rails-app
- git/branch helpers
- Integrate librarian-chef as legit dependency once rails/chef conflicts resolved
- Tests