shuttle-deploy 0.2.0.beta2 → 0.2.0.beta3

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ODM5ZTBlNTBhMjQ3OGVhYzVjMGUyN2M5YzY2OGYxOTdmMTM3OWViOQ==
4
+ Mjk5YzAxY2JkMGFhMzcxMTI1OTFhYzJjYzllZDM3NWU2MzE3YzY2Zg==
5
5
  data.tar.gz: !binary |-
6
- YjYxYzQyYzY2Y2U5OWQ3MzMyNGU1MTM5ZDgxZDQzMzFhZDUwNTUwMw==
6
+ Mzk3MWU5Yjk4M2U1NjVmMDdiZGUzOTBhOWMwNTVkOTRiOTIxN2FjMw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZDc0MzdhNWMxNmRkZThiYWE2OGU1NmM5YmI5ZjRmMmYwZTQ0NTZlMzJjNmE3
10
- MGRhNzNkMzFjODk1MjhhMWMxNzMxMjUwODk2N2MyZTE0YmI4OGUyZDdmNzhh
11
- YzQ0NWQ4M2Q3ZDY4YWIzNjdlY2JlOTFlZDJkNWU0NjFhZGJlZjc=
9
+ ZDE0NDYzZTEwZmFjZDMyOTRmYzdhYWIyOTNhYjI0OWRjYzBlZmY1YWMzMTAw
10
+ YmFhYjJhZmI3MTQxZDYyZTI1MWJjNTliZmIzYjJkYmNjOWY5NThmN2UwNWE0
11
+ OTZhYTA0MzRhYmYyYjkxMjkxNjM4MGM2OWI4NTljNmIwOWNkN2Q=
12
12
  data.tar.gz: !binary |-
13
- ODYzNTI5MDJiNzdjODZkZmIxMzgyM2M4M2JlYzAzNmJlYjMwMTkzZjFjMzE1
14
- YmRlOTg0NWU1NzIzZjZhMTZlYjIxYzQxODA1YTQ5NTE4M2RlNjAzYWE5MmQ5
15
- MWE1MDMzOTczMzNlMjkwMzFkOGZiZDI4MjNlYWI1NWQ0NGIwNjU=
13
+ MDU5YTYwNWU0N2QzNzc0NzFmNGYzMmZkYjJhOGFiZjc0Zjk3ODM3Y2VhYTFl
14
+ MThjZDFiNTgzOTdmNmVhODBiOTNhNGUwOWVlOWI1N2FjOGFiZTEwMWUzZmZh
15
+ MDIwNGQ0YWZmZDU1ZTQyNzkxOTU0ZTRlYjQ5YTQ5MGQ4MTE2ODQ=
@@ -22,5 +22,26 @@ module Shuttle
22
22
  @version = 1
23
23
  end
24
24
  end
25
+
26
+ # Get current deploy version
27
+ # @return [Integer]
28
+ def last_version
29
+ @last_version ||= ssh.read_file(version_path).to_i
30
+ end
31
+
32
+ # Get list of all existing releases
33
+ # @return [Array<Integer>]
34
+ def available_releases
35
+ if ssh.directory_exists?(deploy_path('releases'))
36
+ releases = ssh.capture("ls --color=never #{deploy_path}/releases")
37
+
38
+ releases.
39
+ scan(/[\d]+/).
40
+ map { |s| s.strip.to_i }.
41
+ sort
42
+ else
43
+ []
44
+ end
45
+ end
25
46
  end
26
47
  end
@@ -81,18 +81,22 @@ module Shuttle
81
81
  ssh.open
82
82
 
83
83
  klass = Shuttle.const_get(strategy.capitalize) rescue nil
84
+ command.gsub!(/:/,'_')
85
+ exit_code = 0
84
86
 
85
87
  if klass.nil?
86
88
  STDERR.puts "Invalid strategy: #{strategy}"
87
89
  exit 1
88
90
  end
89
91
 
90
- integration = klass.new(config, ssh, server, target)
92
+ unless %w(setup deploy rollback).include?(command)
93
+ STDERR.puts "Invalid command: #{command}"
94
+ exit 1
95
+ end
96
+
97
+ integration = klass.new(config, ssh, server, target)
91
98
 
92
- command.gsub!(/:/,'_')
93
- exit_code = 0
94
99
  puts "\n"
95
-
96
100
  puts "Shuttle v#{Shuttle::VERSION}\n"
97
101
  puts "\n"
98
102
  integration.log "Connected to #{server.user}@#{server.host}"
@@ -25,6 +25,29 @@ module Shuttle
25
25
  cleanup_releases
26
26
  end
27
27
 
28
+ def rollback
29
+ if last_version == 0
30
+ error "There are no releases to rollback to"
31
+ end
32
+
33
+ release = available_releases.select { |v| v == last_version-1 }.first
34
+
35
+ if release
36
+ if ssh.run("unlink #{current_path}").failure?
37
+ ssh.run("rm -rf #{current_path}")
38
+ end
39
+
40
+ if ssh.run("ln -s #{deploy_path}/releases/#{release} #{current_path}").failure?
41
+ error "Unable to create symlink to current path"
42
+ end
43
+
44
+ ssh.run("echo #{version} > #{version_path}")
45
+ log "Rolled back to release v#{release}"
46
+ else
47
+ error "There are no older releases"
48
+ end
49
+ end
50
+
28
51
  def update_code
29
52
  if config.app.svn
30
53
  return update_code_svn
@@ -1,3 +1,3 @@
1
1
  module Shuttle
2
- VERSION = '0.2.0.beta2'
2
+ VERSION = '0.2.0.beta3'
3
3
  end
data/spec/target_spec.rb CHANGED
@@ -1,30 +1,26 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Shuttle::Target do
4
+ let(:target) { Shuttle::Target.new(attributes) }
5
+
4
6
  describe '#connection' do
5
- subject do
6
- Shuttle::Target.new(
7
- :host => 'host.com',
8
- :user => 'user',
9
- :password => 'password'
10
- )
7
+ let(:attributes) do
8
+ {:host => 'host.com', user: 'user', password: 'password'}
11
9
  end
12
10
 
13
11
  it 'returns a new ssh session connection' do
14
- subject.connection.should be_a Net::SSH::Session
12
+ expect(target.connection).to be_a Net::SSH::Session
15
13
  end
16
14
  end
17
15
 
18
16
  describe '#validate!' do
19
- subject { Shuttle::Target.new(attributes) }
20
-
21
17
  context 'with valid attributes' do
22
18
  let(:attributes) do
23
19
  {:host => 'host.com', :user => 'user', :deploy_to => '/home'}
24
20
  end
25
21
 
26
22
  it 'does not raise errors' do
27
- expect { subject.validate! }.not_to raise_error
23
+ expect { target.validate! }.not_to raise_error
28
24
  end
29
25
  end
30
26
 
@@ -34,7 +30,7 @@ describe Shuttle::Target do
34
30
  end
35
31
 
36
32
  it 'raises error' do
37
- expect { subject.validate! }.to raise_error Shuttle::ConfigError, "Deploy path required"
33
+ expect { target.validate! }.to raise_error Shuttle::ConfigError, "Deploy path required"
38
34
  end
39
35
  end
40
36
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shuttle-deploy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0.beta2
4
+ version: 0.2.0.beta3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Sosedoff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-30 00:00:00.000000000 Z
11
+ date: 2013-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake