negroku 1.1.14 → 2.0.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +17 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +3 -201
  6. data/README.rdoc +6 -0
  7. data/Rakefile +44 -0
  8. data/bin/negroku +0 -8
  9. data/features/negroku.feature +8 -0
  10. data/features/step_definitions/negroku_steps.rb +6 -0
  11. data/features/support/env.rb +15 -0
  12. data/lib/negroku/cli/bootstrap.rb +139 -0
  13. data/lib/negroku/cli/commands/app.rb +39 -0
  14. data/lib/negroku/cli/commands/negroku.rb +15 -0
  15. data/lib/negroku/cli.rb +19 -206
  16. data/lib/negroku/deploy.rb +14 -36
  17. data/lib/negroku/helpers.rb +6 -83
  18. data/lib/negroku/i18n.rb +17 -0
  19. data/lib/negroku/tasks/bower.rake +12 -0
  20. data/lib/negroku/tasks/bundler.rake +12 -0
  21. data/lib/negroku/tasks/negroku.rake +48 -0
  22. data/lib/negroku/tasks/nginx.rake +24 -0
  23. data/lib/negroku/tasks/nodenv.rake +13 -0
  24. data/lib/negroku/tasks/rbenv.rake +56 -0
  25. data/lib/negroku/tasks/unicorn.rake +92 -0
  26. data/lib/negroku/templates/negroku/Capfile.erb +29 -0
  27. data/lib/negroku/templates/negroku/deploy.rb.erb +47 -0
  28. data/lib/negroku/templates/negroku/stage.rb.erb +13 -0
  29. data/lib/negroku/templates/tasks/unicorn_rails.rb.erb +40 -0
  30. data/lib/negroku/{tasks/templates/unicorn.erb → templates/tasks/unicorn_rails_activerecord.rb.erb} +5 -5
  31. data/lib/negroku/version.rb +1 -1
  32. data/lib/negroku.rb +4 -6
  33. data/negroku.gemspec +42 -0
  34. data/negroku.rdoc +5 -0
  35. data/test/default_test.rb +14 -0
  36. data/test/test_helper.rb +9 -0
  37. metadata +252 -51
  38. data/lib/negroku/capfile.rb +0 -32
  39. data/lib/negroku/config.rb +0 -36
  40. data/lib/negroku/tasks/base.rb +0 -29
  41. data/lib/negroku/tasks/bower.rb +0 -9
  42. data/lib/negroku/tasks/log.rb +0 -25
  43. data/lib/negroku/tasks/nginx.rb +0 -61
  44. data/lib/negroku/tasks/rbenv.rb +0 -27
  45. data/lib/negroku/tasks/templates/nginx.erb +0 -90
  46. data/lib/negroku/tasks/unicorn.rb +0 -47
  47. data/lib/negroku/templates/deploy.rb.erb +0 -24
  48. data/lib/negroku/templates/production.rb.erb +0 -14
  49. data/lib/negroku/templates/staging.rb.erb +0 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 00c282d03f5f541227804a784fbc57381fff8ddd
4
- data.tar.gz: 1fc7b07688546bd23134650dc793e1b2d2591ca9
3
+ metadata.gz: 827bfba759edd4825969e04d56bbec0e8c98d4ae
4
+ data.tar.gz: 7e624982d506520b2d10749ed70cf31705801c06
5
5
  SHA512:
