Class: DeploYML::Project

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(root = Dir.pwd) ⇒ Project

Creates a new project using the given configuration file.

Parameters:

  • root (String) (defaults to: Dir.pwd)

    The root directory of the project.

Raises:

  • (ConfigNotFound)

    The configuration file for the project could not be found in any of the common directories.



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.expand_path(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

#environmentsObject (readonly)

The deployment environments of the project



28
29
30
# File 'lib/deployml/project.rb', line 28

def environments
  @environments
end

#rootObject (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.

Parameters:

  • env (Symbol, String) (defaults to: :production)

    The environment to deploy to.

Returns:

  • (true)

    Indicates that the tasks were successfully completed.



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.

Parameters:

  • env (Symbol, String) (defaults to: :production)

    The environment to deploy to.

Returns:

  • (true)

    Indicates that the tasks were successfully completed.

Since:

  • 0.2.0



243
244
245
# File 'lib/deployml/project.rb', line 243

def deploy!(env=:production)
  environment(env).deploy!
end

#developmentEnvironment

Convenience method for accessing the development environment.

Returns:

Since:

  • 0.3.0



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.

Parameters:

  • name (Symbol, String) (defaults to: :production)

    The name of the environment to use.

Returns:

  • (Environment)

    The environment with the given name.

Raises:

Since:

  • 0.3.0



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_configurationHash{Symbol => Object} (protected)

Infers the configuration from the project root directory.

Returns:

  • (Hash{Symbol => Object})

    The inferred configuration.

Since:

  • 0.4.1



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.

Parameters:

  • env (Symbol, String) (defaults to: :production)

    The environment to deploy to.

Returns:

  • (true)

    Indicates that the tasks were successfully completed.



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.

Parameters:

  • tasks (Array<Symbol>)

    The tasks to run during the deployment.

  • env (Symbol, String) (defaults to: :production)

    The environment to deploy to.

Returns:

  • (true)

    Indicates that the tasks were successfully completed.

Since:

  • 0.2.0



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.

Parameters:

  • path (String)

    The path to the configuration file.

Returns:

  • (Hash)

    The loaded configuration.

Raises:

  • (InvalidConfig)

    The configuration file did not contain a YAML Hash.

Since:

  • 0.4.1



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.

Since:

  • 0.3.0



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.

Parameters:

  • env (Symbol, String) (defaults to: :production)

    The environment to deploy to.

Returns:

  • (true)

    Indicates that the tasks were successfully completed.



176
177
178
# File 'lib/deployml/project.rb', line 176

def migrate!(env=:production)
  environment(env).migrate!
end

#productionEnvironment

Convenience method for accessing the production environment.

Returns:

Since:

  • 0.3.0



106
107
108
# File 'lib/deployml/project.rb', line 106

def production
  environment(:production)
end

#redeploy!(env = :production) ⇒ true

Redeploys a project.

Parameters:

  • env (Symbol, String) (defaults to: :production)

    The environment to deploy to.

Returns:

  • (true)

    Indicates that the tasks were successfully completed.

Since:

  • 0.2.0



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.

Parameters:

  • env (Symbol, String) (defaults to: :production)

    The environment to deploy to.

Returns:

  • (true)

    Indicates that the tasks were successfully completed.



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.

Parameters:

  • env (Symbol, String) (defaults to: :production)

    The environment to deploy to.

Returns:

  • (true)

    Indicates that the tasks were successfully completed.



137
138
139
# File 'lib/deployml/project.rb', line 137

def setup!(env=:production)
  environment(env).setup!
end

#stagingEnvironment

Convenience method for accessing the staging environment.

Returns:

Since:

  • 0.3.0



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.

Parameters:

  • env (Symbol, String) (defaults to: :production)

    The environment to deploy to.

Returns:

  • (true)

    Indicates that the tasks were successfully completed.



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.

Parameters:

  • env (Symbol, String) (defaults to: :production)

    The environment to deploy to.

Returns:

  • (true)

    Indicates that the tasks were successfully completed.



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.

Parameters:

  • env (Symbol, String) (defaults to: :production)

    The environment to deploy to.

Returns:

  • (true)

    Indicates that the tasks were successfully completed.



150
151
152
# File 'lib/deployml/project.rb', line 150

def update!(env=:production)
  environment(env).update!
end