mina 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -2,3 +2,4 @@ doc
2
2
  test_env/deploy
3
3
  .rvmrc
4
4
  Gemfile.lock
5
+ pkg/
data/HISTORY.md CHANGED
@@ -1,3 +1,19 @@
1
+ v0.1.1 - Jun 07, 2012
2
+ ---------------------
3
+
4
+ ### Added:
5
+ * Check for releases_path directory in deploy script.
6
+ * mina deploy:cleanup
7
+ * Support for -f option.
8
+
9
+ ### Changed:
10
+ * Gem description.
11
+
12
+ ### Fixed:
13
+ * deploy.rb template (domain, user, git:clone).
14
+ * Handle empty Git repository.
15
+ * Add pkg to gitignore.
16
+
1
17
  v0.1.0 - Jun 06, 2012
2
18
  ---------------------
3
19
 
data/bin/mina CHANGED
@@ -26,7 +26,10 @@ Rake.application.instance_eval do
26
26
  standard_exception_handling do
27
27
  # Initialize Rake and make it think it's Mina.
28
28
  init 'mina'
29
- @rakefiles = ['Minafile', 'config/deploy.rb']
29
+
30
+ # (The only way @rakefiles has only 1 value is if -f is specified.)
31
+ custom_rakefile = (@rakefiles.size == 1)
32
+ @rakefiles = ['Minafile', 'config/deploy.rb'] unless custom_rakefile
30
33
 
31
34
  # Workaround: Rake 0.9+ doesn't record task descriptions unless it's needed.
32
35
  # Need it for 'mina help'
@@ -38,7 +41,7 @@ Rake.application.instance_eval do
38
41
  require 'mina/rake'
39
42
 
40
43
  # Allow running without a Rakefile
41
- load_rakefile if have_rakefile
44
+ load_rakefile if have_rakefile || custom_rakefile
42
45
 
43
46
  # Run tasks
44
47
  top_level
@@ -3,22 +3,22 @@ require 'mina/rails'
3
3
  require 'mina/git'
4
4
 
5
5
  # Basic settings:
6
- # host - The hostname to SSH to
6
+ # domain - The hostname to SSH to
7
7
  # deploy_to - Path to deploy into
8
8
  # repository - Git repo to clone from (needed by mina/git)
9
9
  # user - Username in the server to SSH to (optional)
10
10
 
11
- set :host, 'foobar.com'
11
+ set :domain, 'foobar.com'
12
12
  set :deploy_to, '/var/www/foobar.com'
13
13
  set :repository, 'git://...'
14
- # set :user, 'foobar.com'
14
+ # set :user, 'foobar'
15
15
 
16
16
  desc "Deploys the current version to the server."
17
17
  task :deploy do
18
18
  deploy do
19
19
  # Put things that will set up an empty directory into a fully set-up
20
20
  # instance of your project.
21
- invoke :'git:checkout'
21
+ invoke :'git:clone'
22
22
  invoke :'bundle:install'
23
23
  invoke :'rails:db_migrate'
24
24
  invoke :'rails:assets_precompile'
@@ -11,7 +11,15 @@ cd "<%= deploy_to %>" || (
11
11
  echo "The path '<%= deploy_to %>' is not accessible on the server."
12
12
  echo "You may need to run 'mina setup' first."
13
13
  false
14
- ) || exit 16
14
+ ) || exit 15
15
+
16
+ # Check releases path
17
+ if [ ! -d "<%= releases_path %>" ]; then
18
+ echo "=====> ERROR: not set up."
19
+ echo "The directory '<%= releases_path %>' does not exist on the server."
20
+ echo "You may need to run 'mina setup' first."
21
+ exit 16
22
+ fi
15
23
 
16
24
  # Check lockfile
17
25
  if [ -e "<%= lock_file %>" ]; then
@@ -94,5 +102,5 @@ fi
94
102
  # Unlock
95
103
  <%= echo_cmd %[rm -f "#{lock_file}"] %>
96
104
  echo "OK"
97
- exit 8
105
+ exit 19
98
106
  )
@@ -74,7 +74,8 @@ task :help do
74
74
  [ "-V, --version", "Show program version" ],
75
75
  [ "-v, --verbose", "Show commands as they happen" ],
76
76
  [ "-S, --simulate", "Run in simulation mode" ],
77
- [ "-t, --trace", "Show backtraces when errors occur" ]
77
+ [ "-t, --trace", "Show backtraces when errors occur" ],
78
+ [ "-f FILE", "Use FILE as the deploy configuration" ]
78
79
  ]
