Class: Inploy::Deploy

Inherits:
Object
  • Object
show all
Includes:
DSL, Helper
Defined in:
lib/inploy/deploy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DSL

#callback, #create_folder, #create_folders, #file_exists?, included, #load_module, #login_shell_wrap, #rake, #rake_if_included, #remote_run, #ruby_if_exists, #run, #say, #secure_copy, #sudo_if_should, #using_bundler?

Methods included from Helper

#application_folder, #application_path, #bundle_cmd, #bundle_install, #camelize, #clear_cache, #configuration_file, #copy_sample_files, #host, #install_gems, #jammit_is_installed?, #migrate_database, #notify_new_relic, #skip_step?, #skip_steps_cmd, #tasks, #update_crontab

Constructor Details

#initializeDeploy

Returns a new instance of Deploy.



10
11
12
13
14
15
16
17
18
19
# File 'lib/inploy/deploy.rb', line 10

def initialize
  self.server = :passenger
  @cache_dirs = %w(public/cache)
  @branch = 'master'
  @environment = 'production'
  @user = "deploy"
  @path = "/var/local/apps"
  @app_folder = nil
  configure
end

Instance Attribute Details

#app_folderObject

Returns the value of attribute app_folder.



6
7
8
# File 'lib/inploy/deploy.rb', line 6

def app_folder
  @app_folder
end

#applicationObject

Returns the value of attribute application.



6
7
8
# File 'lib/inploy/deploy.rb', line 6

def application
  @application
end

#branchObject

Returns the value of attribute branch.



6
7
8
# File 'lib/inploy/deploy.rb', line 6

def branch
  @branch
end

#bundler_optsObject

Returns the value of attribute bundler_opts.



6
7
8
# File 'lib/inploy/deploy.rb', line 6

def bundler_opts
  @bundler_opts
end

#cache_dirsObject

Returns the value of attribute cache_dirs.



6
7
8
# File 'lib/inploy/deploy.rb', line 6

def cache_dirs
  @cache_dirs
end

#environmentObject

Returns the value of attribute environment.



6
7
8
# File 'lib/inploy/deploy.rb', line 6

def environment
  @environment
end

#hostsObject

Returns the value of attribute hosts.



6
7
8
# File 'lib/inploy/deploy.rb', line 6

def hosts
  @hosts
end

#login_shellObject

Returns the value of attribute login_shell.



6
7
8
# File 'lib/inploy/deploy.rb', line 6

def 
  @login_shell
end

#pathObject

Returns the value of attribute path.



6
7
8
# File 'lib/inploy/deploy.rb', line 6

def path
  @path
end

#portObject

Returns the value of attribute port.



6
7
8
# File 'lib/inploy/deploy.rb', line 6

def port
  @port
end

#repositoryObject

Returns the value of attribute repository.



6
7
8
# File 'lib/inploy/deploy.rb', line 6

def repository
  @repository
end

#skip_stepsObject

Returns the value of attribute skip_steps.



6
7
8
# File 'lib/inploy/deploy.rb', line 6

def skip_steps
  @skip_steps
end

#ssh_optsObject

Returns the value of attribute ssh_opts.



6
7
8
# File 'lib/inploy/deploy.rb', line 6

def ssh_opts
  @ssh_opts
end

#sudoObject

Returns the value of attribute sudo.



6
7
8
# File 'lib/inploy/deploy.rb', line 6

def sudo
  @sudo
end

#userObject

Returns the value of attribute user.



6
7
8
# File 'lib/inploy/deploy.rb', line 6

def user
  @user
end

Instance Method Details

#configureObject



29
30
31
# File 'lib/inploy/deploy.rb', line 29

def configure
  configure_from configuration_file if configuration_file
end

#configure_from(file) ⇒ Object



33
34
35
36
# File 'lib/inploy/deploy.rb', line 33

def configure_from(file)
  deploy = self
  eval file.read + ';local_variables.each { |variable| deploy.send "#{variable}=", eval(variable.to_s) rescue nil }'
end

#local_setupObject



46
47
48
49
50
51
52
53
54
# File 'lib/inploy/deploy.rb', line 46

def local_setup
  create_folders 'public', 'tmp/pids', 'db'
  callback :after_git
  copy_sample_files
  rake "db:create RAILS_ENV=#{environment}"
  run "./init.sh" if file_exists?("init.sh")
  after_update_code
  callback :after_setup
end

#local_updateObject



70
71
72
73
# File 'lib/inploy/deploy.rb', line 70

def local_update
  update_code
  after_update_code
end

#remote_install(opts) ⇒ Object



38
39
40
# File 'lib/inploy/deploy.rb', line 38

def remote_install(opts)
  remote_run "bash < <(wget -O- #{opts[:from]})"
end

#remote_rake(task) ⇒ Object



60
61
62
# File 'lib/inploy/deploy.rb', line 60

def remote_rake(task)
  remote_run "cd #{application_path} && rake #{task} RAILS_ENV=#{environment}"
end

#remote_reset(params) ⇒ Object



64
65
66
67
68
# File 'lib/inploy/deploy.rb', line 64

def remote_reset(params)
  callback :before_git
  remote_run "cd #{application_path} && git reset --hard #{params[:to]}"
  callback :after_git
end

#remote_setupObject



42
43
44
# File 'lib/inploy/deploy.rb', line 42

def remote_setup
  remote_run "cd #{path} && #{sudo_if_should}git clone --depth 1 #{repository} #{application} && cd #{application_folder} #{checkout}#{bundle} && #{sudo_if_should}rake inploy:local:setup RAILS_ENV=#{environment} environment=#{environment}#{skip_steps_cmd}"
end

#remote_updateObject



56
57
58
# File 'lib/inploy/deploy.rb', line 56

def remote_update
  remote_run "cd #{application_path} && #{sudo_if_should}rake inploy:local:update RAILS_ENV=#{environment} environment=#{environment}#{skip_steps_cmd}"
end

#server=(server) ⇒ Object



25
26
27
# File 'lib/inploy/deploy.rb', line 25

def server=(server)
  load_module "servers/#{server}"
end

#template=(template) ⇒ Object



21
22
23
# File 'lib/inploy/deploy.rb', line 21

def template=(template)
  load_module "templates/#{template}"
end

#update_codeObject



75
76
77
78
79
# File 'lib/inploy/deploy.rb', line 75

def update_code
  callback :before_git
  raise "ERROR: git pull failed with error status = #{$?}" unless run "git pull origin #{branch}"
  callback :after_git
end