class Environmate::Deployment
Public Class Methods
new(user, puppet_env, revision, old_revision = nil)
click to toggle source
create a new instance of Deployment
-
user
- The user who triggered the deployment -
puppet_env
- The puppet environment to deploy -
revision
- The revision which should be deployed in the environment -
old_revision
- The revision the environment had previously
# File lib/environmate/deployment.rb, line 13 def initialize(user, puppet_env, revision, old_revision = nil) @user = user @puppet_env = puppet_env @revision = revision @old_revision = old_revision end
Public Instance Methods
deploy()
click to toggle source
Deploy the puppet environment
# File lib/environmate/deployment.rb, line 70 def deploy lockfile_path = Environmate.configuration['lockfile_path'] lockfile_options = Environmate.configuration['lockfile_options'] Lockfile.new(lockfile_path, lockfile_options) do begin if @revision.nil? || @revision.empty? @user.notify(:info, 'Revision was empty. Only doing a cleanup...') EnvironmentManager.master else @user.notify(:info, "Starting deployment of '#{@puppet_env}'...") new_env = new_environment @user.notify(:info, "Linking '#{@puppet_env}' => '#{@revision}'") new_env.link(@puppet_env) @user.notify(:info, "Done! Starting cleanup...") end EnvironmentManager.cleanup @user.notify(:info, "Cleanup done!") rescue Environmate::DeployError => e @user.notify(:error, "Error during deployment: #{e.message}") rescue => e @user.notify(:error, 'Error during deployment. This is probably a bug') @user.notify(:error, e.class) @user.notify(:error, e.message) @user.notify(:error, e.backtrace) end end end
deploy_dynamic()
click to toggle source
Deploy a dynamic environment
# File lib/environmate/deployment.rb, line 35 def deploy_dynamic if is_static_env? @user.notify(:error, "'#{@puppet_env}' is a static environment. There should not be a branch of the same name") return end @user.notify(:info, "Push of dynamic environment '#{@puppet_env}' received, attempting to deploy...") deploy end
deploy_static(token)
click to toggle source
Deploy a static environment
-
token
- The access token to deploy the environment
# File lib/environmate/deployment.rb, line 23 def deploy_static(token) unless is_static_env? @user.notify(:error, "'#{@puppet_env}' is not a static environment! Deployment aborted!") return end return unless token_valid?(token) @user.notify(:info, "Push of static environment '#{@puppet_env}' received, attempting to deploy...") deploy end
is_static_env?()
click to toggle source
Checks if the puppet environment is a static environment
# File lib/environmate/deployment.rb, line 46 def is_static_env? Environmate.configuration['static_environments'].keys.include?(@puppet_env) end
token_valid?(token)
click to toggle source
Checks if the token ist valid
-
token
- The token received from the hook
# File lib/environmate/deployment.rb, line 53 def token_valid?(token) real_token = Environmate.configuration['static_environments'][@puppet_env]['token'] if real_token.nil? @user.notify(:error, "No token set for '#{@puppet_env}'") false elsif real_token == token true else @user.notify(:error, "Incorrect token for deployment of '#{@puppet_env}'") false end rescue @user.notify(:error, "Error while parsing configuration for '#{@puppet_env}'") false end
Private Instance Methods
new_environment()
click to toggle source
check if the revision is already deployed, if not deploy it
# File lib/environmate/deployment.rb, line 102 def new_environment new_env = EnvironmentManager.find(@revision) if new_env.nil? @user.notify(:info, "Revision '#{@revision}' not already deployed, trying to find optimal starting point for deployment") env = EnvironmentManager.find(@old_revision) || EnvironmentManager.find(@puppet_env) || EnvironmentManager.master @user.notify(:info, "Deploying '#{@revision}' from copy of '#{env.name}'") new_env = env.copy(@revision) @user.notify(:info, "Deployment of '#{@revision}' done!") else @user.notify(:info, "Revision '#{@revision}' is already deployed") end new_env end