6
- metadata.gz: 3b5e451d53b63ef89a164636cbed57775e3f3ad0c3e4f3fad0888e9beaa7ce59cff5b0a54419717806976dd7895fc9865316375095fecd469b6c93c693da79f6
7
- data.tar.gz: c10fe9ae6cd41b034aa86aab80e9f803516d61f9f37bb981996e53523580f1dd1e2968bf374c3b15ae718ef3b026201933139012e5562e48269bac94a069d621
6
+ metadata.gz: 5157300976ec2c0442401f1418845065e867bd32fadc83a6a6145c40f0e1d43d6f2291b138b7b85c74fcd2fa4ed032e18e90c4969b011788f9998202a53400af
7
+ data.tar.gz: 50065eddd201663c94b969b9f66ffbf4e19b1c5019a06434bf8d97f62379f1aa5eb3373b198b63e97e828d9ab4352deffb18d93d0a8b1a1fa71ec0597c62aec7
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
4
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Juan Ignacio Donoso
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -3,211 +3,13 @@ Negroku [![Stories in Ready](https://badge.waffle.io/platanus/negroku.svg)](http
3
3
 
4
4
  Negroku is an opinionated collection of recipes for capistrano.
5
5
 
6
- The goal is to be able to deploy **ruby on rails applications** and **static websites** without the hassle of configuring and defining all the stuff involved in an application deployment.
6
+ The goal is to be able to deploy **ruby on rails applications** and **static websites** without the hassle of configure and define all the stuff involved in an application deployment.
7
7
 
8
- All the server settings pre-defined in the configuration files generated by negroku are targeted to this server generic [configuration guide](https://github.com/platanus/guides/tree/master/deployment). Although in most cases you can customize those settings.
8
+ All the server configurations pre-defined in the configuration files generated by negroku are targeted oto this generic [configuration guide](https://github.com/platanus/guides/tree/master/deployment).
9
9
 
10
- Installation
11
- ------------
10
+ ## This is a rewrite that will use capistrano 3
12
11
 
13
- Install negroku as a global gem.
14
12
 
15
- ```shell
16
- $ gem install negroku
17
- ```
18
13
 
19
- Add the negroku gem to your `Gemfile` development group to lock the version your are going to use.
20
-
21
- ```ruby
22
- group :development do
23
- gem 'negroku', '1.1.4'
24
- end
25
- ```
26
-
27
- You will need to add to your Gemfile these two gems:
28
-
29
- ```ruby
30
- group :assets do
31
- gem 'therubyracer', :platforms => :ruby
32
- end
33
-
34
- group :production do
35
- gem 'unicorn'
36
- end
37
- ```
38
-
39
- Then execute
40
-
41
- ```shell
42
- $ bundle install
43
- ```
44
-
45
- **Note:** Add the `therubyracer` gem only if your are going to use the assets precompile of a rails project.
46
-
47
- ## Getting started
48
-
49
- 1. Create your app executing the following command, and just follow the on-screen questions.
50
-
51
- ```
52
- $ negroku app create
53
- ```
54
-
55
- ####Give your application a name
56
-
57
- This will be used to create the app folder structure in the server and to name some files, for example, the log files.
58
-
59
-
60
- ####Please choose your repository
61
-
62
- You'll need to choose the git respository where your are going to store your project. Typically a GitHub repository, it can be any repository that the server has access to.
63
-
64
- If you have already initializated your git repository for the project, you'll be offered to choose the remotes of the current repo.
65
-
66
- ####Target servers
67
-
68
- You'll need to choose the server address where the project will be deployed and the hostname that will be used by *nginx* to host the application. Negroku will ask this for two stage servers (staging, production)
69
-
70
- *Note:* Refer to the [negroku config taks](#config-task) to add some default servers to the negroku configuration.
71
-
72
-
73
- 1. The `app create` command will bootpstrapp your app (behind the scenes it will run the capistrano command `capify .` and add some customizations)
74
-
75
- Some files and folders will be added to your project, this is the same structure that capistrano expects when using multistage extensions
76
-
77
- ```
78
- project_root
79
- |--- Capfile # Capistrano load file
80
- +--- config
81
- |--- deploy.rb # Global setting for all environments
82
- +--- deploy
83
- |--- production.rb # Specific settings for production server
84
- +--- staging.rb # Specific settings for staging server
85
- ```
86
-
87
- 1. Configure your specific settings in the files created above
88
-
89
- ####Common settings for all stages `deploy.rb`
90
-
91
- Here you can add all the settings that are common to all the stage severs.
92
-
93
- ```ruby
94
- #You may want to change the stages and the default stage
95
- set :stages, %w(production staging)
96
- set :default_stage, "staging"
97
- ```
98
-
99
-
100
- ####Per-stage settings `staging.rb` `production.rb`
101
-
102
- Here you can add all the settings that are specific to the stage.
103
-
104
- ```ruby
105
- #You may want to change the repository branch for each stage.
106
- set :branch, "production" # Optional, defaults to master
107
- ```
108
-
109
-
110
- 1. Prepare the server for your application executing
111
-
112
- ```shell
113
- $ cap deploy:setup
114
- ```
115
-
116
- 1. Commit and push the changes to the repository
117
-
118
- 1. Configure all your environmental variables for your project using the [negroku env taks](#env-task)
119
-
120
- 1. Deploy you application for the first time executing
121
-
122
- ```shell
123
- $ cap deploy:cold # for the default stage
124
- $ cap production deploy:cold # for the production stage
125
- ```
126
-
127
- For all the next following deploys, you should execute
128
-
129
- ```shell
130
- $ cap deploy # for the default stage
131
- $ cap production deploy # for the production stage
132
- ```
133
-
134
- The CLI
135
- -------
136
-
137
- Negroku also provides a simple CLI that helps to initialize the deployment of your project and that wraps some tasks from its recipes collection.
138
-
139
- ### App task
140
-
141
- *comming soon...*
142
-
143
- ### Env task
144
-
145
- *comming soon...*
146
-
147
- ### Config task
148
-
149
- *comming soon...*
150
-
151
- Included recipes
152
- ----------------
153
-
154
- To achieve this goal negroku provides a set of pre-configured capistrano recipes and deploy configuration files in order to streamline the process to deploy a new application.
155
-
156
- ### nginx tasks
157
-
158
- ```
159
- cap nginx:reload # reload Nginx.
160
- cap nginx:restart # restart Nginx.
161
- cap nginx:setup # Setup nginx configuration for this applic...
162
- cap nginx:start # start Nginx.
163
- cap nginx:stop # stop Nginx.
164
- cap nginx:upload_ssl_certificates # Upload SSL certificates for this applicat...
165
- ```
166
-
167
- ### unicorn tasks
168
-
169
- ```
170
- cap unicorn:add_worker # Add a new worker
171
- cap unicorn:duplicate # Duplicate Unicorn
172
- cap unicorn:reload # Reload Unicorn
173
- cap unicorn:remove_worker # Remove amount of workers
174
- cap unicorn:restart # Restart Unicorn
175
- cap unicorn:setup # Setup unicorn configuration for this appl...
176
- cap unicorn:shutdown # Immediately shutdown Unicorn
177
- cap unicorn:start # Start Unicorn master process
178
- cap unicorn:stop # Stop Unicorn
179
- ```
180
-
181
- ### logging tasks
182
-
183
- ```
184
- cap log:app # Stream (tail) the application's productio...
185
- cap log:nginx_access # Stream (tail) the nginx access log.
186
- cap log:nginx_error # Stream (tail) the nginx error log.
187
- cap log:unicorn_error # Stream (tail) the unicorn error log.
188
- ```
189
-
190
- ### rbenv task
191
-
192
- ```
193
- cap rbenv:vars:add # Add rbenv vars
194
- cap rbenv:vars:show # Show current rbenv vars
195
- cap rbenv:vars:symlink # Symlink rbenv-vars file into the current ...
196
- ```
197
-
198
-
199
- Customizing the recipes
200
- -----------------------
201
-
202
- Aside of predefining some ways of doing the deployments, negroku is very flexible. This flexibility is inherited from capistrano, so you can extend negroku with your recipes, overide existing ones, and modify every configuration you want.
203
-
204
- Contributing
205
- ------------
206
-
207
- 1. Fork it
208
- 2. Create your feature branch (`git checkout -b my-new-feature`)
209
- 3. Commit your changes (`git commit -am 'Add some feature'`)
210
- 4. Push to the branch (`git push origin my-new-feature`)
211
- 5. Create new Pull Request
212
14
 
213
15
 
data/README.rdoc ADDED
@@ -0,0 +1,6 @@
1
+ = negroku
2
+
3
+ Describe your project here
4
+
5
+ :include:negroku.rdoc
6
+
data/Rakefile ADDED
@@ -0,0 +1,44 @@
1
+ require 'rake/clean'
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]
data/bin/negroku CHANGED
@@ -1,10 +1,2 @@
1
1
  #!/usr/bin/env ruby
2
-
3
- require 'rubygems'
4
- require 'capistrano'
5
- require 'negroku/config'
6
- require 'negroku/helpers'
7
- require 'negroku/capfile'
8
2
  require 'negroku/cli'
9
-
10
- Negroku::CLI.start
@@ -0,0 +1,8 @@
1
+ Feature: My bootstrapped app kinda works
2
+ In order to get going on coding my awesome app
3
+ I want to have aruba and cucumber setup
4
+ So I don't have to do it myself
5
+
6
+ Scenario: App just runs
7
+ When I get help for "negroku"
8
+ Then the exit status should be 0
@@ -0,0 +1,6 @@
1
+ When /^I get help for "([^"]*)"$/ do |app_name|
2
+ @app_name = app_name
3
+ step %(I run `#{app_name} help`)
4
+ end
5
+
6
+ # Add more step definitions here
@@ -0,0 +1,15 @@
1
+ require 'aruba/cucumber'
2
+
3
+ ENV['PATH'] = "#{File.expand_path(File.dirname(__FILE__) + '/../../bin')}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
4
+ LIB_DIR = File.join(File.expand_path(File.dirname(__FILE__)),'..','..','lib')
5
+
6
+ Before do
7
+ # Using "announce" causes massive warnings on 1.9.2
8
+ @puts = true
9
+ @original_rubylib = ENV['RUBYLIB']
10
+ ENV['RUBYLIB'] = LIB_DIR + File::PATH_SEPARATOR + ENV['RUBYLIB'].to_s
11
+ end
12
+
13
+ After do
14
+ ENV['RUBYLIB'] = @original_rubylib
15
+ end
@@ -0,0 +1,139 @@
1
+ require 'erb'
2
+ require 'pathname'
3
+
4
+ module Negroku::Bootstrap
5
+ extend self
6
+
7
+ def install
8
+
9
+ data = {}
10
+ data[:application_name] = ask_name
11
+ data[:repo_url] = select_repo
12
+
13
+ custom_capify select_stages, data
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)
24
+
25
+ end
26
+
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
+
53
+ private
54
+
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
+ # This code was exatracted from capistrano to be used with our own templates
64
+ # https://github.com/capistrano/capistrano/blob/68e7632c5f16823a09c324d556a208e096abee62/lib/capistrano/tasks/install.rake
65
+ def custom_capify(stages, data={})
66
+
67
+ FileUtils.mkdir_p @deploy_dir
68
+
69
+ template = File.read(@deploy_rb)
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
75
+
76
+ template = File.read(@stage_rb)
77
+ stages.each do |stage|
78
+ file = @deploy_dir.join("#{stage}.rb")
79
+ File.open(file, 'w+') do |f|
80
+ f.write(ERB.new(template).result(binding))
81
+ puts I18n.t(:written_file, scope: :negroku, file: file)
82
+ end
83
+ end
84
+
85
+ FileUtils.mkdir_p @tasks_dir
86
+
87
+ FileUtils.cp(@capfile, 'Capfile')
88
+
89
+
90
+ puts I18n.t :capified, scope: :negroku
91
+
92
+ end
93
+
94
+ def custom_stage(stage, data={})
95
+
96
+ end
97
+
98
+ # Ask the application name
99
+ def ask_name
100
+ question = I18n.t :application_name, scope: :negroku
101
+ Ask.input question, default: File.basename(Dir.getwd)
102
+ end
103
+
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
+ # Get git remotes from current git and ask to select one
111
+ def select_repo
112
+ remote_urls = %x(git remote -v 2> /dev/null | awk '{print $2}' | uniq).split("\n")
113
+ remote_urls << (I18n.t :other, scope: :negroku)
114
+
115
+ question = I18n.t :choose_repo_url, scope: :negroku
116
+ selected_idx = Ask.list question, remote_urls
117
+
118
+ if selected_idx == remote_urls.length - 1
119
+ question = I18n.t :type_repo_url, scope: :negroku
120
+ Ask.input question
121
+ else remote_urls[selected_idx] end
122
+ end
123
+
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
+ end
@@ -0,0 +1,39 @@
1
+ module Negroku::CLI
2
+
3
+ desc 'Create and manage your app'
4
+ command :app do |app|
5
+
6
+ app.desc 'Bootstrap your application with capistrano and negroku'
7
+ app.command :create do |create|
8
+ create.action do |global_options,options,args|
9
+
10
+ Negroku::Bootstrap.install
11
+
12
+ end
13
+ end
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
+ end
39
+ end
@@ -0,0 +1,15 @@
1
+ module Negroku::CLI
2
+
3
+ # This is the default negroku command
4
+ # Here we'll manage the main interative cli ui
5
+ command :negroku do |c|
6
+
7
+ c.default_command :ask
8
+ c.command :ask do |s|
9
+ s.action do |global_options,options,args|
10
+
11
+ end
12
+ end
13
+
14
+ end
15
+ end