Skip to content
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

Labs #153

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Labs #153

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ A full list of tasks provided:
rake heroku:deploy:after # Callback after deploys
rake heroku:deploy:before # Callback before deploys
rake heroku:deploy:force[commit] # Force-pushes the given commit, migrates and restarts (default: HEAD)
rake heroku:features # Install features (labs) for the application.
rake heroku:features:local # List configured features (labs), without installing them
rake heroku:logs # Shows the Heroku logs
rake heroku:logs:tail # Tail the Heroku logs (requires logging:expanded)
rake heroku:maintenance # Enable maintenance mode
Expand Down
44 changes: 30 additions & 14 deletions lib/heroku_san/stage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,49 +17,53 @@ def initialize(stage, options = {})
def ==(other)
other.name == name && other.options == options
end

def heroku
@heroku ||= HerokuSan::API.new(:api_key => auth_token, :mock => MOCK)
end

def app
@options['app'] or raise MissingApp, "#{name}: is missing the app: configuration value. I don't know what to access on Heroku."
end

def repo
@options['repo'] ||= "[email protected]:#{app}.git"
end

def stack
@options['stack'] ||= heroku.get_stack(app).body.detect{|stack| stack['current']}['name']
end

def tag
@options['tag']
end

def config
@options['config'] ||= {}
end

def addons
(@options['addons'] ||= []).flatten
end


def features
(@options['features'] ||= []).flatten
end

def run(command, args = nil)
sh_heroku "run", command, *args
end

def push(sha = nil, force = false)
sha ||= git_parsed_tag(tag)
git_push(sha, repo, force ? %w[--force] : [])
end

def migrate
run('rake db:migrate')
restart
end

def deploy(commit = nil, force = nil)
strategy = @options['deploy'].new(self, commit, force)
strategy.deploy
Expand All @@ -82,7 +86,7 @@ def maintenance(action = nil)
heroku.post_app_maintenance(app, {:on => '1', :off => '0'}[action])
end
end

def create
params = {
'name' => @options['app'],
Expand All @@ -103,7 +107,7 @@ def sharing_remove(email) # DEPREC?
def long_config
heroku.get_config_vars(app).body
end

def push_config(options = nil)
params = (options || config)
heroku.put_config_vars(app, params).body
Expand All @@ -121,18 +125,30 @@ def install_addons
installed_addons
end

def installed_features
heroku.get_features(app).body.select { |feature| feature['enabled'] }
end

def install_features
features_to_install = features - installed_features.map { |l| l['name'] }
features_to_install.each do |feature|
heroku.post_feature(feature, app)
end
installed_features
end

def restart
"restarted" if heroku.post_ps_restart(app).body == 'ok'
end

def logs(tail = false)
sh_heroku 'logs', (tail ? '--tail' : nil)
end

def revision
git_named_rev(git_revision(repo))
end

private

def auth_token
Expand Down
25 changes: 24 additions & 1 deletion lib/heroku_san/tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
each_heroku_app do |stage|
addons = stage.install_addons
puts "#{stage.name} addons"
addons.each do |addon|
addons.each do |addon|
puts " - " + addon['name'] + (addon['configured'] ? "" : " # Configure at https://api.heroku.com/myapps/#{stage.app}/addons/#{addon['name']}")
end
end
Expand All @@ -105,6 +105,29 @@
end
end

desc 'Install features (labs) for the application.'
task :features do
each_heroku_app do |stage|
features = stage.install_features
puts "#{stage.name} features (labs)"
features.each do |feature|
puts " - " + feature['name']
end
end
end

namespace :features do
desc 'List configured features (labs), without installing them'
task :local do
each_heroku_app do |stage|
puts "Configured features (labs) for #{stage.name}:"
stage.features.each do |feature|
puts " - #{feature}"
end
end
end
end

desc 'Creates an example configuration file'
task :create_config do
filename = %Q{#{HerokuSan.project.config_file.to_s}}
Expand Down
2 changes: 2 additions & 0 deletions lib/templates/heroku.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ staging:
- memcache:5mb
- logging:basic
- scheduler:standard
features:
- user-env-compile

demo:
app: awesomeapp-demo
Expand Down
Loading