biola_deploy 0.4.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dab32b0e710d35404b6b3db6b9ff1cabddb81d22
4
- data.tar.gz: d7f668dfa8c072b7f600250278152de9912300c6
3
+ metadata.gz: 6eceeb81d797e4f0e7aa9aa5ffbd517808c420bd
4
+ data.tar.gz: f465f3c67964f9aab1bb1c6e099aced584837c45
5
5
  SHA512:
6
- metadata.gz: 24606cc80b13554bd05572bc0c2896c8ae794a2f517fa718e4d0dccb95122ae0179dc1dc0ece40fc8fc9b7bc985a3f429866776a3f75792423485b06fe2a191d
7
- data.tar.gz: 5541721bbed8ac5e663d022e8d7c31451b4f01c3d085088119b85164d126cf2d6d0ea2cd9aa7703cd02aacd0126643755c978ad5813185cbfe277a1fce97fd98
6
+ metadata.gz: a31b819c009e7b5105bd552b1dab3e218f4dde90dfbc97a259a9b2f0e7184d963ef09179bb0c52f58f3d9a20da46a878dee15851238a654e0a2892990392ccc1
7
+ data.tar.gz: 564b9248d47548025418181f62d3201b52802001f249010e95225e4d4d4f8cbc828d66b76145ab9bfe6a206d988d56c0f39f8828cef769e76918e9bdde444503
@@ -1,3 +1,3 @@
1
1
  module BiolaDeploy
2
- VERSION = '0.4.1'
2
+ VERSION = '0.5.0'
3
3
  end
@@ -1,62 +1,81 @@
1
1
  require 'fileutils'
2
- require 'uri'
3
2
 
4
3
  namespace :deploy do
5
4
  desc 'Run the database migrations'
6
- task :migrate_db => :environment do
7
- puts 'migrating the database...'
8
- Rake::Task['db:migrate'].invoke
5
+ task :migrate_db do
6
+ if_rails_loads 'database migration' do
7
+ Rake::Task['db:migrate'].invoke
8
+ end
9
9
  end
10
10
 
11
11
  desc 'Reindex Solr if it exists'
12
12
  task :reindex_solr do
13
- if Rake::Task.task_defined? 'sunspot:reindex'
14
- puts 'reindexing Solr...'
13
+ if_rails_loads 'Solr reindex' do
15
14
  Rake::Task['sunspot:reindex'].invoke
16
15
  end
17
16
  end
18
17
 
19
18
  desc 'Precompile the asset pipeline in Rails apps 3.1 and above'
20
19
  task :precompile_assets do
21
- if Rake::Task.task_defined? 'assets:precompile'
22
- puts 'precompiling assets...'
20
+ if_rails_loads 'asset precompile' do
23
21
  Rake::Task['assets:precompile'].invoke
24
22
  end
25
23
  end
26
24
 
27
25
  desc 'Tell NewRelic about this deployment'
28
- task :tell_newrelic => :environment do
29
- require 'new_relic/cli/command'
30
- require 'new_relic/cli/deployments'
26
+ task :tell_newrelic do
27
+ if_rails_loads 'NewRelic deployment' do
28
+ # TODO: check for NewRelic
29
+ require 'new_relic/cli/command'
30
+ require 'new_relic/cli/deployments'
31
31
 
32
- version = if defined? Version
33
- Version.current
34
- else
35
- `git log -1 --format=%h`.chomp # abbreviated hash of latest git commit
36
- end
32
+ version = if defined? Version
33
+ Version.current
34
+ else
35
+ `git log -1 --format=%h`.chomp # abbreviated hash of latest git commit
36
+ end
37
37
 
38
- NewRelic::Cli::Deployments.new(revision: version).run
38
+ NewRelic::Cli::Deployments.new(revision: version).run
39
+ end
39
40
  end
40
41
 
41
- desc 'Trigger a Passenger restart'
42
- task :restart_app => :environment do
43
- restart_file = 'tmp/restart.txt'
42
+ desc 'Trigger an application restart'
43
+ task :restart_app do
44
+ if_rails_loads 'application restart' do
45
+ restart_file = 'tmp/restart.txt'
44
46
 
45
- puts 'restarting the app...'
46
- Dir.chdir(app_dir) do
47
- make_globally_writable restart_file if File.exists? restart_file
48
- FileUtils.touch restart_file
47
+ Dir.chdir(app_dir) do
48
+ if File.exists? restart_file
49
+ FileUtils.touch restart_file
50
+ end
51
+ end
49
52
  end
50
53
  end
51
54
 
52
55
  private
53
56
 
54
- def app_dir
55
- Rails.root.to_s
57
+ # If this is a first run and there is no database.yml (for instance)
58
+ # this will return false
59
+ def if_rails_loads(task_description, &block)
60
+ error = nil
61
+
62
+ unless defined?(Rails) && Rails.initialized?
63
+ begin
64
+ load 'config/environment.rb'
65
+ rescue LoadError, RuntimeError => e
66
+ error = e.message
67
+ end
68
+ end
69
+
70
+ if error
71
+ puts "Skipping #{task_description} because: #{error}"
72
+ else
73
+ puts "Running #{task_description}"
74
+ block.call
75
+ end
56
76
  end
57
77
 
58
- def make_globally_writable(file)
59
- permissions = File.directory?(file) ? 777 : 666
60
- system "sudo chmod #{permissions} #{file}"
78
+ def app_dir
79
+ Rails.root.to_s
61
80
  end
62
81
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: biola_deploy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Crownoble