Class: EY::Deployment
- Inherits:
-
Object
- Object
- EY::Deployment
- Defined in:
- lib/ey/deployment.rb
Defined Under Namespace
Classes: Error
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
Class Method Summary collapse
Instance Method Summary collapse
- #build_app ⇒ Object
- #db_adapter ⇒ Object
- #db_config ⇒ Object
- #db_file ⇒ Object
- #db_migrate ⇒ Object
- #hoptoad_key ⇒ Object
-
#initialize(env) ⇒ Deployment
constructor
A new instance of Deployment.
- #resque_config ⇒ Object
- #resque_file ⇒ Object
- #resque_web ⇒ Object
- #setup ⇒ Object
- #setup_db ⇒ Object
- #setup_resque ⇒ Object
- #sha1 ⇒ Object
- #valid_envs ⇒ Object
Constructor Details
#initialize(env) ⇒ Deployment
Returns a new instance of Deployment.
29 30 31 |
# File 'lib/ey/deployment.rb', line 29 def initialize(env) @env = env end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
33 34 35 |
# File 'lib/ey/deployment.rb', line 33 def env @env end |
Class Method Details
.app ⇒ Object
13 14 15 |
# File 'lib/ey/deployment.rb', line 13 def self.app @app ||= instance.build_app end |
.db_migrate ⇒ Object
21 22 23 |
# File 'lib/ey/deployment.rb', line 21 def self.db_migrate instance.db_migrate end |
.env ⇒ Object
17 18 19 |
# File 'lib/ey/deployment.rb', line 17 def self.env instance.env end |
.instance ⇒ Object
25 26 27 |
# File 'lib/ey/deployment.rb', line 25 def self.instance @instance || raise(Error, "call setup(rack_env) first") end |
.setup(env) ⇒ Object
8 9 10 11 |
# File 'lib/ey/deployment.rb', line 8 def self.setup(env) @instance = new(env) @instance.setup end |
Instance Method Details
#build_app ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/ey/deployment.rb', line 49 def build_app instance = self Rack::Builder.app { if instance.hoptoad_key use Rack::Hoptoad, instance.hoptoad_key end map "/ey/sha1" do run lambda { [200, {"Content-Type" => "text/plain"}, [instance.sha1]] } end if instance.resque_web map "/ey/resque" do run Resque::Server end end map "/" do run instance.app end } end |
#db_adapter ⇒ Object
98 99 100 |
# File 'lib/ey/deployment.rb', line 98 def db_adapter "postgres" end |
#db_config ⇒ Object
112 113 114 115 116 |
# File 'lib/ey/deployment.rb', line 112 def db_config @db_config ||= YAML.load_file(db_file.to_s). fetch(@env). values_at("username", "password", "host", "database") end |
#db_file ⇒ Object
124 125 126 |
# File 'lib/ey/deployment.rb', line 124 def db_file @db_file ||= Pathname("config/database.yml") end |
#db_migrate ⇒ Object
90 91 92 |
# File 'lib/ey/deployment.rb', line 90 def db_migrate DataMapper.auto_migrate! end |
#hoptoad_key ⇒ Object
106 107 |
# File 'lib/ey/deployment.rb', line 106 def hoptoad_key end |
#resque_config ⇒ Object
118 119 120 121 122 |
# File 'lib/ey/deployment.rb', line 118 def resque_config @resque_config ||= YAML.load_file(resque_file.to_s). fetch(@env). values_at("redis_host", "redis_port") end |
#resque_file ⇒ Object
128 129 130 |
# File 'lib/ey/deployment.rb', line 128 def resque_file @resque_file ||= Pathname("config/resque.yml") end |
#resque_web ⇒ Object
109 110 |
# File 'lib/ey/deployment.rb', line 109 def resque_web end |
#setup ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ey/deployment.rb', line 35 def setup unless valid_envs.include?(@env) raise Error, "invalid env: #{@env.inspect}" end if db_file.exist? setup_db end if resque_file.exist? setup_resque end end |
#setup_db ⇒ Object
74 75 76 |
# File 'lib/ey/deployment.rb', line 74 def setup_db DataMapper.setup(:default, ("#{db_adapter}://%s:%s@%s/%s" % db_config)) end |
#setup_resque ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/ey/deployment.rb', line 78 def setup_resque Resque.redis = ("%s:%s" % resque_config) if hoptoad_key Resque::Failure::Hoptoad.configure do |c| c.api_key = hoptoad_key c.secure = true c.server_environment = @env end end end |
#sha1 ⇒ Object
102 103 104 |
# File 'lib/ey/deployment.rb', line 102 def sha1 `git rev-parse HEAD`.chomp end |
#valid_envs ⇒ Object
94 95 96 |
# File 'lib/ey/deployment.rb', line 94 def valid_envs %w[staging production] end |