From 2ce1fadf52db285455acaa9ec1ec1b069391878a Mon Sep 17 00:00:00 2001 From: did Date: Fri, 27 May 2011 08:19:20 -0700 Subject: [PATCH] simplify the installation procedure for bushido users --- .gitignore | 1 + Gemfile | 10 ++++-- Gemfile.lock | 15 ++++++--- config/environments/development.rb | 10 ++++++ config/locales/formtastic.it.yml | 2 +- doc/TODO | 22 +++++++------- lib/locomotive/hosting/bushido.rb | 2 +- lib/locomotive/import.rb | 8 ++++- lib/locomotive/import/job.rb | 1 + lib/locomotive/middlewares/fonts.rb | 6 +++- lib/tasks/bushido.rake | 47 +++++++++++++++++++++++++++-- lib/tasks/locomotive.rake | 12 ++++++++ 12 files changed, 111 insertions(+), 25 deletions(-) create mode 100644 lib/tasks/locomotive.rake diff --git a/.gitignore b/.gitignore index bf447d5f..977de89e 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,4 @@ config/deploy.rb perf/*.rb gem_graph.png sites/ +permanent diff --git a/Gemfile b/Gemfile index da254639..5a494b87 100644 --- a/Gemfile +++ b/Gemfile @@ -27,7 +27,6 @@ gem 'fog', '0.3.7' gem 'mimetype-fu' gem 'actionmailer-with-request', :require => 'actionmailer_with_request' gem 'heroku', '1.19.1' -gem 'bushido' gem 'httparty', '>= 0.6.1' gem 'RedCloth', '4.2.7' gem 'delayed_job', '2.1.4' @@ -41,11 +40,16 @@ gem 'SystemTimer', :platforms => :ruby_18 group :development do # Using unicorn_rails instead of webrick (default server) gem 'unicorn' + gem 'bushido_stub', :path => '../gems/bushido_stub' end group :test, :development do - gem "ruby-debug", :platforms => :mri_18 - gem "ruby-debug19", :platforms => :mri_19 + gem 'ruby-debug', :platforms => :mri_18 + gem 'ruby-debug19', :platforms => :mri_19 +end + +group :production do + gem 'bushido' end group :test do diff --git a/Gemfile.lock b/Gemfile.lock index 2de2373d..38270433 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -11,6 +11,12 @@ GIT xpath (0.1.2) nokogiri (~> 1.4) +PATH + remote: ../gems/bushido_stub + specs: + bushido_stub (0.0.1) + activesupport + GEM remote: http://rubygems.org/ specs: @@ -74,7 +80,6 @@ GEM celerity (0.8.9) childprocess (0.1.9) ffi (~> 1.0.6) - closure-compiler (1.1.1) columnize (0.3.2) configuration (1.2.0) crack (0.1.8) @@ -141,9 +146,8 @@ GEM inherited_resources (1.1.2) has_scope (~> 0.5.0) responders (~> 0.6.0) - jammit (0.6.0) - closure-compiler (>= 0.1.0) - yui-compressor (>= 0.9.1) + jammit (0.6.3) + yui-compressor (>= 0.9.3) json (1.5.1) json_pure (1.4.6) kgio (2.4.1) @@ -244,7 +248,7 @@ GEM ffi (>= 1.0.7) json_pure rubyzip - spork (0.8.4) + spork (0.8.5) term-ansicolor (1.0.5) thor (0.14.6) treetop (1.4.9) @@ -271,6 +275,7 @@ DEPENDENCIES autotest bson_ext (~> 1.3.0) bushido + bushido_stub! capybara cucumber (= 0.8.5) cucumber-rails diff --git a/config/environments/development.rb b/config/environments/development.rb index b973ee5f..c66e1a8b 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -27,4 +27,14 @@ Locomotive::Application.configure do :port => 1025, :domain => "example.com" } + + # set up the bushido stub (uncomment it) + # config.bushido_stub_env = false + + config.bushido_stub_env = { + 'APP_TLD' => 'bushi.do', + 'BUSHIDO_APP' => 'san_francisco', + 'BUSHIDO_HOST' => 'bushi.do', + 'LOCOMOTIVE_SITE_NAME' => 'Locomotive TEST' + } end \ No newline at end of file diff --git a/config/locales/formtastic.it.yml b/config/locales/formtastic.it.yml index 66e20276..adb1a689 100644 --- a/config/locales/formtastic.it.yml +++ b/config/locales/formtastic.it.yml @@ -14,7 +14,7 @@ it: membership_email: Email account file: File preview: Anteprima - options: Opzioni + options: Opzioni avanzate custom_fields: Campi personalizzati other_fields: Altre informazioni presentation: Presentazione diff --git a/doc/TODO b/doc/TODO index 6487944f..7eb36344 100644 --- a/doc/TODO +++ b/doc/TODO @@ -1,28 +1,25 @@ BOARD: -x bugs: - x #50 - x #51 ~ editable_elements: inheritable: false (Mattias) => seems to be fixed by Dirk's last pull request (#44) => content tag - bushido version -- upgrade warning if new version of locomotive (maybe based on the commit id) -- duostack version -x 2 different sites on the same main domain (one in www, the other one in something else) (Raphael Costa) -- seo section for the page form: seo title, seo keywords, seo description -- icon for redirection page in the pages section (back-office) -- write my first tutorial about locomotive + - default template BACKLOG: - custom_fields: - validation: regexp (pre-defined regexps ?) - - new type: belongs_to => association + x new type: belongs_to => association - inline editing (http://www.aloha-editor.com/wiki/index.php/Aloha_PHP_Example) - html view in the aloha popup - editable elements should wrap a tag: div, h1, ...etc (default span) - edit images (upload new ones, ...etc) => wait for aloha or send them an email ? - global regions: keyword in editable element (http://www.mongodb.org/display/DOCS/Updating) - cucumber features for admin pages (in progress) +(- duostack version) +- icon for redirection page in the pages section (back-office) +- write my first tutorial about locomotive +- upgrade warning if new version of locomotive (maybe based on the commit id) + REFACTORING: @@ -211,4 +208,7 @@ x validation for custom fields: required done x pull request #44 x bug on dates (https://github.com/locomotivecms/engine/issues#issue/48) x generated sitemaps are invalid (url + date) -x integrate new locomotivecms home \ No newline at end of file +x integrate new locomotivecms home +x seo section for the page form: seo title, seo keywords, seo description +x bugs: #50, #51 +x 2 different sites on the same main domain (one in www, the other one in something else) (Raphael Costa) \ No newline at end of file diff --git a/lib/locomotive/hosting/bushido.rb b/lib/locomotive/hosting/bushido.rb index 8a30623d..6e437b2f 100644 --- a/lib/locomotive/hosting/bushido.rb +++ b/lib/locomotive/hosting/bushido.rb @@ -29,7 +29,7 @@ module Locomotive self.setup_smtp_settings - self.config.delayed_job = true # force the use of delayed_job + self.config.delayed_job = false #true # force the use of delayed_job self.bushido_domains = ::Bushido::App.domains self.bushido_subdomain = ::Bushido::App.subdomain diff --git a/lib/locomotive/import.rb b/lib/locomotive/import.rb index 45ebd993..a78381ce 100644 --- a/lib/locomotive/import.rb +++ b/lib/locomotive/import.rb @@ -6,4 +6,10 @@ require 'locomotive/import/assets' require 'locomotive/import/asset_collections' require 'locomotive/import/content_types' require 'locomotive/import/snippets' -require 'locomotive/import/pages' \ No newline at end of file +require 'locomotive/import/pages' + +module Locomotive + module Import + DEFAULT_SITE_TEMPLATE = 'https://github.com/locomotivecms/default-site-template/zipball/master' + end +end \ No newline at end of file diff --git a/lib/locomotive/import/job.rb b/lib/locomotive/import/job.rb index f45d3e13..2a65c0b8 100644 --- a/lib/locomotive/import/job.rb +++ b/lib/locomotive/import/job.rb @@ -70,6 +70,7 @@ module Locomotive job = self.new(zipfile, site, options) if Locomotive.config.delayed_job + puts "delayed::JOB !" Delayed::Job.enqueue job, { :site => site, :job_type => 'import' } else job.perform diff --git a/lib/locomotive/middlewares/fonts.rb b/lib/locomotive/middlewares/fonts.rb index 49c66d4d..05c22e62 100644 --- a/lib/locomotive/middlewares/fonts.rb +++ b/lib/locomotive/middlewares/fonts.rb @@ -10,7 +10,11 @@ module Locomotive def call(env) if env["PATH_INFO"] =~ @path_regexp - site = fetch_site(env['SERVER_NAME']) + if Locomotive.config.multi_sites? + site = fetch_site(env['SERVER_NAME']) + else + site = Site.first + end if site.nil? @app.call(env) diff --git a/lib/tasks/bushido.rake b/lib/tasks/bushido.rake index 159d3c10..07f99450 100644 --- a/lib/tasks/bushido.rake +++ b/lib/tasks/bushido.rake @@ -1,10 +1,53 @@ require 'bushido' require 'jammit' +require 'net/http' 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." - task :install do + task :install => :environment do Jammit.package! + + if ENV['BUSHIDO_USER_EMAIL'] && ENV['BUSHIDO_USER_ID'] + # already logged in in Bushido + account = Account.create!({ + :email => ENV['BUSHIDO_USER_EMAIL'], + :name => ENV['BUSHIDO_USER_NAME'] || ENV['BUSHIDO_USER_EMAIL'].split('@').first, + :password => ActiveSupport::SecureRandom.base64(6) + }) + else + # create an anonymous account right away + account = Account.create!({ + :email => "#{ENV['BUSHIDO_APP']}@#{ENV['BUSHIDO_HOST']}", + :name => ENV['BUSHIDO_APP'], + :password => ActiveSupport::SecureRandom.base64(6) + }) + end + + # create the site + site = Site.create_first_one(:name => ENV['LOCOMOTIVE_SITE_NAME'] || ENV['BUSHIDO_APP']) + + # fetch the site template + template_url = ENV['SITE_TEMPLATE_URL'] || Locomotive::Import::DEFAULT_SITE_TEMPLATE + template_url = "http://#{template_url}" unless template_url =~ /^https?:\/\// + + template_local_path = "#{Rails.root}/permanent/site_template.zip" + + uri = URI.parse(template_url) + http = Net::HTTP.new(uri.host, uri.port) + + if template_url.starts_with?('https') # ssl request ? + http.use_ssl = true + http.verify_mode = OpenSSL::SSL::VERIFY_NONE + end + + case http.request(Net::HTTP::Get.new(uri.request_uri)) + when Net::HTTPSuccess, Net::HTTPFound + `curl -L -s -o #{template_local_path} #{template_url}` + + Locomotive::Import::Job.run!(File.open(template_local_path), site, { :samples => true }) + else + # do nothing + end end desc "Prepare an app to run on the Bushido hosting platform, called on every update. Called just before booting the app." @@ -12,4 +55,4 @@ namespace :bushido do Jammit.package! end end - + diff --git a/lib/tasks/locomotive.rake b/lib/tasks/locomotive.rake new file mode 100644 index 00000000..227de113 --- /dev/null +++ b/lib/tasks/locomotive.rake @@ -0,0 +1,12 @@ +namespace :locomotive do + + desc 'Fetch the Locomotive default site template for the installation' + task :fetch_default_site_template => :environment do + puts "Downloading default site template from '#{Locomotive::Import.DEFAULT_SITE_TEMPLATE}'" + `curl -L -s -o #{Rails.root}/tmp/default_site_template.zip #{Locomotive::Import.DEFAULT_SITE_TEMPLATE}` + puts '...done' + end + +end + +