make the bushido installation process the smoothest
This commit is contained in:
parent
2ce1fadf52
commit
ef7ac0e721
1
.gitignore
vendored
1
.gitignore
vendored
@ -31,3 +31,4 @@ perf/*.rb
|
|||||||
gem_graph.png
|
gem_graph.png
|
||||||
sites/
|
sites/
|
||||||
permanent
|
permanent
|
||||||
|
doc/bushido
|
||||||
|
2
Gemfile
2
Gemfile
@ -40,12 +40,12 @@ gem 'SystemTimer', :platforms => :ruby_18
|
|||||||
group :development do
|
group :development do
|
||||||
# Using unicorn_rails instead of webrick (default server)
|
# Using unicorn_rails instead of webrick (default server)
|
||||||
gem 'unicorn'
|
gem 'unicorn'
|
||||||
gem 'bushido_stub', :path => '../gems/bushido_stub'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
group :test, :development do
|
group :test, :development do
|
||||||
gem 'ruby-debug', :platforms => :mri_18
|
gem 'ruby-debug', :platforms => :mri_18
|
||||||
gem 'ruby-debug19', :platforms => :mri_19
|
gem 'ruby-debug19', :platforms => :mri_19
|
||||||
|
gem 'bushido_stub', :path => '../gems/bushido_stub'
|
||||||
end
|
end
|
||||||
|
|
||||||
group :production do
|
group :production do
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
GIT
|
GIT
|
||||||
remote: git://github.com/floehopper/mocha.git
|
remote: git://github.com/floehopper/mocha.git
|
||||||
revision: adeb8ae0189963cf3024f2b37d5348a7feaae11e
|
revision: 6da1242f26b12a24c4fcf67bf5921a25bc1bc88d
|
||||||
specs:
|
specs:
|
||||||
mocha (0.9.12.20110213002255)
|
mocha (0.9.12.20110213002255)
|
||||||
|
|
||||||
@ -15,7 +15,6 @@ PATH
|
|||||||
remote: ../gems/bushido_stub
|
remote: ../gems/bushido_stub
|
||||||
specs:
|
specs:
|
||||||
bushido_stub (0.0.1)
|
bushido_stub (0.0.1)
|
||||||
activesupport
|
|
||||||
|
|
||||||
GEM
|
GEM
|
||||||
remote: http://rubygems.org/
|
remote: http://rubygems.org/
|
||||||
@ -64,7 +63,7 @@ GEM
|
|||||||
bson (1.3.1)
|
bson (1.3.1)
|
||||||
bson_ext (1.3.1)
|
bson_ext (1.3.1)
|
||||||
builder (2.1.2)
|
builder (2.1.2)
|
||||||
bushido (0.0.12)
|
bushido (0.0.14)
|
||||||
highline (>= 1.6.1)
|
highline (>= 1.6.1)
|
||||||
json (>= 1.4.6)
|
json (>= 1.4.6)
|
||||||
rest-client (>= 1.6.1)
|
rest-client (>= 1.6.1)
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
require 'bushido'
|
require 'bushido'
|
||||||
require 'locomotive/hosting/bushido/custom_domain'
|
require 'locomotive/hosting/bushido/custom_domain'
|
||||||
require 'locomotive/hosting/bushido/first_installation'
|
require 'locomotive/hosting/bushido/first_installation'
|
||||||
|
require 'locomotive/hosting/bushido/account_ext'
|
||||||
|
require 'locomotive/hosting/bushido/middleware'
|
||||||
|
|
||||||
module Locomotive
|
module Locomotive
|
||||||
module Hosting
|
module Hosting
|
||||||
@ -29,7 +31,9 @@ module Locomotive
|
|||||||
|
|
||||||
self.setup_smtp_settings
|
self.setup_smtp_settings
|
||||||
|
|
||||||
self.config.delayed_job = false #true # force the use of delayed_job
|
self.add_middleware
|
||||||
|
|
||||||
|
self.config.delayed_job = true # force the use of delayed_job
|
||||||
|
|
||||||
self.bushido_domains = ::Bushido::App.domains
|
self.bushido_domains = ::Bushido::App.domains
|
||||||
self.bushido_subdomain = ::Bushido::App.subdomain
|
self.bushido_subdomain = ::Bushido::App.subdomain
|
||||||
@ -38,6 +42,7 @@ module Locomotive
|
|||||||
def enhance_site_model_with_bushido
|
def enhance_site_model_with_bushido
|
||||||
Site.send :include, Locomotive::Hosting::Bushido::CustomDomain
|
Site.send :include, Locomotive::Hosting::Bushido::CustomDomain
|
||||||
Site.send :include, Locomotive::Hosting::Bushido::FirstInstallation
|
Site.send :include, Locomotive::Hosting::Bushido::FirstInstallation
|
||||||
|
Account.send :include, Locomotive::Hosting::Bushido::AccountExt
|
||||||
end
|
end
|
||||||
|
|
||||||
def setup_smtp_settings
|
def setup_smtp_settings
|
||||||
@ -53,6 +58,12 @@ module Locomotive
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def add_middleware
|
||||||
|
::Locomotive::Application.configure do |config|
|
||||||
|
config.middleware.use '::Locomotive::Hosting::Bushido::Middleware'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# manage domains
|
# manage domains
|
||||||
|
|
||||||
def add_bushido_domain(name)
|
def add_bushido_domain(name)
|
||||||
|
19
lib/locomotive/hosting/bushido/account_ext.rb
Normal file
19
lib/locomotive/hosting/bushido/account_ext.rb
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
module Locomotive
|
||||||
|
module Hosting
|
||||||
|
module Bushido
|
||||||
|
|
||||||
|
module AccountExt
|
||||||
|
|
||||||
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
|
included do
|
||||||
|
|
||||||
|
field :bushido_user_id, :type => Integer
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
51
lib/locomotive/hosting/bushido/middleware.rb
Normal file
51
lib/locomotive/hosting/bushido/middleware.rb
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
require 'rack/utils'
|
||||||
|
|
||||||
|
module Locomotive
|
||||||
|
module Hosting
|
||||||
|
module Bushido
|
||||||
|
class Middleware
|
||||||
|
|
||||||
|
BUSHIDO_JS_URL = 'http://localhost:4567/javascripts/bushido.js'
|
||||||
|
|
||||||
|
include Rack::Utils
|
||||||
|
|
||||||
|
def initialize(app, opts = {})
|
||||||
|
@app = app
|
||||||
|
@bushido_app_name = ENV['BUSHIDO_APP']
|
||||||
|
@bushido_claimed = ENV['BUSHIDO_CLAIMED'] && ENV['BUSHIDO_CLAIMED'].to_s.downcase == 'true'
|
||||||
|
end
|
||||||
|
|
||||||
|
def call(env)
|
||||||
|
status, headers, response = @app.call(env)
|
||||||
|
|
||||||
|
if env["PATH_INFO"] =~ /^\/admin\//
|
||||||
|
content = ""
|
||||||
|
response.each { |part| content += part }
|
||||||
|
|
||||||
|
# "claiming" bar + stats ?
|
||||||
|
content.gsub!(/<\/body>/i, <<-STR
|
||||||
|
<script type="text/javascript">
|
||||||
|
var _bushido_app = '#{@bushido_app_name}';
|
||||||
|
var _bushido_claimed = #{@bushido_claimed.to_s};
|
||||||
|
(function() {
|
||||||
|
var bushido = document.createElement('script'); bushido.type = 'text/javascript'; bushido.async = true;
|
||||||
|
bushido.src = '#{BUSHIDO_JS_URL}';
|
||||||
|
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(bushido, s);
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
STR
|
||||||
|
)
|
||||||
|
|
||||||
|
headers['content-length'] = bytesize(content).to_s
|
||||||
|
|
||||||
|
[status, headers, [content]]
|
||||||
|
else
|
||||||
|
[status, headers, response]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -5,14 +5,17 @@ require 'net/http'
|
|||||||
namespace :bushido do
|
namespace :bushido do
|
||||||
desc "Prepare an app to run on the Bushido hosting platform, only called during the initial installation. Called just before booting the app."
|
desc "Prepare an app to run on the Bushido hosting platform, only called during the initial installation. Called just before booting the app."
|
||||||
task :install => :environment do
|
task :install => :environment do
|
||||||
|
|
||||||
|
# re-built assets
|
||||||
Jammit.package!
|
Jammit.package!
|
||||||
|
|
||||||
if ENV['BUSHIDO_USER_EMAIL'] && ENV['BUSHIDO_USER_ID']
|
if ENV['BUSHIDO_USER_EMAIL'] && ENV['BUSHIDO_USER_ID']
|
||||||
# already logged in in Bushido
|
# already logged in in Bushido
|
||||||
account = Account.create!({
|
account = Account.create!({
|
||||||
:email => ENV['BUSHIDO_USER_EMAIL'],
|
:email => ENV['BUSHIDO_USER_EMAIL'],
|
||||||
:name => ENV['BUSHIDO_USER_NAME'] || ENV['BUSHIDO_USER_EMAIL'].split('@').first,
|
:name => ENV['BUSHIDO_USER_NAME'] || ENV['BUSHIDO_USER_EMAIL'].split('@').first,
|
||||||
:password => ActiveSupport::SecureRandom.base64(6)
|
:bushido_user_id => ENV['BUSHIDO_USER_ID'],
|
||||||
|
:password => ActiveSupport::SecureRandom.base64(6)
|
||||||
})
|
})
|
||||||
else
|
else
|
||||||
# create an anonymous account right away
|
# create an anonymous account right away
|
||||||
@ -44,14 +47,40 @@ namespace :bushido do
|
|||||||
when Net::HTTPSuccess, Net::HTTPFound
|
when Net::HTTPSuccess, Net::HTTPFound
|
||||||
`curl -L -s -o #{template_local_path} #{template_url}`
|
`curl -L -s -o #{template_local_path} #{template_url}`
|
||||||
|
|
||||||
|
tmp, Locomotive.config.delayed_job = Locomotive.config.delayed_job, false # disable DJ during this import
|
||||||
|
|
||||||
Locomotive::Import::Job.run!(File.open(template_local_path), site, { :samples => true })
|
Locomotive::Import::Job.run!(File.open(template_local_path), site, { :samples => true })
|
||||||
|
|
||||||
|
Locomotive.config.delayed_job = tmp # restore DJ flag
|
||||||
else
|
else
|
||||||
# do nothing
|
# do nothing
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
desc "Perform custom actions triggered by the Bushido hosting platform."
|
||||||
|
task :message => :environment do
|
||||||
|
event = ::Bushido::App.last_event
|
||||||
|
|
||||||
|
puts "processing...#{event.inspect}"
|
||||||
|
|
||||||
|
case event.category.to_s
|
||||||
|
when 'user'
|
||||||
|
case event.name.to_s
|
||||||
|
when 'create'
|
||||||
|
# an user has just claimed his application
|
||||||
|
account = Account.order_by(:created_at).first
|
||||||
|
|
||||||
|
account.email = event.data['email']
|
||||||
|
account.bushido_user_id = event.data['id']
|
||||||
|
|
||||||
|
account.save!
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
desc "Prepare an app to run on the Bushido hosting platform, called on every update. Called just before booting the app."
|
desc "Prepare an app to run on the Bushido hosting platform, called on every update. Called just before booting the app."
|
||||||
task :update do
|
task :update do
|
||||||
|
# re-built assets
|
||||||
Jammit.package!
|
Jammit.package!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user