gitpusshuten 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --format Fuubar
data/Gemfile CHANGED
@@ -6,4 +6,5 @@ group :test do
6
6
  gem 'rspec'
7
7
  gem 'mocha'
8
8
  gem 'infinity_test'
9
+ gem 'fuubar'
9
10
  end
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gitpusshuten (0.0.3)
4
+ gitpusshuten (0.0.5)
5
5
  activesupport (~> 3.0.0)
6
6
  highline (~> 1.6.0)
7
7
  json (~> 1.4.0)
@@ -14,6 +14,10 @@ GEM
14
14
  specs:
15
15
  activesupport (3.0.1)
16
16
  diff-lcs (1.1.2)
17
+ fuubar (0.0.2)
18
+ rspec (~> 2.0)
19
+ rspec-instafail (~> 0.1.4)
20
+ ruby-progressbar (~> 0.0.9)
17
21
  highline (1.6.1)
18
22
  infinity_test (0.2.0)
19
23
  watchr (>= 0.7)
@@ -32,9 +36,11 @@ GEM
32
36
  rspec-core (2.0.1)
33
37
  rspec-expectations (2.0.1)
34
38
  diff-lcs (>= 1.1.2)
39
+ rspec-instafail (0.1.4)
35
40
  rspec-mocks (2.0.1)
36
41
  rspec-core (~> 2.0.1)
37
42
  rspec-expectations (~> 2.0.1)
43
+ ruby-progressbar (0.0.9)
38
44
  watchr (0.7)
39
45
 
40
46
  PLATFORMS
@@ -42,6 +48,7 @@ PLATFORMS
42
48
 
43
49
  DEPENDENCIES
44
50
  activesupport (~> 3.0.0)
51
+ fuubar
45
52
  gitpusshuten!
46
53
  highline (~> 1.6.0)
47
54
  infinity_test
@@ -125,6 +125,7 @@ module GitPusshuTen
125
125
  puts "\nGit Pusshu Ten\n\s\s\s\sプッシュ天\n\n"
126
126
  puts "[Command]\n\n\s\s#{y(command)}\n\n"
127
127
  puts "[Description]\n\n\s\s#{get_constant_for(command).description}\n\n"
128
+ puts "#{get_constant_for(command).long_description.gsub(/^/, "\s\s")}\n\n" unless get_constant_for(command).long_description.nil?
128
129
  puts "[Usage]\n\n\s\s#{y get_constant_for(command).usage}\n\n"
129
130
  puts "[Examples]\n#{get_constant_for(command).example}\n\n"
130
131
  puts "For a list of all commands: #{y 'heavenly help'}"
@@ -20,7 +20,15 @@ module GitPusshuTen
20
20
 
21
21
  ##
22
22
  # Contains the invoked command
23
- attr_accessor :command
23
+ attr_writer :command
24
+
25
+ ##
26
+ # Returns the underscored version of the command if it's a string
27
+ # otherwise just return the unmodified value (probably nil)
28
+ def command
29
+ return @command.underscore if @command.is_a?(String)
30
+ @command
31
+ end
24
32
 
25
33
  ##
26
34
  # This is a flag, that, when set to true, will invoke the
@@ -42,6 +50,17 @@ module GitPusshuTen
42
50
  end
43
51
  end
44
52
 
53
+ ##
54
+ # This is used by the "help" command to display the
55
+ # long version of the description
56
+ def self.long_description(value = nil)
57
+ if value.nil?
58
+ @long_description
59
+ else
60
+ @long_description = value
61
+ end
62
+ end
63
+
45
64
  ##
46
65
  # This is used by the "help" command to display the
47
66
  # usage of the command in the CLI
@@ -206,7 +225,9 @@ module GitPusshuTen
206
225
  ##
207
226
  # Connect to the remote environment and perform the pre deploy hooks
208
227
  hooks.render_commands(hooks.pre_hooks).each do |name, commands|
