class DeploYML::Project

Constants

CONFIG_DIR

The general configuration directory.

CONFIG_FILE

The configuration file name.

ENVIRONMENTS_DIR

The configuration directory.

STAGING_DIR

The name of the directory to stage deployments in.

Attributes

environments[R]

The deployment environments of the project

root[R]

The root directory of the project

Public Class Methods

new(root=Dir.pwd) click to toggle source

Creates a new project using the given configuration file.

@param [String] root

The root directory of the project.

@raise [ConfigNotFound]

The configuration file for the project could not be found
in any of the common directories.
# 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

Public Instance Methods

config!(env=:production) click to toggle source

Configures the Web server to be ran on the destination server.

@param [Symbol, String] env

The environment to deploy to.

@return [true]

Indicates that the tasks were successfully completed.
# File lib/deployml/project.rb, line 189
def config!(env=:production)
  environment(env).config!
end
deploy!(env=:production) click to toggle source

Deploys a new project.

@param [Symbol, String] env

The environment to deploy to.

@return [true]

Indicates that the tasks were successfully completed.

@since 0.2.0

# File lib/deployml/project.rb, line 243
def deploy!(env=:production)
  environment(env).deploy!
end
development() click to toggle source

Convenience method for accessing the development environment.

@return [Environment]

The development environment.

@since 0.3.0

# File lib/deployml/project.rb, line 82
def development
  environment(:development)
end
environment(name=:production) click to toggle source

@param [Symbol, String] name

The name of the environment to use.

@return [Environment]

The environment with the given name.

@raise [UnknownEnvironment]

No environment was configured with the given name.

@since 0.3.0

# 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
install!(env=:production) click to toggle source

Installs the project on the destination server.

@param [Symbol, String] env

The environment to deploy to.

@return [true]

Indicates that the tasks were successfully completed.
# File lib/deployml/project.rb, line 163
def install!(env=:production)
  environment(env).install!
end
invoke(tasks,env=:production) click to toggle source

Deploys the project.

@param [Array<Symbol>] tasks

The tasks to run during the deployment.

@param [Symbol, String] env

The environment to deploy to.

@return [true]

Indicates that the tasks were successfully completed.

@since 0.2.0

# File lib/deployml/project.rb, line 124
def invoke(tasks,env=:production)
  environment(env).invoke(tasks)
end
migrate!(env=:production) click to toggle source

Migrates the database used by the project.

@param [Symbol, String] env

The environment to deploy to.

@return [true]

Indicates that the tasks were successfully completed.
# File lib/deployml/project.rb, line 176
def migrate!(env=:production)
  environment(env).migrate!
end
production() click to toggle source

Convenience method for accessing the production environment.

@return [Environment]

The production environment.

@since 0.3.0

# File lib/deployml/project.rb, line 106
def production
  environment(:production)
end
redeploy!(env=:production) click to toggle source

Redeploys a project.

@param [Symbol, String] env

The environment to deploy to.

@return [true]

Indicates that the tasks were successfully completed.

@since 0.2.0

# File lib/deployml/project.rb, line 258
def redeploy!(env=:production)
  environment(env).redeploy!
end
restart!(env=:production) click to toggle source

Restarts the Web server for the project.

@param [Symbol, String] env

The environment to deploy to.

@return [true]

Indicates that the tasks were successfully completed.
# File lib/deployml/project.rb, line 228
def restart!(env=:production)
  environment(env).restart!
end
setup!(env=:production) click to toggle source

Sets up the deployment repository for the project.

@param [Symbol, String] env

The environment to deploy to.

@return [true]

Indicates that the tasks were successfully completed.
# File lib/deployml/project.rb, line 137
def setup!(env=:production)
  environment(env).setup!
end
staging() click to toggle source

Convenience method for accessing the staging environment.

@return [Environment]

The staging environment.

@since 0.3.0

# File lib/deployml/project.rb, line 94
def staging
  environment(:staging)
end
start!(env=:production) click to toggle source

Starts the Web server for the project.

@param [Symbol, String] env

The environment to deploy to.

@return [true]

Indicates that the tasks were successfully completed.
# File lib/deployml/project.rb, line 202
def start!(env=:production)
  environment(env).start!
end
stop!(env=:production) click to toggle source

Stops the Web server for the project.

@param [Symbol, String] env

The environment to deploy to.

@return [true]

Indicates that the tasks were successfully completed.
# File lib/deployml/project.rb, line 215
def stop!(env=:production)
  environment(env).stop!
end
update!(env=:production) click to toggle source

Updates the deployed repository of the project.

@param [Symbol, String] env

The environment to deploy to.

@return [true]

Indicates that the tasks were successfully completed.
# File lib/deployml/project.rb, line 150
def update!(env=:production)
  environment(env).update!
end

Protected Instance Methods

infer_configuration() click to toggle source

Infers the configuration from the project root directory.

@return [Hash{Symbol => Object}]

The inferred configuration.

@since 0.4.1

# 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
load_configuration(path) click to toggle source

Loads configuration from a YAML file.

@param [String] path

The path to the configuration file.

@return [Hash]

The loaded configuration.

@raise [InvalidConfig]

The configuration file did not contain a YAML Hash.

@since 0.4.1

# 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!() click to toggle source

Loads the project configuration.

@since 0.3.0

# 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