Class: DeploYML::Project
- Inherits:
-
Object
- Object
- DeploYML::Project
- Defined in:
- lib/deployml/project.rb
Constant Summary collapse
- CONFIG_DIR =
The general configuration directory.
'config'
- CONFIG_FILE =
The configuration file name.
'deploy.yml'
- ENVIRONMENTS_DIR =
The configuration directory.
'deploy'
- STAGING_DIR =
The name of the directory to stage deployments in.
'.deploy'
Instance Attribute Summary collapse
-
#environments ⇒ Object
readonly
The deployment environments of the project.
-
#root ⇒ Object
readonly
The root directory of the project.
Instance Method Summary collapse
-
#config!(env = :production) ⇒ true
Configures the Web server to be ran on the destination server.
-
#deploy!(env = :production) ⇒ true
Deploys a new project.
-
#development ⇒ Environment
Convenience method for accessing the development environment.
-
#environment(name = :production) ⇒ Environment
The environment with the given name.
-
#infer_configuration ⇒ Hash{Symbol => Object}
protected
Infers the configuration from the project root directory.
-
#initialize(root = Dir.pwd) ⇒ Project
constructor
Creates a new project using the given configuration file.
-
#install!(env = :production) ⇒ true
Installs the project on the destination server.
-
#invoke(tasks, env = :production) ⇒ true
Deploys the project.
-
#load_configuration(path) ⇒ Hash
protected
Loads configuration from a YAML file.
-
#load_environments! ⇒ Object
protected
Loads the project configuration.
-
#migrate!(env = :production) ⇒ true
Migrates the database used by the project.
-
#production ⇒ Environment
Convenience method for accessing the production environment.
-
#redeploy!(env = :production) ⇒ true
Redeploys a project.
-
#restart!(env = :production) ⇒ true
Restarts the Web server for the project.
-
#setup!(env = :production) ⇒ true
Sets up the deployment repository for the project.
-
#staging ⇒ Environment
Convenience method for accessing the staging environment.
-
#start!(env = :production) ⇒ true
Starts the Web server for the project.
-
#stop!(env = :production) ⇒ true
Stops the Web server for the project.
-
#update!(env = :production) ⇒ true
Updates the deployed repository of the project.
Constructor Details
#initialize(root = Dir.pwd) ⇒ Project
Creates a new project using the given configuration file.
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/deployml/project.rb', line 40 def initialize(root=Dir.pwd) @root = File.(root) @config_file = File.join(@root,CONFIG_DIR,CONFIG_FILE) @environments_dir = File.join(@root,CONFIG_DIR,ENVIRONMENTS_DIR) unless (File.file?(@config_file) || File.directory?(@environments_dir)) raise(ConfigNotFound,"could not find '#{CONFIG_FILE}' or '#{ENVIRONMENTS_DIR}' in #{root}",caller) end load_environments! end |
Instance Attribute Details
#environments ⇒ Object (readonly)
The deployment environments of the project
28 29 30 |
# File 'lib/deployml/project.rb', line 28 def environments @environments end |
#root ⇒ Object (readonly)
The root directory of the project
25 26 27 |
# File 'lib/deployml/project.rb', line 25 def root @root end |
Instance Method Details
#config!(env = :production) ⇒ true
Configures the Web server to be ran on the destination server.
189 190 191 |
# File 'lib/deployml/project.rb', line 189 def config!(env=:production) environment(env).config! end |
#deploy!(env = :production) ⇒ true
Deploys a new project.
243 244 245 |
# File 'lib/deployml/project.rb', line 243 def deploy!(env=:production) environment(env).deploy! end |
#development ⇒ Environment
Convenience method for accessing the development environment.
82 83 84 |
# File 'lib/deployml/project.rb', line 82 def development environment(:development) end |
#environment(name = :production) ⇒ Environment
Returns The environment with the given name.
64 65 66 67 68 69 70 71 72 |
# File 'lib/deployml/project.rb', line 64 def environment(name=:production) name = name.to_sym unless @environments[name] raise(UnknownEnvironment,"unknown environment: #{name}",caller) end return @environments[name] end |
#infer_configuration ⇒ Hash{Symbol => Object} (protected)
Infers the configuration from the project root directory.
272 273 274 275 276 277 278 279 280 281 |
# File 'lib/deployml/project.rb', line 272 def infer_configuration config = {} # check for Bundler if File.file?(File.join(@root,'Gemfile')) config[:bundler] = true end return config end |
#install!(env = :production) ⇒ true
Installs the project on the destination server.
163 164 165 |
# File 'lib/deployml/project.rb', line 163 def install!(env=:production) environment(env).install! end |
#invoke(tasks, env = :production) ⇒ true
Deploys the project.
124 125 126 |
# File 'lib/deployml/project.rb', line 124 def invoke(tasks,env=:production) environment(env).invoke(tasks) end |
#load_configuration(path) ⇒ Hash (protected)
Loads configuration from a YAML file.
297 298 299 300 301 302 303 304 305 |
# File 'lib/deployml/project.rb', line 297 def load_configuration(path) config = YAML.load_file(path) unless config.kind_of?(Hash) raise(InvalidConfig,"DeploYML file #{path.dump} does not contain a Hash",caller) end return config end |
#load_environments! ⇒ Object (protected)
Loads the project configuration.
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
# File 'lib/deployml/project.rb', line 312 def load_environments! base_config = infer_configuration if File.file?(@config_file) base_config.merge!(load_configuration(@config_file)) end @environments = {} if File.directory?(@environments_dir) Dir.glob(File.join(@environments_dir,'*.yml')) do |path| config = base_config.merge(load_configuration(path)) name = File.basename(path).sub(/\.yml$/,'').to_sym @environments[name] = Environment.new(name,config) end else @environments[:production] = Environment.new(:production,base_config) end end |
#migrate!(env = :production) ⇒ true
Migrates the database used by the project.
176 177 178 |
# File 'lib/deployml/project.rb', line 176 def migrate!(env=:production) environment(env).migrate! end |
#production ⇒ Environment
Convenience method for accessing the production environment.
106 107 108 |
# File 'lib/deployml/project.rb', line 106 def production environment(:production) end |
#redeploy!(env = :production) ⇒ true
Redeploys a project.
258 259 260 |
# File 'lib/deployml/project.rb', line 258 def redeploy!(env=:production) environment(env).redeploy! end |
#restart!(env = :production) ⇒ true
Restarts the Web server for the project.
228 229 230 |
# File 'lib/deployml/project.rb', line 228 def restart!(env=:production) environment(env).restart! end |
#setup!(env = :production) ⇒ true
Sets up the deployment repository for the project.
137 138 139 |
# File 'lib/deployml/project.rb', line 137 def setup!(env=:production) environment(env).setup! end |
#staging ⇒ Environment
Convenience method for accessing the staging environment.
94 95 96 |
# File 'lib/deployml/project.rb', line 94 def staging environment(:staging) end |
#start!(env = :production) ⇒ true
Starts the Web server for the project.
202 203 204 |
# File 'lib/deployml/project.rb', line 202 def start!(env=:production) environment(env).start! end |
#stop!(env = :production) ⇒ true
Stops the Web server for the project.
215 216 217 |
# File 'lib/deployml/project.rb', line 215 def stop!(env=:production) environment(env).stop! end |
#update!(env = :production) ⇒ true
Updates the deployed repository of the project.
150 151 152 |
# File 'lib/deployml/project.rb', line 150 def update!(env=:production) environment(env).update! end |