209
- GitPusshuTen::Log.message("Performing pre deploy hook: #{y(name)}")
228
+ adjusted_name = name.sub(/^\d+\)\s/, '')
229
+
230
+ GitPusshuTen::Log.message("Performing pre deploy hook: #{y(adjusted_name)}")
210
231
  standard environment.execute_as_user("cd '#{e.app_dir}'; #{commands}")
211
232
  end
212
233
  end
@@ -224,7 +245,9 @@ module GitPusshuTen
224
245
  ##
225
246
  # Connect to the remote environment and perform the post deploy hooks
226
247
  hooks.render_commands(hooks.post_hooks).each do |name, commands|
227
- GitPusshuTen::Log.message("Performing post deploy hook: #{y(name)}")
248
+ adjusted_name = name.sub(/^\d+\)\s/, '')
249
+
250
+ GitPusshuTen::Log.message("Performing post deploy hook: #{y(adjusted_name)}")
228
251
  standard environment.execute_as_user("cd '#{e.app_dir}'; #{commands}")
229
252
  end
230
253
  end
@@ -241,6 +264,16 @@ module GitPusshuTen
241
264
  e.execute_as_user('')
242
265
  end
243
266
 
267
+ ##
268
+ # Will check to see if the user exists, if it doesn't then it'll
269
+ # display an error telling the user to set up a user first
270
+ def requires_user_existence!
271
+ if not e.user_exists?
272
+ error "You have to setup your user before you can perform this action."
273
+ exit
274
+ end
275
+ end
276
+
244
277
  end
245
278
  end
246
279
  end
@@ -118,5 +118,11 @@ module GitPusshuTen
118
118
  self
119
119
  end
120
120
 
121
+ ##
122
+ # Returns a (simple) sanitized version of the application name
123
+ def sanitized_app_name
124
+ application.gsub(' ', '_').downcase
125
+ end
126
+
121
127
  end
122
128
  end
@@ -132,14 +132,21 @@ module GitPusshuTen
132
132
  # Takes an array of hooks and renders them a Hash that
133
133
  # contains the name of the hook, as well as all the commands
134
134
  # bundled in a single string, separated by semi-colons.
135
+ #
136
+ # Note: Using a hack to avoid "Hash" sorting issues between Ruby versions
137
+ # which cause the hooks to invoke in the incorrect order. This has been addressed
138
+ # by prefixing the Hash's "key" with the index of the array and sorting based on that.
139
+ # Then the \d+\)\s gets #sub'd for friendly user output
135
140
  def render_commands(hooks)
136
141
  hooks_hash = {}
137
- hooks.each do |hook|
138
- hooks_hash[hook.name] = ''
142
+
143
+ hooks.each_with_index do |hook, index|
144
+ hooks_hash["#{index}) #{hook.name}"] = ''
139
145
  hook.commands.each do |command|
140
- hooks_hash[hook.name] << "#{command};".gsub(/;{2,}/, ';')
146
+ hooks_hash["#{index}) #{hook.name}"] += "#{command};".gsub(/;{2,}/, ';')
141
147
  end
142
148
  end
149
+
143
150
  hooks_hash
144
151
  end
145
152
 
@@ -5,7 +5,7 @@ module GitPusshuTen
5
5
  ##
6
6
  # Displays a regular message without prefix
7
7
  def self.standard(message)
8
- puts message
8
+ puts message unless message.nil?
9
9
  to_file message
10
10
  end
11
11
 
