Top Level Namespace

Defined Under Namespace

Modules: Negroku Classes: App, Capfile, Konfig, RemoteEnv, Target

Instance Method Summary collapse

Instance Method Details

#baseObject

Load Deployment Tasks



34
# File 'lib/negroku/deploy.rb', line 34

load_tasks('base')

#default_environmentObject

Default path



19
20
21
# File 'lib/negroku/deploy.rb', line 19

set :default_environment, {
  'PATH' => "$HOME/.rbenv/shims:$HOME/.rbenv/bin:$HOME/.nodenv/shims:$HOME/.nodenv/bin:$PATH"
}

#getConfigObject



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/negroku/config.rb', line 25

def getConfig
  # load config from file
  config_file = File.join(ENV['HOME'], ".negroku")

  # create an empty .negroku file
  unless File.exist?(config_file)
    %x(touch #{config_file})
  end

  # base config
  YAML.load_file(config_file) || {}
end

#getTemplate(template) ⇒ Object



78
79
80
# File 'lib/negroku/helpers.rb', line 78

def getTemplate(template)
  File.read(File.join(File.dirname(__FILE__), 'templates', template))
end

#init(target = ".", data) ⇒ Object



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/negroku/helpers.rb', line 1

def init(target=".", data)

  # Main locations
  target_path    = File.expand_path(target)
  config_path = File.join(target_path, "config")
  deploy_path = File.join(target_path, "config", "deploy")
  capfile = File.join(target_path, "Capfile")
  deployfile = File.join(config_path, "deploy.rb")
  stagingfile = File.join(deploy_path, "staging.rb")
  productionfile = File.join(deploy_path, "production.rb")

  # Create the cap file if not found
  if Dir.entries(target_path).include?("Capfile")
    puts "[Negroku] => Found Capfile!"
  else
    puts "[Negroku] => Capifying!"
    `capify #{target_path}`
  end

  # Find or create config folder
  unless File.directory?(config_path)
    puts "[Negroku] => Could not find the \"config\" folder. Creating it now!"
    %x(mkdir #{config_path})
  end

  # Find or create deploy folder
  unless File.directory?(deploy_path)
    puts "[Negroku] => Could not find the \"deploy\" folder. Creating it now!"
    %x(mkdir #{deploy_path})
  end

  # replace and rename older deploy.rb
  if File.exist?(deployfile)
    puts "[Negroku] => Backing up deploy.rb"
    old_versions = Dir.entries(config_path).map {|entree| entree if entree =~ /deploy\.old\.(\d+)\.rb$/}.compact!
    if old_versions.empty?
      %x(mv #{deployfile} #{File.join(config_path, 'deploy.old.1.rb')})
    else
      version = old_versions.last.match('^deploy\.old\.(\d+)\.rb$')[1].to_i + 1
      %x(mv #{deployfile} #{File.join(config_path, "deploy.old.#{version}.rb")})
    end
  end

  # Create the new deploy
  puts "[Negroku] => Writing new deploy.rb."
  erb = getTemplate 'deploy.rb.erb'
  File.open(deployfile, 'w') do |f|
    f.write ERB.new(erb).result(binding)
  end

  # Create the new configuration stages
  puts "[Negroku] => Writing new deploy/staging.rb"
  erb = getTemplate 'staging.rb.erb'
  File.open(stagingfile, 'w') do |f|
    f.write ERB.new(erb).result(binding)
  end
  puts "[Negroku] => Writing new deploy/production.rb"
  erb = getTemplate 'production.rb.erb'
  File.open(productionfile, 'w') do |f|
    f.write ERB.new(erb).result(binding)
  end

  # Prepares the Capfile for negroku
  cfile = Capfile.new(capfile)
  cfile.assets()
  puts "[Negroku] => Enabling assets tasks."
  cfile.negroku()
  puts "[Negroku] => Adding Negroku Loader inside #{capfile}."

end

#joinObject

Load Deployer Helpers



3
# File 'lib/negroku/deploy.rb', line 3

require File.join(File.dirname(__FILE__), 'helpers')

#load_tasks(tasks) ⇒ Object

Helper Method that assists in loading in tasks from the tasks folder



84
85
86
# File 'lib/negroku/helpers.rb', line 84

def load_tasks(tasks)
  load File.join(File.dirname(__FILE__), 'tasks', "#{tasks}.rb")
end

#negrokuObject

Returns a path that can be loaded by the “load” method inside the Capfile



5
6
7
# File 'lib/negroku.rb', line 5

def negroku
  File.join(File.dirname(__FILE__), 'negroku', 'deploy.rb')
end

#remoteObject

Default Configuration



12
# File 'lib/negroku/deploy.rb', line 12

set :remote, 'origin'

#saveConfig(action, type, data) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/negroku/config.rb', line 3

def saveConfig(action, type, data)
  # Load the yaml file
  config_file = File.join(ENV['HOME'], ".negroku")
  config = getConfig

  # If I need to add some multiple values
  if action === :add
    newData = config[type] || []
    newData.push(data)
    newData.uniq!
    config = config.merge({ type => newData })
  elsif action === :remove
    #..
  elsif action === :replace
    #..
  end

  File.open(config_file, 'w') do |f|
    f.write config.to_yaml
  end
end

#set_default(name, *args, &block) ⇒ Object

Wrapper method to set default values for recipes.



9
10
11
# File 'lib/negroku/tasks/base.rb', line 9

def set_default(name, *args, &block)
  set(name, *args, &block) unless exists?(name)
end

#showConfigObject



72
73
74
75
76
# File 'lib/negroku/helpers.rb', line 72

def showConfig()
  # Load the yaml file
  config = getConfig
  puts config
end

#template(from, to) ⇒ Object

Wrapper method for quickly loading, rendering ERB templates and uploading them to the server.



3
4
5
6
# File 'lib/negroku/tasks/base.rb', line 3

def template(from, to)
  erb = File.read(File.expand_path("../templates/#{from}", __FILE__))
  put ERB.new(erb).result(binding), to
end