negroku 2.0.0.pre2 → 2.0.0.pre3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +2 -0
- data/Rakefile +1 -44
- data/lib/negroku/cli/bootstrap.rb +11 -92
- data/lib/negroku/cli/commands/app.rb +0 -23
- data/lib/negroku/cli/commands/env.rb +14 -0
- data/lib/negroku/cli/commands/stage.rb +16 -0
- data/lib/negroku/cli/env.rb +57 -0
- data/lib/negroku/cli/stage.rb +88 -0
- data/lib/negroku/cli.rb +15 -0
- data/lib/negroku/formatters/simple.rb +0 -2
- data/lib/negroku/helpers/app_directory.rb +22 -0
- data/lib/negroku/helpers/env.rb +10 -0
- data/lib/negroku/helpers/logs.rb +9 -0
- data/lib/negroku/helpers/templates.rb +35 -0
- data/lib/negroku/helpers.rb +4 -9
- data/lib/negroku/i18n.rb +3 -11
- data/lib/negroku/locales/en.yml +19 -0
- data/lib/negroku/tasks/rails.rake +22 -0
- data/lib/negroku/tasks/rbenv.rake +11 -9
- data/lib/negroku/tasks/unicorn.rake +8 -5
- data/lib/negroku/templates/negroku/deploy.rb.erb +4 -11
- data/lib/negroku/templates/negroku/stage.rb.erb +4 -4
- data/lib/negroku/version.rb +1 -1
- data/negroku.gemspec +13 -12
- data/spec/lib/cli/bootstrap_spec.rb +46 -0
- data/spec/lib/cli/env_spec.rb +49 -0
- data/spec/lib/cli/stage_spec.rb +79 -0
- data/spec/spec_helper.rb +15 -0
- metadata +79 -53
- data/test/default_test.rb +0 -14
- data/test/test_helper.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2304543c710a4d86a60f368a026e53ae593f8d5
|
4
|
+
data.tar.gz: e9046a6bfcffe5db9bfc4c55262b9d030b08537e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26513388eb619bcb04ee854a1a24831e1ee90f6cca7ce9a4264d6fb4af35eff5bd37f27a4a8c1adc79d4ff0b0711cfed4a8f4f80ae01e29af95532071ccc4cf6
|
7
|
+
data.tar.gz: 502dbf0589cbc762fd46ab1c1b1bf02455665cb2edc1ffe8c6f6dbb7a46668e8c2c4a578fa3c44450e3dec558dbd59751d48a4666819cda82a7b150ccd62f6ef
|
data/.rspec
ADDED
data/Rakefile
CHANGED
@@ -1,44 +1 @@
|
|
1
|
-
require
|
2
|
-
require 'rubygems'
|
3
|
-
require 'rubygems/package_task'
|
4
|
-
require 'rdoc/task'
|
5
|
-
require 'cucumber'
|
6
|
-
require 'cucumber/rake/task'
|
7
|
-
Rake::RDocTask.new do |rd|
|
8
|
-
rd.main = "README.rdoc"
|
9
|
-
rd.rdoc_files.include("README.rdoc","lib/**/*.rb","bin/**/*")
|
10
|
-
rd.title = 'Negroku'
|
11
|
-
end
|
12
|
-
|
13
|
-
spec = eval(File.read('negroku.gemspec'))
|
14
|
-
|
15
|
-
Gem::PackageTask.new(spec) do |pkg|
|
16
|
-
end
|
17
|
-
CUKE_RESULTS = 'results.html'
|
18
|
-
CLEAN << CUKE_RESULTS
|
19
|
-
desc 'Run features'
|
20
|
-
Cucumber::Rake::Task.new(:features) do |t|
|
21
|
-
opts = "features --format html -o #{CUKE_RESULTS} --format progress -x"
|
22
|
-
opts += " --tags #{ENV['TAGS']}" if ENV['TAGS']
|
23
|
-
t.cucumber_opts = opts
|
24
|
-
t.fork = false
|
25
|
-
end
|
26
|
-
|
27
|
-
desc 'Run features tagged as work-in-progress (@wip)'
|
28
|
-
Cucumber::Rake::Task.new('features:wip') do |t|
|
29
|
-
tag_opts = ' --tags ~@pending'
|
30
|
-
tag_opts = ' --tags @wip'
|
31
|
-
t.cucumber_opts = "features --format html -o #{CUKE_RESULTS} --format pretty -x -s#{tag_opts}"
|
32
|
-
t.fork = false
|
33
|
-
end
|
34
|
-
|
35
|
-
task :cucumber => :features
|
36
|
-
task 'cucumber:wip' => 'features:wip'
|
37
|
-
task :wip => 'features:wip'
|
38
|
-
require 'rake/testtask'
|
39
|
-
Rake::TestTask.new do |t|
|
40
|
-
t.libs << "test"
|
41
|
-
t.test_files = FileList['test/*_test.rb']
|
42
|
-
end
|
43
|
-
|
44
|
-
task :default => [:test,:features]
|
1
|
+
require "bundler/gem_tasks"
|
@@ -1,6 +1,3 @@
|
|
1
|
-
require 'erb'
|
2
|
-
require 'pathname'
|
3
|
-
|
4
1
|
module Negroku::Bootstrap
|
5
2
|
extend self
|
6
3
|
|
@@ -10,103 +7,40 @@ module Negroku::Bootstrap
|
|
10
7
|
data[:application_name] = ask_name
|
11
8
|
data[:repo_url] = select_repo
|
12
9
|
|
13
|
-
custom_capify
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
def add_stage(stage=nil)
|
18
|
-
|
19
|
-
if stage.nil?
|
20
|
-
name = ask_stage
|
21
|
-
end
|
22
|
-
|
23
|
-
custom_stage(name)
|
10
|
+
custom_capify data
|
24
11
|
|
25
12
|
end
|
26
13
|
|
27
|
-
def remove_stage(stage=nil)
|
28
|
-
|
29
|
-
current_stages = Dir[File.join(@deploy_dir, '*.rb')].map(){|f| File.basename(f)}
|
30
|
-
|
31
|
-
if stage.nil?
|
32
|
-
selections = Ask.checkbox "What stages you want to remove", current_stages
|
33
|
-
stages_to_delete = selections.map.with_index { |v, i| current_stages[i] if v}.compact
|
34
|
-
else
|
35
|
-
stages_to_delete = ["#{stage}.rb"]
|
36
|
-
end
|
37
|
-
|
38
|
-
if stages_to_delete.count > 0
|
39
|
-
stages_to_delete.each do |s|
|
40
|
-
path_to_delete = File.join(@deploy_dir, s)
|
41
|
-
begin
|
42
|
-
FileUtils.rm(path_to_delete)
|
43
|
-
rescue
|
44
|
-
puts "The stage '#{s}' doesn't exist"
|
45
|
-
end
|
46
|
-
end
|
47
|
-
else
|
48
|
-
puts "Nothing to do"
|
49
|
-
end
|
50
|
-
|
51
|
-
end
|
52
14
|
|
53
15
|
private
|
54
16
|
|
55
|
-
@tasks_dir = Pathname.new('lib/capistrano/tasks')
|
56
|
-
@config_dir = Pathname.new('config')
|
57
|
-
@deploy_dir = @config_dir.join('deploy')
|
58
|
-
|
59
|
-
@deploy_rb = File.expand_path("../../templates/negroku/deploy.rb.erb", __FILE__)
|
60
|
-
@stage_rb = File.expand_path("../../templates/negroku/stage.rb.erb", __FILE__)
|
61
|
-
@capfile = File.expand_path("../../templates/negroku/Capfile.erb", __FILE__)
|
62
|
-
|
63
17
|
# This code was exatracted from capistrano to be used with our own templates
|
64
18
|
# https://github.com/capistrano/capistrano/blob/68e7632c5f16823a09c324d556a208e096abee62/lib/capistrano/tasks/install.rake
|
65
|
-
def custom_capify(
|
66
|
-
|
67
|
-
|
19
|
+
def custom_capify(data={})
|
20
|
+
# defaults
|
21
|
+
data[:server_url] = ""
|
22
|
+
data[:branch] = "master"
|
68
23
|
|
69
|
-
|
70
|
-
file = @config_dir.join('deploy.rb')
|
71
|
-
File.open(file, 'w+') do |f|
|
72
|
-
f.write(ERB.new(template).result(binding))
|
73
|
-
puts I18n.t(:written_file, scope: :negroku, file: file)
|
74
|
-
end
|
24
|
+
FileUtils.mkdir_p AppDirectory.deploy
|
75
25
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
f.write(ERB.new(template).result(binding))
|
81
|
-
puts I18n.t(:written_file, scope: :negroku, file: file)
|
82
|
-
end
|
83
|
-
end
|
26
|
+
deploy_rb = AppDirectory.config.join('deploy.rb')
|
27
|
+
capfile = AppDirectory.root.join('Capfile')
|
28
|
+
build_template("negroku/deploy.rb.erb", deploy_rb, binding)
|
29
|
+
build_template('negroku/Capfile.erb', capfile, binding)
|
84
30
|
|
85
|
-
FileUtils.mkdir_p
|
86
|
-
|
87
|
-
FileUtils.cp(@capfile, 'Capfile')
|
31
|
+
FileUtils.mkdir_p AppDirectory.tasks
|
88
32
|
|
89
33
|
|
90
34
|
puts I18n.t :capified, scope: :negroku
|
91
35
|
|
92
36
|
end
|
93
37
|
|
94
|
-
def custom_stage(stage, data={})
|
95
|
-
|
96
|
-
end
|
97
|
-
|
98
38
|
# Ask the application name
|
99
39
|
def ask_name
|
100
40
|
question = I18n.t :application_name, scope: :negroku
|
101
41
|
Ask.input question, default: File.basename(Dir.getwd)
|
102
42
|
end
|
103
43
|
|
104
|
-
# Ask the stage name
|
105
|
-
def ask_stage
|
106
|
-
question = I18n.t :ask_stage_name, scope: :negroku
|
107
|
-
Ask.input question
|
108
|
-
end
|
109
|
-
|
110
44
|
# Get git remotes from current git and ask to select one
|
111
45
|
def select_repo
|
112
46
|
remote_urls = %x(git remote -v 2> /dev/null | awk '{print $2}' | uniq).split("\n")
|
@@ -121,19 +55,4 @@ module Negroku::Bootstrap
|
|
121
55
|
else remote_urls[selected_idx] end
|
122
56
|
end
|
123
57
|
|
124
|
-
# Ask which stages to setup
|
125
|
-
def select_stages
|
126
|
-
default_stages = %w(staging production other)
|
127
|
-
|
128
|
-
question = I18n.t :choose_stages, scope: :negroku
|
129
|
-
selected_idx = Ask.checkbox question, default_stages
|
130
|
-
|
131
|
-
stages = selected_idx.map.with_index { |v, i| default_stages[i] if v}.compact
|
132
|
-
|
133
|
-
if selected_idx.last
|
134
|
-
question = "List the extra stages (comma separated)"
|
135
|
-
stages[0...-1].concat (Ask.input question).split(",").map(&:strip)
|
136
|
-
else stages end
|
137
|
-
end
|
138
|
-
|
139
58
|
end
|
@@ -12,28 +12,5 @@ module Negroku::CLI
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
app.desc 'Bootstrap your application with capistrano and negroku'
|
16
|
-
app.command :stage do |stage|
|
17
|
-
|
18
|
-
stage.desc 'Bootstrap your application with capistrano and negroku'
|
19
|
-
stage.command :add do |add|
|
20
|
-
add.action do |global_options,options,args|
|
21
|
-
|
22
|
-
Negroku::Bootstrap.add_stage
|
23
|
-
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
stage.desc 'Bootstrap your application with capistrano and negroku'
|
28
|
-
stage.command :remove do |remove|
|
29
|
-
remove.action do |global_options,options,args|
|
30
|
-
|
31
|
-
Negroku::Bootstrap.remove_stage args.first
|
32
|
-
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
15
|
end
|
39
16
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Negroku::CLI
|
2
|
+
|
3
|
+
desc 'Manage your apps env variables'
|
4
|
+
command :env do |app|
|
5
|
+
|
6
|
+
app.desc 'Adds multiple variables from rbenv-vars to a server'
|
7
|
+
app.command :bulk do |bulk|
|
8
|
+
bulk.action do |global_options,options,args|
|
9
|
+
Negroku::Env.bulk
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Negroku::CLI
|
2
|
+
|
3
|
+
desc 'Create and manage stages'
|
4
|
+
command :stage do |stage|
|
5
|
+
|
6
|
+
stage.desc 'Adds a new stage'
|
7
|
+
stage.command :add do |add|
|
8
|
+
add.action do |global_options,options,args|
|
9
|
+
|
10
|
+
Negroku::Stage.add
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Negroku::Env
|
2
|
+
extend self
|
3
|
+
|
4
|
+
ENV_FILE = ".rbenv-vars"
|
5
|
+
|
6
|
+
def bulk(selected_stage = nil)
|
7
|
+
if stage = selected_stage || select_stage
|
8
|
+
variables = select_variables
|
9
|
+
if variables.empty?
|
10
|
+
puts I18n.t(:no_variables_added, scope: :negroku)
|
11
|
+
else
|
12
|
+
add_vars_to_stage(stage, variables)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Adds the variables to the selected stage using cap rbenv add
|
18
|
+
def add_vars_to_stage(stage, variables)
|
19
|
+
# convert to array using VAR=value
|
20
|
+
vars_array = variables.map{|k,v| "#{k}=#{v}" }
|
21
|
+
Capistrano::Application.invoke(stage)
|
22
|
+
Capistrano::Application.invoke("rbenv:vars:add", *vars_array)
|
23
|
+
end
|
24
|
+
|
25
|
+
# build a list of variables from ENV_FILE and yeilds it
|
26
|
+
def get_variables
|
27
|
+
return unless File.exists?(ENV_FILE)
|
28
|
+
|
29
|
+
File.open(ENV_FILE).each do |line|
|
30
|
+
var_name = line.split("=").first
|
31
|
+
yield var_name unless line =~ /^\#/
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Returns a hash of selected variables and values
|
36
|
+
def select_variables
|
37
|
+
selection = {}
|
38
|
+
puts I18n.t(:ask_variables_message, scope: :negroku)
|
39
|
+
get_variables do |var_name|
|
40
|
+
selection[var_name] = Ask.input(var_name)
|
41
|
+
end
|
42
|
+
selection.reject {|key, value| value.empty? }
|
43
|
+
end
|
44
|
+
|
45
|
+
def select_stage
|
46
|
+
if current_stages.empty?
|
47
|
+
puts I18n.t(:no_stages_found, scope: :negroku)
|
48
|
+
else
|
49
|
+
selection = Ask.list I18n.t(:select_stages_question, scope: :negroku), current_stages
|
50
|
+
current_stages[selection]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def current_stages
|
55
|
+
@current_stages ||= Capistrano::Application.stages
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module Negroku::Stage
|
2
|
+
extend self
|
3
|
+
|
4
|
+
def add
|
5
|
+
config = {
|
6
|
+
stage_name: ask_stage,
|
7
|
+
branch: select_branch,
|
8
|
+
domains: ask_domains,
|
9
|
+
server_url: ask_server_url
|
10
|
+
}
|
11
|
+
|
12
|
+
add_stage_file config
|
13
|
+
Negroku::Env.bulk(config[:stage_name]) if ask_add_vars
|
14
|
+
end
|
15
|
+
|
16
|
+
def ask_add_vars
|
17
|
+
question = I18n.t :ask_add_vars, scope: :negroku
|
18
|
+
Ask.confirm question, default: false
|
19
|
+
end
|
20
|
+
|
21
|
+
def add_stage_file(data)
|
22
|
+
destination = AppDirectory.deploy.join("#{data[:stage_name]}.rb")
|
23
|
+
|
24
|
+
build_template("negroku/stage.rb.erb", destination, binding)
|
25
|
+
end
|
26
|
+
|
27
|
+
def ask_server_url
|
28
|
+
question = I18n.t :ask_server_url, scope: :negroku
|
29
|
+
Ask.input question
|
30
|
+
end
|
31
|
+
|
32
|
+
def ask_domains
|
33
|
+
question = I18n.t :ask_domains, scope: :negroku
|
34
|
+
Ask.input question
|
35
|
+
end
|
36
|
+
|
37
|
+
def select_branch
|
38
|
+
question = I18n.t :select_branch, scope: :negroku
|
39
|
+
branches = get_remote_branches
|
40
|
+
answer = Ask.list question, branches
|
41
|
+
return branches[answer] unless branches.empty?
|
42
|
+
end
|
43
|
+
|
44
|
+
def get_remote_branches(fetch: false)
|
45
|
+
%x(git fetch) if fetch
|
46
|
+
|
47
|
+
branches = []
|
48
|
+
%x(git branch -r).split.each do |branch|
|
49
|
+
next unless branch.start_with? 'origin'
|
50
|
+
branches << branch.split('/', 2)[1] unless branch =~ /HEAD/
|
51
|
+
end
|
52
|
+
branches.uniq
|
53
|
+
end
|
54
|
+
|
55
|
+
# Ask the stage name
|
56
|
+
def ask_stage
|
57
|
+
question = I18n.t :ask_stage_name, scope: :negroku
|
58
|
+
stage_name = Ask.input question
|
59
|
+
raise "Stage name required" if stage_name.empty?
|
60
|
+
stage_name
|
61
|
+
end
|
62
|
+
|
63
|
+
def remove_stage(stage=nil)
|
64
|
+
|
65
|
+
current_stages = Dir[File.join(@deploy_dir, '*.rb')].map(){|f| File.basename(f)}
|
66
|
+
|
67
|
+
if stage.nil?
|
68
|
+
selections = Ask.checkbox "What stages you want to remove", current_stages
|
69
|
+
stages_to_delete = selections.map.with_index { |v, i| current_stages[i] if v}.compact
|
70
|
+
else
|
71
|
+
stages_to_delete = ["#{stage}.rb"]
|
72
|
+
end
|
73
|
+
|
74
|
+
if stages_to_delete.count > 0
|
75
|
+
stages_to_delete.each do |s|
|
76
|
+
path_to_delete = File.join(@deploy_dir, s)
|
77
|
+
begin
|
78
|
+
FileUtils.rm(path_to_delete)
|
79
|
+
rescue
|
80
|
+
puts "The stage '#{s}' doesn't exist"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
else
|
84
|
+
puts "Nothing to do"
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
end
|
data/lib/negroku/cli.rb
CHANGED
@@ -1,8 +1,23 @@
|
|
1
|
+
require 'capistrano/all'
|
2
|
+
require 'capistrano/setup'
|
3
|
+
require 'capistrano/deploy'
|
4
|
+
|
5
|
+
# Load applications deploy config if it exists
|
6
|
+
require './config/deploy' if File.exists? "./config/deploy"
|
7
|
+
|
1
8
|
require 'gli'
|
2
9
|
require 'inquirer'
|
3
10
|
require 'negroku/i18n'
|
4
11
|
require 'negroku/version'
|
5
12
|
require 'negroku/cli/bootstrap'
|
13
|
+
require 'negroku/cli/stage'
|
14
|
+
require 'negroku/cli/env'
|
15
|
+
require 'negroku/helpers/app_directory'
|
16
|
+
require 'negroku/helpers/templates'
|
17
|
+
|
18
|
+
require 'capistrano/rbenv'
|
19
|
+
require 'negroku/deploy'
|
20
|
+
|
6
21
|
|
7
22
|
module Negroku::CLI
|
8
23
|
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
module AppDirectory
|
4
|
+
extend self
|
5
|
+
|
6
|
+
def config
|
7
|
+
@config ||= Pathname.new('config')
|
8
|
+
end
|
9
|
+
|
10
|
+
def root
|
11
|
+
@root ||= Pathname.new('')
|
12
|
+
end
|
13
|
+
|
14
|
+
def deploy
|
15
|
+
config.join('deploy')
|
16
|
+
end
|
17
|
+
|
18
|
+
def tasks
|
19
|
+
@tasks ||= Pathname.new('lib/capistrano/tasks')
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# helper to build the add VAR cmd
|
2
|
+
def build_add_var_cmd(vars_file, key, value)
|
3
|
+
puts "#{vars_file} #{key} #{value}"
|
4
|
+
cmd = "if awk < #{vars_file} -F= '{print $1}' | grep --quiet -w #{key}; then "
|
5
|
+
cmd += "sed -i 's/^#{key}=.*/#{key}=#{value.gsub("\/", "\\/")}/g' #{vars_file};"
|
6
|
+
cmd += "else echo '#{key}=#{value}' >> #{vars_file};"
|
7
|
+
cmd += "fi"
|
8
|
+
cmd
|
9
|
+
end
|
10
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require "erb"
|
2
|
+
|
3
|
+
# Build the template
|
4
|
+
def build_template(template, destination, binding)
|
5
|
+
template_file = get_template_file(template)
|
6
|
+
|
7
|
+
result = ERB.new(template_file, nil, '-').result(binding)
|
8
|
+
|
9
|
+
if destination
|
10
|
+
File.open(destination.to_s, 'w+') do |f|
|
11
|
+
f.write(result)
|
12
|
+
end
|
13
|
+
|
14
|
+
puts I18n.t(:written_file, scope: :negroku, file: destination)
|
15
|
+
else
|
16
|
+
return StringIO.new(result)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Render one nested error partial
|
21
|
+
def partial(filename, binding)
|
22
|
+
template_file = get_template_file(filename)
|
23
|
+
ERB.new(template_file, nil, '-', '_erbout2').result(binding)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Get the template file from the project and fallback to the gem
|
27
|
+
def get_template_file(filename)
|
28
|
+
if File.exists?(filename)
|
29
|
+
templateFile = filename
|
30
|
+
else
|
31
|
+
templateFile = File.expand_path("../../templates/#{filename}", __FILE__)
|
32
|
+
end
|
33
|
+
|
34
|
+
File.read(templateFile)
|
35
|
+
end
|
data/lib/negroku/helpers.rb
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
require 'negroku/helpers/templates'
|
2
|
+
require 'negroku/helpers/logs'
|
3
|
+
require 'negroku/helpers/env'
|
4
|
+
|
1
5
|
# Find out if a specific library file was already required
|
2
6
|
def was_required?(file)
|
3
7
|
rex = Regexp.new("/#{Regexp.quote(file)}\.(so|o|sl|rb)?")
|
@@ -7,12 +11,3 @@ end
|
|
7
11
|
def load_task(name)
|
8
12
|
load File.join(File.dirname(__FILE__), 'tasks', "#{name}.rake")
|
9
13
|
end
|
10
|
-
|
11
|
-
# Define los
|
12
|
-
def define_logs(namespace, hash)
|
13
|
-
logs = fetch(:negroku_logs, {})
|
14
|
-
|
15
|
-
logs[namespace] = hash
|
16
|
-
|
17
|
-
set :negroku_logs, logs
|
18
|
-
end
|
data/lib/negroku/i18n.rb
CHANGED
@@ -1,17 +1,9 @@
|
|
1
1
|
require 'i18n'
|
2
2
|
require 'set'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
application_name: 'Give your application a name',
|
8
|
-
other: 'Other',
|
9
|
-
choose_repo_url: 'Choose the repository url',
|
10
|
-
type_repo_url: 'Type the url and username e.g. git@github.com:username/app-name.git',
|
11
|
-
choose_stages: 'Select the stages you are going to use'
|
12
|
-
}
|
13
|
-
|
14
|
-
I18n.backend.store_translations(:en, { negroku: en })
|
4
|
+
locale_path = File.join(File.dirname(__FILE__), 'locales')
|
5
|
+
I18n.load_path = Dir[File.join(locale_path, '*.yml')]
|
6
|
+
I18n.backend.load_translations
|
15
7
|
|
16
8
|
if I18n.respond_to?(:enforce_available_locales=)
|
17
9
|
I18n.enforce_available_locales = true
|
@@ -0,0 +1,19 @@
|
|
1
|
+
en:
|
2
|
+
negroku:
|
3
|
+
capified: "Capified"
|
4
|
+
written_file: 'create %{file}'
|
5
|
+
application_name: 'Give your application a name'
|
6
|
+
other: 'Other'
|
7
|
+
choose_repo_url: 'Choose the repository url'
|
8
|
+
type_repo_url: 'Type the url and username e.g. git@github.com:username/app-name.git'
|
9
|
+
choose_stages: 'Select the stages you are going to use'
|
10
|
+
select_stages_question: 'Select stages you want to add variables to'
|
11
|
+
no_variables_added: 'No variables added'
|
12
|
+
ask_variables_message: "Give the variables values, if empty, it will be ignored"
|
13
|
+
rbenv_vars_not_found: ".rbenv-vars does not exists"
|
14
|
+
no_stages_found: "There are no stages available"
|
15
|
+
ask_stage_name: "Stage name"
|
16
|
+
select_branch: "Select the branch to use"
|
17
|
+
ask_domains: "Type the domains to use"
|
18
|
+
ask_server_url: "Type the server url to deploy to"
|
19
|
+
ask_add_vars: "Do you want to add rbenv-vars to the server now?"
|
@@ -9,6 +9,28 @@ namespace :load do
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
+
namespace :rails do
|
13
|
+
desc "Open the rails console on the primary remote app server"
|
14
|
+
task :console do
|
15
|
+
on roles(:app), :primary => true do |host|
|
16
|
+
execute_interactively host, "console #{fetch(:rails_env)}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
desc "Open the rails dbconsole on the primary remote app server"
|
21
|
+
task :dbconsole do
|
22
|
+
on roles(:app), :primary => true do |host|
|
23
|
+
execute_interactively host, "dbconsole #{fetch(:rails_env)}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def execute_interactively(host, command)
|
28
|
+
command = "cd #{fetch(:deploy_to)}/current && #{SSHKit.config.command_map[:bundle]} exec rails #{command}"
|
29
|
+
puts command if fetch(:log_level) == :debug
|
30
|
+
exec "ssh -l #{host.user} #{host.hostname} -p #{host.port || 22} -t '#{command}'"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
12
34
|
namespace :negroku do
|
13
35
|
|
14
36
|
namespace :rails do
|
@@ -25,22 +25,24 @@ namespace :rbenv do
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
desc "Add environmental
|
29
|
-
task :add,
|
30
|
-
|
31
|
-
|
28
|
+
desc "Add environmental variables in the form VAR=value"
|
29
|
+
task :add, :variable do |t, args|
|
30
|
+
|
31
|
+
vars = [args.variable] + args.extras
|
32
|
+
|
32
33
|
on release_roles :app do
|
33
34
|
within shared_path do
|
34
35
|
unless test "[ ! -f .rbenv-vars ]"
|
35
36
|
execute :touch, ".rbenv-vars"
|
36
37
|
end
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
38
|
+
vars.compact.each do |var|
|
39
|
+
key, value = var.split('=')
|
40
|
+
cmd = build_add_var_cmd("#{shared_path}/.rbenv-vars", key, value)
|
41
|
+
execute cmd
|
42
|
+
end
|
42
43
|
end
|
43
44
|
end
|
45
|
+
|
44
46
|
end
|
45
47
|
|
46
48
|
desc "Remove environmental variable"
|
@@ -60,12 +60,15 @@ namespace :negroku do
|
|
60
60
|
task :setup do
|
61
61
|
on release_roles fetch(:unicorn_roles) do
|
62
62
|
within "#{shared_path}/config" do
|
63
|
-
|
64
|
-
|
65
|
-
|
63
|
+
template_path = fetch(:unicorn_template)
|
64
|
+
|
65
|
+
# user a build in template if the template doesn't exists in the project
|
66
|
+
unless File.exists?(template_path)
|
67
|
+
template_path = "tasks/unicorn_#{fetch(:unicorn_template_type)}.rb.erb"
|
66
68
|
end
|
67
|
-
|
68
|
-
|
69
|
+
|
70
|
+
config = build_template(template_path, nil, binding)
|
71
|
+
upload! config, '/tmp/unicorn.rb'
|
69
72
|
|
70
73
|
execute :mv, '/tmp/unicorn.rb', 'unicorn.rb'
|
71
74
|
end
|