@@ -0,0 +1,222 @@
1
+ # encoding: utf-8
2
+ module GitPusshuTen
3
+ module Commands
4
+ class ActiveRecord < GitPusshuTen::Commands::Base
5
+ description "[Module] Active Record commands."
6
+ long_description "By using the Active Record CLI utility you can avoid checking your database.yml into your git repository.\n" +
7
+ "Use the examples below to create, and then upload your custom database.yml for the desired environment to the server\n" +
8
+ "and the Active Record module will handle the rest! After the deployment of your application this uploaded database.yml file will\n" +
9
+ "be placed inside your APP_ROOT/config/database.yml. If the database.yml file already exists there, it'll overwrite it.\n" +
10
+ "This is a security measure, since it's generally bad practice to store any sensitive information in your Git repository."
11
+
12
+ usage "active_record <command> for <enviroment>"
13
+ example "heavenly active_record create_configuration # Creates a template for your remote database."
14
+ example " create_config # Alias."
15
+ example "heavenly active_record upload_configuration # Uploads your configuration file to the remote server."
16
+ example " upload_config # Alias."
17
+ example "heavenly active_record download_configuration # Downloads your configuration file from the remote server."
18
+ example " download_config # Alias."
19
+
20
+ def initialize(*objects)
21
+ super
22
+
23
+ ##
24
+ # Set the command
25
+ @command = cli.arguments.shift
26
+
27
+ ##
28
+ # Display the help screen if either the command
29
+ # or environment name hasn't been set
30
+ help if command.nil? or e.name.nil?
31
+
32
+ ##
33
+ # Default Configuration
34
+ @local_configuration_dir = File.join(local.gitpusshuten_dir, 'active_record')
35
+ @local_configuration_file = File.join(@local_configuration_dir, "#{e.name}.database.yml")
36
+ @remote_configuration_dir = File.join(c.path, 'modules', 'active_record')
37
+ @remote_configuration_file = File.join(@remote_configuration_dir, "#{e.sanitized_app_name}.#{e.name}.database.yml")
38
+
39
+ ##
40
+ # Ensure the directory is always available
41
+ FileUtils.mkdir_p(@local_configuration_dir)
42
+ end
43
+
44
+ ##
45
+ # Creates a template for the user to work with
46
+ def perform_create_configuration!
47
+ overwrite_if_exists?
48
+
49
+ render_database_yml
50
+ message "Created #{y(@local_configuration_file)}."
51
+ end
52
+
53
+ ##
54
+ # Alias to perform_create_configuration!
55
+ def perform_create_config!
56
+ perform_create_configuration!
57
+ end
58
+
59
+ ##
60
+ # Uploads the local configuration file to the remote server.
61
+ def perform_upload_configuration!
62
+ requires_user_existence!
63
+ prompt_for_user_password!
64
+
65
+ if not File.exist?(@local_configuration_file)
66
+ error "Could not find #{y(@local_configuration_file)}."
67
+ error "Either download an existing one from your server with:"
68
+ standard "\n\s\s#{y("heavenly active_record download-configuration from #{e.name}")}\n\n"
69
+ error "Or create a new template with:"
70
+ standard "\n\s\s#{y("heavenly active_record create-configuration for #{e.name}")}"
71
+ exit
72
+ end
73
+
74
+ ##
75
+ # Ensure the remote active_record module directory exits
76
+ # and upload the local file to the remote file location
77
+ Spinner.return :message => "Uploading the database configuration file.." do
78
+ e.execute_as_user("mkdir -p '#{@remote_configuration_dir}'")
79
+ e.scp_as_user(:upload, @local_configuration_file, @remote_configuration_file)
80
+ g('Done!')
81
+ end
82
+ end
83
+
84
+ ##
85
+ # Alias to perform_upload_configuration!
86
+ def perform_upload_config!
87
+ perform_upload_configuration!
88
+ end
89
+
90
+ ##
91
+ # Downloads the configuration file from the remote server.
92
+ def perform_download_configuration!
93
+ overwrite_if_exists?
94
+
95
+ ##
96
+ # Don't proceed unless the file exists
97
+ if not e.file?(@remote_configuration_file)
98
+ error "Configuration could not be found on the server in #{y(@remote_configuration_file)}."
99
+ exit
100
+ end
101
+
102
+ ##
103
+ # Ensure the remote active_record module directory exits
104
+ # and upload the local file to the remote file location
105
+ Spinner.return :message => "Downloading the database configuration file.." do
106
+ e.scp_as_user(:download, @remote_configuration_file, @local_configuration_file)
107
+ g('Done!')
108
+ end
109
+ end
110
+
111
+ ##
112
+ # Alias to perform_download_configuration!
113
+ def perform_download_config!
114
+ perform_download_configuration!
115
+ end
116
+
117
+ ##
118
+ # Prompts the user to choose a database adapter
119
+ def choose_adapter
120
+ choose do |menu|
121
+ menu.prompt = ''
122
+ menu.choice('mysql', 'mysql2')
123
+ menu.choice('postgresql')
124
+ menu.choice('sqlite3')
125
+ menu.choice('oracle')
126
+ menu.choice('frontbase')
127
+ menu.choice('ibm_db')
128
+ end
129
+ end
130
+
131
+ ##
132
+ # Render the chosen Active Record database template file
133
+ def render_database_yml
134
+ config_content = case choose_adapter
135
+ when 'mysql', 'mysql2'
136
+ <<-CONFIG
137
+ production:
138
+ adapter: mysql2
139
+ encoding: utf8
140
+ reconnect: false
141
+ database: #{e.sanitized_app_name}_#{e.name}
142
+ pool: 5
143
+ username: #{c.user}
144
+ password:
145
+ host: localhost
146
+ # socket: /tmp/mysql.sock
147
+ CONFIG
148
+ when 'postgresql'
149
+ <<-CONFIG
150
+ production:
151
+ adapter: postgresql
152
+ encoding: unicode
153
+ database: #{e.sanitized_app_name}_#{e.name}
154
+ pool: 5
155
+ username: #{c.user}
156
+ password:
157
+ CONFIG
158
+ when 'sqlite3'
159
+ <<-CONFIG
160
+ production:
161
+ adapter: sqlite3
162
+ database: db/production.sqlite3
163
+ pool: 5
164
+ timeout: 5000
165
+ CONFIG
166
+ when 'oracle'
167
+ <<-CONFIG
168
+ production:
169
+ adapter: oracle
170
+ database: #{e.sanitized_app_name}_#{e.name}
171
+ username: #{c.user}
172
+ password:
173
+ CONFIG
174
+ when 'frontbase'
175
+ <<-CONFIG
176
+ production:
177
+ adapter: frontbase
178
+ host: localhost
179
+ database: #{e.sanitized_app_name}_#{e.name}
180
+ username: #{c.user}
181
+ password:
182
+ CONFIG
183
+ when 'ibm_db'
184
+ <<-CONFIG
185
+ production:
186
+ adapter: ibm_db
187
+ username: #{c.user}
188
+ password:
189
+ database: #{e.sanitized_app_name}_#{e.name}
190
+ #schema: db2inst1
191
+ #host: localhost
192
+ #port: 50000
193
+ #account: my_account
194
+ #app_user: my_app_user
195
+ #application: my_application
196
+ #workstation: my_workstation
197
+ #security: SSL
198
+ #timeout: 10
199
+ #authentication: SERVER
200
+ #parameterized: false
201
+ CONFIG
202
+ end # end case statement
203
+
204
+ File.open(@local_configuration_file, 'w') do |file|
205
+ file << config_content
206
+ end
207
+ end
208
+
209
+ ##
210
+ # If the local configuration file exists, it will ask the
211
+ # user whether he wants to overwrite it
212
+ def overwrite_if_exists?
213
+ if File.exist?(@local_configuration_file)
214
+ warning "Configuration file already exists in #{@local_configuration_file}."
215
+ warning "Would you like to overwrite?"
216
+ exit unless yes?
217
+ end
218
+ end
219
+
220
+ end
221
+ end
222
+ end
@@ -1,19 +1,14 @@
1
1
  ##