79
80
  opts.each { |args| puts " %-17s %s" % args }
80
81
  puts ""
@@ -2,6 +2,7 @@ set_default :releases_path, "releases"
2
2
  set_default :shared_path, "shared"
3
3
  set_default :current_path, "current"
4
4
  set_default :lock_file, "deploy.lock"
5
+ set_default :keep_releases, 5
5
6
 
6
7
  namespace :deploy do
7
8
  desc "Forces a deploy unlock."
@@ -27,6 +28,18 @@ namespace :deploy do
27
28
  #{cmds.join(" &&\n")}
28
29
  }
29
30
  end
31
+
32
+ desc "Clean up old releases. By default, the last 5 releases are kept on
33
+ each server (though you can change this with the keep_releases setting).
34
+ All other deployed revisions are removed from the servers."
35
+ task :cleanup do
36
+ queue %{echo "-----> Cleaning up old releases (keeping #{keep_releases!})"}
37
+ queue echo_cmd %{cd "#{deploy_to!}" || exit 15}
38
+ queue echo_cmd %{cd "#{releases_path!}" || exit 16}
39
+ queue echo_cmd %{count=`ls -1d [0-9]* | sort -rn | wc -l`}
40
+ queue echo_cmd %{remove=$((count > 5 ? count - #{keep_releases} : 0))}
41
+ queue echo_cmd %{ls -1d [0-9]* | sort -rn | tail -n $remove | xargs rm -rf {}}
42
+ end
30
43
  end
31
44
 
32
45
  desc "Sets up a site."
@@ -3,6 +3,11 @@ namespace :git do
3
3
  task :clone do
4
4
  settings.revision ||= `git rev-parse HEAD`.strip
5
5
 
6
+ if settings.revision.empty?
7
+ error "Git revision is empty. Check if you are in git tree."
8
+ exit 1
9
+ end
10
+
6
11
  queue %{
7
12
  echo "-----> Cloning the Git repository"
8
13
  #{echo_cmd %[git clone "#{repository!}" . -n --recursive]} &&
@@ -1,5 +1,5 @@
1
1
  module Mina
2
2
  def self.version
3
- "0.1.0"
3
+ "0.1.1"
4
4
  end
5
5
  end
@@ -4,7 +4,7 @@ Gem::Specification.new do |s|
4
4
  s.name = "mina"
5
5
  s.version = Mina.version
6
6
  s.summary = %{Really fast deployer and server automation tool.}
7
- s.description = %Q{Builds scripts."}
7
+ s.description = %Q{Really fast deployer and server automation tool.}
8
8
  s.authors = ["Rico Sta. Cruz", "Michael Galero"]
9
9
  s.email = ["rico@nadarei.co", "mikong@nadarei.co"]
10
10
  s.homepage = "http://github.com/nadarei/mina"
@@ -55,6 +55,12 @@ describe "Invoking the 'mina' command in a project" do
55
55
  end
56
56
  end
57
57
 
58
+ it "with 'mina -f' on a non-existing file should fail" do
59
+ run_command '-f', 'foobar'
60
+ stderr.should include 'mina aborted'
61
+ stderr.should include 'No Rakefile found'
62
+ end
63
+
58
64
  it "with 'mina tasks' should print tasks" do
59
65
  mina 'tasks'
60
66
 
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+ require 'command_helper'
3
+
4
+ describe "Invoking the 'mina' command in a project without a deploy.rb" do
5
+ before :each do
6
+ Dir.chdir root('spec/fixtures/custom_file_env')
7
+ FileUtils.rm_rf 'deploy'
8
+ end
9
+
10
+ it 'should fail' do
11
+ run_command 'deploy', '--simulate'
12
+ exitstatus.should be > 0
13
+ end
14
+
15
+ it 'should pass if you provide a new rakefile' do
16
+ mina 'deploy', '--simulate', '-f', 'custom_deploy.rb'
17
+ stdout.should include 'Creating a temporary build path'
18
+ end
19
+ end
20
+
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+ require 'command_helper'
3
+
4
+ describe "Invoking the 'mina deploy' command outside of git tree" do
5
+ before do
6
+ temp_path = "/tmp/mina-spec"
7
+ FileUtils.mkdir_p("#{temp_path}/config")
8
+ FileUtils.cp root('spec/fixtures/empty_env/config/deploy.rb'), "#{temp_path}/config/deploy.rb"
9
+ Dir.chdir temp_path
10
+ end
11
+
12
+ after do
13
+ FileUtils.rm_rf "/tmp/mina-spec"
14
+ Dir.chdir root
15
+ end
16
+
17
+ it 'should prompt empty revision error message' do
18
+ run_command 'deploy', 'simulate=1'
19
+ exitstatus.should_not eq(0)
20
+ stderr.should match(/git revision is empty/i)
21
+ end
22
+ end
@@ -2,10 +2,10 @@ require 'spec_helper'
2
2
 
3
3
  describe 'Settings in rake tasks' do
4
4
  it '#set should work' do
5
- rake { set :host, 'localhost' }
5
+ rake { set :domain, 'localhost' }
6
6
 
7
- rake.host.should == 'localhost'
8
- rake.settings.host.should == 'localhost'
7
+ rake.domain.should == 'localhost'
8
+ rake.settings.domain.should == 'localhost'
9
9
  end
10
10
 
11
11
  it '#settings ||= should work' do
@@ -7,8 +7,8 @@ describe 'Settings' do
7
7
  end
8
8
 
9
9
  it 'setting/getting should work' do
10
- @settings.host = '192.168.1.1'
11
- @settings.host.should == '192.168.1.1'
10
+ @settings.domain = '192.168.1.1'
11
+ @settings.domain.should == '192.168.1.1'
12
12
  end
13
13
 
14
14
  it 'question mark should work' do
@@ -0,0 +1,15 @@
1
+ require 'fileutils'
2
+ FileUtils.mkdir_p "#{Dir.pwd}/deploy"
3
+
4
+ require 'mina/git'
5
+
6
+ set :domain, 'localhost'
7
+ set :deploy_to, "#{Dir.pwd}/deploy"
8
+ set :repository, "#{Dir.pwd}"
9
+
10
+ desc "Deploys."
11
+ task :deploy do
12
+ deploy do
13
+ invoke :'git:clone'
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ require 'fileutils'
2
+ FileUtils.mkdir_p "#{Dir.pwd}/deploy"
3
+
4
+ require 'mina/git'
5
+
6
+ set :domain, 'localhost'
7
+ set :deploy_to, "#{Dir.pwd}/deploy"
8
+ set :repository, "#{Dir.pwd}"
9
+
10
+ desc "Deploys."
11
+ task :deploy do
12
+ deploy do
13
+ invoke :'git:clone'
14
+ end
15
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mina
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-06-06 00:00:00.000000000 Z
13
+ date: 2012-06-07 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
17
- requirement: &70316358397800 !ruby/object:Gem::Requirement
17
+ requirement: &70204554987380 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70316358397800
25
+ version_requirements: *70204554987380
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: open4
28
- requirement: &70316358397380 !ruby/object:Gem::Requirement
28
+ requirement: &70204554986960 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *70316358397380
36
+ version_requirements: *70204554986960
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: rspec
39
- requirement: &70316358396960 !ruby/object:Gem::Requirement
39
+ requirement: &70204554986540 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,8 +44,8 @@ dependencies:
44
44
  version: '0'
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *70316358396960
48
- description: Builds scripts."
47
+ version_requirements: *70204554986540
48
+ description: Really fast deployer and server automation tool.
49
49
  email:
50
50
  - rico@nadarei.co
51
51
  - mikong@nadarei.co
@@ -80,7 +80,9 @@ files:
80
80
  - mina.gemspec
81
81
  - spec/command_helper.rb
82
82
  - spec/commands/command_spec.rb
83
+ - spec/commands/custom_config_spec.rb
83
84
  - spec/commands/deploy_spec.rb
85
+ - spec/commands/git_spec.rb
84
86
  - spec/commands/outside_project_spec.rb
85
87
  - spec/commands/real_deploy_spec.rb
86
88
  - spec/commands/verbose_spec.rb
@@ -88,6 +90,8 @@ files:
88
90
  - spec/dsl/settings_in_rake_spec.rb
89
91
  - spec/dsl/settings_spec.rb
90
92
  - spec/dsl/to_spec.rb
93
+ - spec/fixtures/custom_file_env/custom_deploy.rb
94
+ - spec/fixtures/empty_env/config/deploy.rb
91
95
  - spec/spec_helper.rb
92
96
  - test_env/config/deploy.rb
93
97
  homepage: http://github.com/nadarei/mina