locomotive-heroku 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.textile +41 -0
- data/Rakefile +30 -0
- data/lib/locomotive/heroku.rb +63 -0
- data/lib/locomotive/heroku/custom_domain.rb +38 -0
- data/lib/locomotive/heroku/enabler.rb +24 -0
- data/lib/locomotive/heroku/first_installation.rb +27 -0
- data/lib/locomotive/heroku/patches.rb +6 -0
- data/lib/locomotive/heroku/version.rb +5 -0
- metadata +82 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 NoCoffee, released under the MIT license
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.textile
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
h1. Heroku extension for LocomotiveCMS
|
2
|
+
|
3
|
+
This extension allows LocomotiveCMS to run on heroku
|
4
|
+
|
5
|
+
h2. Requirements
|
6
|
+
|
7
|
+
* Heroku gem
|
8
|
+
* Heroku app
|
9
|
+
* Heroku API key
|
10
|
+
* LocomotiveCMS engine
|
11
|
+
|
12
|
+
h2. Installation
|
13
|
+
|
14
|
+
Inside your LocomotiveCMS application, open your **Gemfile** file and insert the following line after the one referencing LocomotiveCMS
|
15
|
+
|
16
|
+
bc. gem 'locomotive_heroku', :require => 'locomotive/heroku'
|
17
|
+
|
18
|
+
h2. Configuration
|
19
|
+
|
20
|
+
Then, you have to let Heroku know about your API key and your application name
|
21
|
+
Modify your Locomotive config file (**config/locomotive.rb**)
|
22
|
+
|
23
|
+
bc. config.hosting = { :target => :heroku, :api_key => '<YOUR HEROKU API KEY>', :app_name => '<MY HEROKU APP NAME>' }
|
24
|
+
|
25
|
+
h2. Storage: Amazon S3
|
26
|
+
|
27
|
+
Because Heroku disables writing on their disk, we have to use Amazon S3 or any storage providers as long as they are supported by Carrierwave. In the following example, we will use Amazon S3 which is by far the most known/used.
|
28
|
+
|
29
|
+
Open your terminal and at the root of your application on your machine,
|
30
|
+
|
31
|
+
bc.. heroku config:add S3_KEY_ID=<your s3 key id>
|
32
|
+
heroku config:add S3_SECRET_KEY=<your s3 secret key>
|
33
|
+
heroku config:add S3_BUCKET=<your s3 bucket name>
|
34
|
+
|
35
|
+
p. Note: If you plan to use another storage provider, do not forget to modify the **config/carrierwave.rb** file accordingly.
|
36
|
+
|
37
|
+
h2. Contact
|
38
|
+
|
39
|
+
Feel free to contact me at didier at nocoffee dot fr.
|
40
|
+
|
41
|
+
Copyright (c) 2012 NoCoffee, released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'Heroku'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
Bundler::GemHelper.install_tasks
|
24
|
+
|
25
|
+
# === RSpec ===
|
26
|
+
require 'rspec/core/rake_task'
|
27
|
+
RSpec::Core::RakeTask.new(:spec)
|
28
|
+
|
29
|
+
# === Default task ===
|
30
|
+
task :default => :spec
|
@@ -0,0 +1,63 @@
|
|
1
|
+
puts "\t...loading heroku extension"
|
2
|
+
|
3
|
+
require 'heroku-api'
|
4
|
+
require 'locomotive/heroku/patches'
|
5
|
+
require 'locomotive/heroku/custom_domain'
|
6
|
+
require 'locomotive/heroku/first_installation'
|
7
|
+
require 'locomotive/heroku/enabler'
|
8
|
+
|
9
|
+
module Locomotive
|
10
|
+
module Heroku
|
11
|
+
|
12
|
+
class << self
|
13
|
+
attr_accessor :connection, :app_name, :domains
|
14
|
+
|
15
|
+
def domains
|
16
|
+
if @domains.nil?
|
17
|
+
response = self.connection.get_domains(self.app_name)
|
18
|
+
|
19
|
+
if response.status == 200
|
20
|
+
@domains = response.body.map { |h| h['domain'] }.reject { |n| n.starts_with?('*') }
|
21
|
+
else
|
22
|
+
@domains = []
|
23
|
+
end
|
24
|
+
else
|
25
|
+
@domains
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def connection
|
30
|
+
return @connection if @connection
|
31
|
+
|
32
|
+
raise 'The Heroku API key is mandatory' if ENV['HEROKU_API_KEY'].blank? && Locomotive.config.hosting[:api_key].blank?
|
33
|
+
|
34
|
+
@connection = ::Heroku::API.new(:api_key => ENV['HEROKU_API_KEY'] || Locomotive.config.hosting[:api_key])
|
35
|
+
end
|
36
|
+
|
37
|
+
def app_name
|
38
|
+
return @app_name if @app_name
|
39
|
+
|
40
|
+
raise 'The Heroku application name is mandatory' if ENV['APP_NAME'].blank? && Locomotive.config.hosting[:app_name].blank?
|
41
|
+
|
42
|
+
@app_name = Locomotive.config.hosting[:app_name] || ENV['APP_NAME']
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.add_domain(name)
|
47
|
+
Locomotive.log "[add heroku domain] #{name}"
|
48
|
+
|
49
|
+
response = self.connection.post_domain(self.app_name, name)
|
50
|
+
|
51
|
+
if response.status >= 200 && response.status < 300
|
52
|
+
self.domains << name
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.remove_domain(name)
|
57
|
+
Locomotive.log "[remove heroku domain] #{name}"
|
58
|
+
self.connection.delete_domain(self.app_name, name)
|
59
|
+
self.domains.delete(name)
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Locomotive
|
2
|
+
module Heroku
|
3
|
+
module CustomDomain
|
4
|
+
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
after_save :sync_heroku_domains
|
9
|
+
after_destroy :remove_heroku_domains
|
10
|
+
end
|
11
|
+
|
12
|
+
protected
|
13
|
+
|
14
|
+
def sync_heroku_domains
|
15
|
+
# all the Heroku domains should also referenced in the site, if not then remove them from Heroku.
|
16
|
+
Locomotive::Heroku.domains.each do |domain|
|
17
|
+
unless self.domains_without_subdomain.include?(domain)
|
18
|
+
Locomotive::Heroku.remove_domain(domain)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# add the site domains should referenced in the Heroku domains, if not then add them to Heroku
|
23
|
+
self.domains_without_subdomain.each do |domain|
|
24
|
+
unless Locomotive::Heroku.domains.include?(domain)
|
25
|
+
Locomotive::Heroku.add_domain(domain)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def remove_heroku_domains
|
31
|
+
self.domains_without_subdomain.each do |domain|
|
32
|
+
Locomotive::Heroku.remove_domain(domain)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Locomotive
|
2
|
+
|
3
|
+
def self.enable_heroku
|
4
|
+
Locomotive.config.domain = 'herokuapp.com' unless Locomotive.config.multi_sites?
|
5
|
+
|
6
|
+
# we can manage domains within Heroku no matter what the value of the multi_sites option is
|
7
|
+
Locomotive.config.manage_domains = true
|
8
|
+
Locomotive.config.manage_subdomain = false unless Locomotive.config.multi_sites?
|
9
|
+
|
10
|
+
# rack_cache: disabled because of Varnish
|
11
|
+
Locomotive.config.rack_cache = false
|
12
|
+
|
13
|
+
# hooks
|
14
|
+
Locomotive::Site.send :include, Locomotive::Heroku::CustomDomain
|
15
|
+
Locomotive::Site.send :include, Locomotive::Heroku::FirstInstallation
|
16
|
+
|
17
|
+
# initialize the API connection
|
18
|
+
Locomotive::Heroku.connection
|
19
|
+
|
20
|
+
# load all the domains
|
21
|
+
Locomotive::Heroku.domains
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Locomotive
|
2
|
+
module Heroku
|
3
|
+
module FirstInstallation
|
4
|
+
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
|
9
|
+
class << self
|
10
|
+
alias_method_chain :create_first_one, :heroku
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
module ClassMethods
|
16
|
+
|
17
|
+
def create_first_one_with_heroku(attributes)
|
18
|
+
attributes[:subdomain] = Locomotive::Heroku.app_name
|
19
|
+
|
20
|
+
self.create_first_one_without_heroku(attributes)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: locomotive-heroku
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Didier Lafforgue
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-01 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: &2154722040 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.2.1
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2154722040
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: heroku-api
|
27
|
+
requirement: &2154721380 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.1.0
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2154721380
|
36
|
+
description: Enhance the LocomotiveCMS engine in order to make it run on Heroku
|
37
|
+
email:
|
38
|
+
- didier@nocoffee.fr
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- lib/locomotive/heroku/custom_domain.rb
|
44
|
+
- lib/locomotive/heroku/enabler.rb
|
45
|
+
- lib/locomotive/heroku/first_installation.rb
|
46
|
+
- lib/locomotive/heroku/patches.rb
|
47
|
+
- lib/locomotive/heroku/version.rb
|
48
|
+
- lib/locomotive/heroku.rb
|
49
|
+
- MIT-LICENSE
|
50
|
+
- Rakefile
|
51
|
+
- README.textile
|
52
|
+
homepage: http://www.locomotivecms.com
|
53
|
+
licenses: []
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
segments:
|
65
|
+
- 0
|
66
|
+
hash: 255214951121743543
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
segments:
|
74
|
+
- 0
|
75
|
+
hash: 255214951121743543
|
76
|
+
requirements: []
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 1.8.11
|
79
|
+
signing_key:
|
80
|
+
specification_version: 3
|
81
|
+
summary: Heroku for LocomotiveCMS
|
82
|
+
test_files: []
|