2
- # Will check if the app_root/config/database.yml.<environment> exists
3
- # if it does, it'll overwrite the database.yml with that environment database.
4
- # If it does not exist, it'll leave the database.yml unchanged.
5
- post "Setting proper database for environment. (Rails)" do
6
- run "if [[ -f 'config/database.yml.#{environment}' ]]; then " +
7
- "echo 'config/database.yml.#{environment} found! Using this one instead of config/database.yml';" +
8
- "echo 'Overwriting config/database.yml with config/database.yml.#{environment}';" +
9
- "mv 'config/database.yml.#{environment}' 'config/database.yml'; " +
2
+ # If the user uploaded his own database.yml file (using the Active Record CLI) then
3
+ # it'll overwrite the repository version (if it exists) before migrating.
4
+ post "Configure and Migrate Database (Active Record)" do
5
+ run "if [[ -f '#{configuration.path}/modules/active_record/#{configuration.sanitized_app_name}.#{environment}.database.yml' ]]; then " +
6
+ "cp '#{configuration.path}/modules/active_record/#{configuration.sanitized_app_name}.#{environment}.database.yml' " +
7
+ "'#{configuration.path}/#{configuration.sanitized_app_name}.#{environment}/config/database.yml'; " +
8
+ "echo 'Uploaded \"database.yml\" file found! Will be using it for the #{environment} environment!'; " +
9
+ "else echo 'Could not find any (pre) uploaded database.yml, skipping.'; " +
10
10
  "fi"
11
- end
12
-
13
- ##
14
- # Will create the database if it doesn't exist yet.
15
- # Migrates the database.
16
- post "Migrate Database (Active Record)" do
11
+
17
12
  run "rake db:create"
18
13
  run "rake db:migrate"
19
14
  end
@@ -4,9 +4,9 @@ module GitPusshuTen
4
4
  class Redis < GitPusshuTen::Commands::Base
5
5
  description "[Module] Redis commands."
6
6
  usage "redis <command> for <enviroment>"
7
- example "heavenly redis install # Installs Redis (system wide) and downloads config template."
8
- example "heavenly redis upload-configuration # Uploads the Redis configuration template to the server, will install Redis if not already present."
9
- example " upload-config # Alias."
7
+ example "heavenly redis install to staging # Installs Redis (system wide) and downloads config template."
8
+ example "heavenly redis upload-configuration to staging # Uploads the Redis configuration template to the server, will install Redis if not already present."
9
+ example " upload-config to staging # Alias."
10
10
 
11
11
  def initialize(*objects)
12
12
  super
@@ -1,3 +1,3 @@
1
1
  module GitPusshuTen
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
data/lib/gitpusshuten.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'FileUtils'
1
+ require 'fileutils'
2
2
  require 'open-uri'
3
3
  require 'yaml'
4
4
 
data/spec/hooks_spec.rb CHANGED
@@ -138,9 +138,9 @@ describe GitPusshuTen::Hooks do
138
138
  describe '#render_commands_as_string' do
139
139
  it do
140
140
  hooks.render_commands(hooks.post_hooks).should == {
141
- :render_output => 'rake render:output;',
142
- :restart_nginx_and_passenger => '/etc/init.d/nginx stop;sleep 1;/etc/init.d/nginx start;mkdir tmp;touch tmp/restart.txt;',
143
- :ensure_correct_branch => 'git commit -am "Commit and Ensuring";git checkout master;'
141
+ '0) render_output' => 'rake render:output;',
142
+ '1) restart_nginx_and_passenger' => '/etc/init.d/nginx stop;sleep 1;/etc/init.d/nginx start;mkdir tmp;touch tmp/restart.txt;',
143
+ '2) ensure_correct_branch' => 'git commit -am "Commit and Ensuring";git checkout master;'
144
144
  }
145
145
  end
146
146
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitpusshuten
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Michael van Rooijen
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-23 00:00:00 +01:00
18
+ date: 2010-11-24 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -129,6 +129,7 @@ extra_rdoc_files: []
129
129
  files:
130
130
  - .bundle/config
131
131
  - .gitignore
132
+ - .rspec
132
133
  - Gemfile
133
134
  - Gemfile.lock
134
135
  - README.md
@@ -163,6 +164,7 @@ files:
163
164
  - lib/gitpusshuten/initializer.rb
164
165
  - lib/gitpusshuten/local.rb
165
166
  - lib/gitpusshuten/log.rb
167
+ - lib/gitpusshuten/modules/active_record/command.rb
166
168
  - lib/gitpusshuten/modules/active_record/hooks.rb
167
169
  - lib/gitpusshuten/modules/apache/command.rb
168
170
  - lib/gitpusshuten/modules/bundler/command.rb