cap_blue_green_deploy 1.0.0.pre.rc1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7dcbb168a64b8345a4ac64f2a9ab71025591e73c
4
+ data.tar.gz: bf45a7dc14a62306a00ff4c245d304015940d20d
5
+ SHA512:
6
+ metadata.gz: f7b058689c0b1260f7c5ec84dab7d55d958368892faa19513246e33c9cba5c9ffc34d84166a6b2c149eb887fe65c5f8622fd76072fc9d1f57c03a044eb3b2453
7
+ data.tar.gz: e7b88001ff0b003bc20e9d04d08df8ebb394fac4d4a542cca1a96744eda100010fe07187d6960c077ff1fdbd51bc860cceb62f282f1321c8bc48c09912ea5262
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ InstalledFiles
7
+ _yardoc
8
+ coverage
9
+ doc/
10
+ lib/bundler/man
11
+ pkg
12
+ rdoc
13
+ spec/reports
14
+ test/tmp
15
+ test/version_tmp
16
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ cap_blue_green_deploy
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.1.2
data/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # Changelog
2
+
3
+ ## 1.0.0.pre.rc1
4
+
5
+ - Adding fully functional ```cap deploy:blue_green:live``` command
6
+ - Adding fully functional ```cap deploy:blue_green:rollback``` command
7
+ - Overriding default ```cap deploy:cleanup``` command to use the gem cleanup command: ```cap deploy:blue_green:cleanup```
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,54 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ cap_blue_green_deploy (1.0.0.pre.rc1)
5
+ capistrano (>= 2.0.0, < 3.0.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ byebug (3.4.0)
11
+ columnize (~> 0.8)
12
+ debugger-linecache (~> 1.2)
13
+ slop (~> 3.6)
14
+ capistrano (2.15.5)
15
+ highline
16
+ net-scp (>= 1.0.0)
17
+ net-sftp (>= 2.0.0)
18
+ net-ssh (>= 2.0.14)
19
+ net-ssh-gateway (>= 1.1.0)
20
+ columnize (0.8.9)
21
+ debugger-linecache (1.2.0)
22
+ diff-lcs (1.2.5)
23
+ highline (1.6.21)
24
+ net-scp (1.2.1)
25
+ net-ssh (>= 2.6.5)
26
+ net-sftp (2.1.2)
27
+ net-ssh (>= 2.6.5)
28
+ net-ssh (2.9.1)
29
+ net-ssh-gateway (1.2.0)
30
+ net-ssh (>= 2.6.5)
31
+ rake (10.3.2)
32
+ rspec (3.0.0)
33
+ rspec-core (~> 3.0.0)
34
+ rspec-expectations (~> 3.0.0)
35
+ rspec-mocks (~> 3.0.0)
36
+ rspec-core (3.0.4)
37
+ rspec-support (~> 3.0.0)
38
+ rspec-expectations (3.0.4)
39
+ diff-lcs (>= 1.2.0, < 2.0)
40
+ rspec-support (~> 3.0.0)
41
+ rspec-mocks (3.0.4)
42
+ rspec-support (~> 3.0.0)
43
+ rspec-support (3.0.4)
44
+ slop (3.6.0)
45
+
46
+ PLATFORMS
47
+ ruby
48
+
49
+ DEPENDENCIES
50
+ bundler (~> 1.3)
51
+ byebug
52
+ cap_blue_green_deploy!
53
+ rake
54
+ rspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Rafael Biriba
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 ADDED
@@ -0,0 +1,33 @@
1
+ # Cap Blue Green Deploy (Under Development) [![Code Climate](https://codeclimate.com/github/rafaelbiriba/cap_blue_green_deploy/badges/gpa.svg)](https://codeclimate.com/github/rafaelbiriba/cap_blue_green_deploy) [![Travis](https://api.travis-ci.org/rafaelbiriba/cap_blue_green_deploy.svg?branch=master)](https://travis-ci.org/rafaelbiriba/cap_blue_green_deploy)
2
+
3
+ Blue-Green deployment solution for Capistrano, using symbolic links between releases.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'cap_blue_green_deploy'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install cap_blue_green_deploy
18
+
19
+ And then, require the gem script under your capistrano configuration file (Capfile, deploy.rb, ...):
20
+
21
+ require 'cap_blue_green_deploy'
22
+
23
+ ## Usage
24
+
25
+ WIP
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
7
+ task :test => :spec
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cap_blue_green_deploy/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cap_blue_green_deploy"
8
+ spec.version = CapBlueGreenDeploy::VERSION
9
+ spec.authors = ["Rafael Biriba"]
10
+ spec.email = ["biribarj@gmail.com"]
11
+ spec.description = "Blue-Green deployment solution for Capistrano, using symbolic links between releases."
12
+ spec.summary = "Blue-Green deployment solution for Capistrano"
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "capistrano", ">= 2.0.0", "< 3.0.0"
22
+ spec.add_development_dependency "bundler", "~> 1.3"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "rspec"
25
+ spec.add_development_dependency "byebug"
26
+ end
@@ -0,0 +1,4 @@
1
+ require "capistrano"
2
+
3
+ capistrano_instance = Capistrano::Configuration.instance
4
+ CapBlueGreenDeploy::Tasks.load_into(capistrano_instance) if capistrano_instance
@@ -0,0 +1,43 @@
1
+ module CapBlueGreenDeploy::Tasks::Cleanup
2
+
3
+ def cleanup_task_run
4
+ filter_local_releases!
5
+ if keep_releases >= local_releases.length
6
+ logger.important "no old releases to clean up"
7
+ else
8
+ logger.info "keeping #{keep_releases} of #{local_releases.length} deployed releases"
9
+ remove_dirs local_releases_fullpath
10
+ end
11
+ end
12
+
13
+ def local_releases_fullpath
14
+ (local_releases - local_releases.last(keep_releases)).map do |release|
15
+ File.join(releases_path, release)
16
+ end.join(" ")
17
+ end
18
+
19
+ def filter_local_releases!
20
+ current_live = File.basename fullpath_by_symlink(blue_green_live_path)
21
+ previous_live = File.basename fullpath_by_symlink(blue_green_previous_path)
22
+ local_releases.select! { |release| release != current_live && release != previous_live }
23
+ end
24
+
25
+ def local_releases
26
+ @local_releases ||= dirs_inside(releases_path)
27
+ end
28
+
29
+ def self.task_load config
30
+ config.load do
31
+ namespace :deploy do
32
+ desc "Clean up old releases"
33
+ task :cleanup do
34
+ cleanup_task_run
35
+ end
36
+
37
+ namespace :blue_green do
38
+ task :cleanup, :except => { :no_release => true } { cleanup_task_run }
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,17 @@
1
+ module CapBlueGreenDeploy::Tasks::Common
2
+ def fullpath_by_symlink sym
3
+ capture("if [ -L #{sym} ]; then readlink #{sym}; fi ").strip
4
+ end
5
+
6
+ def dirs_inside path
7
+ capture("ls -xt #{path}").split.reverse
8
+ end
9
+
10
+ def do_symlink from, to
11
+ run "rm -f #{to} && ln -s #{from} #{to}"
12
+ end
13
+
14
+ def remove_dirs dirs
15
+ try_sudo "rm -rf #{dirs}"
16
+ end
17
+ end
@@ -0,0 +1,20 @@
1
+ module CapBlueGreenDeploy::Tasks::Live
2
+ def live_task_run
3
+ current_live = fullpath_by_symlink blue_green_live_path
4
+ do_symlink current_live, blue_green_previous_path unless current_live.empty?
5
+ do_symlink current_release, blue_green_live_path
6
+ end
7
+
8
+ def self.task_load config
9
+ config.load do
10
+ namespace :deploy do
11
+ namespace :blue_green do
12
+ desc "Make the current app live"
13
+ task :live, :roles => :app, :except => { :no_release => true } { live_task_run }
14
+ end
15
+ end
16
+
17
+ after "deploy:blue_green:live", "deploy:cleanup"
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,21 @@
1
+ module CapBlueGreenDeploy::Tasks::Rollback
2
+ def rollback_task_run
3
+ previous_live = fullpath_by_symlink blue_green_previous_path
4
+ unless previous_live.empty?
5
+ do_symlink previous_live, blue_green_live_path
6
+ else
7
+ logger.important "no old release to rollback"
8
+ end
9
+ end
10
+
11
+ def self.task_load config
12
+ config.load do
13
+ namespace :deploy do
14
+ namespace :blue_green do
15
+ desc "Rollback to the previous live release"
16
+ task :rollback, :roles => :app, :except => { :no_release => true } { rollback_task_run }
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,29 @@
1
+ Gem.find_files("cap_blue_green_deploy/tasks/**/*.rb").each { |path| require path }
2
+
3
+ module CapBlueGreenDeploy::Tasks
4
+
5
+ def self.load_into config
6
+ load_libraries config
7
+ load_variables config
8
+ Live.task_load config
9
+ Rollback.task_load config
10
+ Cleanup.task_load config
11
+ end
12
+
13
+ def self.load_libraries config
14
+ config.load do
15
+ extend Common
16
+ extend Live
17
+ extend Rollback
18
+ extend Cleanup
19
+ end
20
+ end
21
+
22
+ def self.load_variables config
23
+ config.load do
24
+ _cset :keep_releases, 5
25
+ _cset :blue_green_live_path, "#{deploy_to}/current_live"
26
+ _cset :blue_green_previous_path, "#{deploy_to}/previous_live"
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ module CapBlueGreenDeploy
2
+ VERSION = "1.0.0.pre.rc1"
3
+ end
@@ -0,0 +1,7 @@
1
+ module CapBlueGreenDeploy
2
+ module Tasks; end
3
+ end
4
+
5
+ require "cap_blue_green_deploy/version"
6
+ require "cap_blue_green_deploy/tasks"
7
+ require "cap_blue_green_deploy/init"
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe "init.rb" do
4
+ it "should call tasks module init if capistrano instance exists" do
5
+ config = "config"
6
+ allow(Capistrano::Configuration).to receive(:instance).and_return(config)
7
+ expect(CapBlueGreenDeploy::Tasks).to receive(:load_into).with(config)
8
+ load Gem.find_files("cap_blue_green_deploy/init.rb").first
9
+ end
10
+
11
+ it "should not call tasks module init if capistrano instance not exists" do
12
+ allow(Capistrano::Configuration).to receive(:instance).and_return(nil)
13
+ expect(CapBlueGreenDeploy::Tasks).to_not receive(:load_into)
14
+ load Gem.find_files("cap_blue_green_deploy/init.rb").first
15
+ end
16
+ end
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ describe CapBlueGreenDeploy::Tasks::Cleanup do
4
+
5
+ class TestClass
6
+ include CapBlueGreenDeploy::Tasks::Cleanup
7
+ end
8
+
9
+ subject do
10
+ TestClass.new
11
+ end
12
+
13
+ before do
14
+ @config = double("config")
15
+ allow(@config).to receive(:load) { |&arg| arg.call }
16
+ end
17
+
18
+ describe ".task_load" do
19
+ let :subject do
20
+ CapBlueGreenDeploy::Tasks::Cleanup
21
+ end
22
+
23
+ before do
24
+ allow(subject).to receive(:namespace)
25
+ allow(subject).to receive(:desc)
26
+ allow(subject).to receive(:task)
27
+ allow(subject).to receive(:after)
28
+ end
29
+
30
+ context "capistrano default cleanup task" do
31
+ before do
32
+ allow(subject).to receive(:blue_green)
33
+ expect(subject).to receive(:namespace).with(:deploy) { |&arg| arg.call }
34
+ end
35
+
36
+ it "should define default cleanup task description" do
37
+ expect(subject).to receive(:desc).with("Clean up old releases")
38
+ subject.task_load(@config)
39
+ end
40
+
41
+ it "should set default cleanup task action" do
42
+ expect(subject).to receive(:task) { |&arg| arg.call }
43
+ expect(subject).to receive(:cleanup_task_run)
44
+ subject.task_load(@config)
45
+ end
46
+ end
47
+
48
+ context "capistrano blue green cleanup task" do
49
+ before do
50
+ expect(subject).to receive(:namespace).with(:deploy) { |&arg| arg.call }
51
+ expect(subject).to receive(:namespace).with(:blue_green) { |&arg| arg.call }
52
+ end
53
+
54
+ it "should set live task action" do
55
+ expect(subject).to receive(:task).with(:cleanup, :except => { :no_release => true }) { |&arg| arg.call }
56
+ expect(subject).to receive(:cleanup_task_run)
57
+ subject.task_load(@config)
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe CapBlueGreenDeploy::Tasks::Common do
4
+
5
+ class TestClass
6
+ include CapBlueGreenDeploy::Tasks::Common
7
+ end
8
+
9
+ subject do
10
+ TestClass.new
11
+ end
12
+
13
+ describe "#fullpath_by_symlink" do
14
+ it "should return fullpath of symlink" do
15
+ fullpath = "fullpath"
16
+ expect(subject).to receive(:capture).with("if [ -L #{fullpath} ]; then readlink #{fullpath}; fi ").and_return(fullpath + " ")
17
+ expect(subject.fullpath_by_symlink(fullpath)).to eq fullpath
18
+ end
19
+ end
20
+
21
+ describe "#dirs_inside" do
22
+ it "should return dirs name inside of symlink" do
23
+ path = "path"
24
+ dirs = ["teste1", "teste2"]
25
+ expect(subject).to receive(:capture).with("ls -xt #{path}").and_return(dirs.join(" "))
26
+ expect(subject.dirs_inside(path)).to eq dirs.reverse
27
+ end
28
+ end
29
+
30
+ describe "#do_symlink" do
31
+ it "should create new symlink" do
32
+ from = "path1"
33
+ to = "path2"
34
+ expect(subject).to receive(:run).with("rm -f #{to} && ln -s #{from} #{to}")
35
+ subject.do_symlink(from, to)
36
+ end
37
+ end
38
+
39
+ describe "#remove_dirs" do
40
+ it "should remove dirs" do
41
+ dirs = "teste1 teste2"
42
+ expect(subject).to receive(:try_sudo).with("rm -rf #{dirs}")
43
+ subject.remove_dirs(dirs)
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,87 @@
1
+ require 'spec_helper'
2
+
3
+ describe CapBlueGreenDeploy::Tasks::Live do
4
+
5
+ class TestClass
6
+ include CapBlueGreenDeploy::Tasks::Live
7
+ end
8
+
9
+ subject do
10
+ TestClass.new
11
+ end
12
+
13
+ before do
14
+ @config = double("config")
15
+ allow(@config).to receive(:load) { |&arg| arg.call }
16
+ end
17
+
18
+ describe "#live_task_run" do
19
+ let :live_path do
20
+ "live path"
21
+ end
22
+
23
+ let :previous_path do
24
+ "previous path"
25
+ end
26
+
27
+ let :current_release do
28
+ "current release"
29
+ end
30
+
31
+ before do
32
+ allow(subject).to receive(:do_symlink)
33
+ allow(subject).to receive(:fullpath_by_symlink).and_return("")
34
+ allow(subject).to receive(:blue_green_live_path).and_return(live_path)
35
+ allow(subject).to receive(:blue_green_previous_path).and_return(previous_path)
36
+ allow(subject).to receive(:current_release).and_return(current_release)
37
+ end
38
+
39
+ it "should create rollback symlink linking to current live release if exists" do
40
+ current_live = "link"
41
+ allow(subject).to receive(:fullpath_by_symlink).with(live_path).and_return(current_live)
42
+ expect(subject).to receive(:do_symlink).with(current_live, previous_path)
43
+ subject.live_task_run
44
+ end
45
+
46
+ it "should create current live symlink linking to the new release" do
47
+ expect(subject).to receive(:do_symlink).with(current_release, live_path)
48
+ subject.live_task_run
49
+ end
50
+ end
51
+
52
+ describe ".task_load" do
53
+ let :subject do
54
+ CapBlueGreenDeploy::Tasks::Live
55
+ end
56
+
57
+ before do
58
+ allow(subject).to receive(:namespace)
59
+ allow(subject).to receive(:desc)
60
+ allow(subject).to receive(:task)
61
+ allow(subject).to receive(:after)
62
+ end
63
+
64
+ it "should create callback to run cleanup after live action" do
65
+ expect(subject).to receive(:after).with("deploy:blue_green:live", "deploy:cleanup")
66
+ subject.task_load(@config)
67
+ end
68
+
69
+ context "capistrano blue green live task" do
70
+ before do
71
+ expect(subject).to receive(:namespace).with(:deploy) { |&arg| arg.call }
72
+ expect(subject).to receive(:namespace).with(:blue_green) { |&arg| arg.call }
73
+ end
74
+
75
+ it "should define live task description" do
76
+ expect(subject).to receive(:desc).with("Make the current app live")
77
+ subject.task_load(@config)
78
+ end
79
+
80
+ it "should set live task action" do
81
+ expect(subject).to receive(:task).with(:live, roles: :app, except: { no_release: true }) { |&arg| arg.call }
82
+ expect(subject).to receive(:live_task_run)
83
+ subject.task_load(@config)
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,82 @@
1
+ require 'spec_helper'
2
+
3
+ describe CapBlueGreenDeploy::Tasks::Rollback do
4
+
5
+ class TestClass
6
+ include CapBlueGreenDeploy::Tasks::Rollback
7
+ end
8
+
9
+ subject do
10
+ TestClass.new
11
+ end
12
+
13
+ before do
14
+ @config = double("config")
15
+ allow(@config).to receive(:load) { |&arg| arg.call }
16
+ end
17
+
18
+ describe "#rollback_task_run" do
19
+ let :live_path do
20
+ "live path"
21
+ end
22
+
23
+ let :previous_path do
24
+ "previous path"
25
+ end
26
+
27
+ let :current_release do
28
+ "current release"
29
+ end
30
+
31
+ before do
32
+ allow(subject).to receive(:do_symlink)
33
+ allow(subject).to receive(:fullpath_by_symlink).and_return("")
34
+ allow(subject).to receive(:blue_green_live_path).and_return(live_path)
35
+ allow(subject).to receive(:blue_green_previous_path).and_return(previous_path)
36
+ end
37
+
38
+ it "should create current live symlink linking to rollback release if exists" do
39
+ previous_live = "link"
40
+ allow(subject).to receive(:fullpath_by_symlink).with(previous_path).and_return(previous_live)
41
+ expect(subject).to receive(:do_symlink).with(previous_live, live_path)
42
+ subject.rollback_task_run
43
+ end
44
+
45
+ it "should log if no rollback releases was found" do
46
+ logger = Object
47
+ allow(subject).to receive(:logger).and_return(logger)
48
+ expect(logger).to receive(:important).with("no old release to rollback")
49
+ subject.rollback_task_run
50
+ end
51
+ end
52
+
53
+ describe ".task_load" do
54
+ let :subject do
55
+ CapBlueGreenDeploy::Tasks::Rollback
56
+ end
57
+
58
+ before do
59
+ allow(subject).to receive(:namespace)
60
+ allow(subject).to receive(:desc)
61
+ allow(subject).to receive(:task)
62
+ end
63
+
64
+ context "capistrano blue green rollback task" do
65
+ before do
66
+ expect(subject).to receive(:namespace).with(:deploy) { |&arg| arg.call }
67
+ expect(subject).to receive(:namespace).with(:blue_green) { |&arg| arg.call }
68
+ end
69
+
70
+ it "should define rollback task description" do
71
+ expect(subject).to receive(:desc).with("Rollback to the previous live release")
72
+ subject.task_load(@config)
73
+ end
74
+
75
+ it "should set rollback task action" do
76
+ expect(subject).to receive(:task).with(:rollback, roles: :app, except: { no_release: true }) { |&arg| arg.call }
77
+ expect(subject).to receive(:rollback_task_run)
78
+ subject.task_load(@config)
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,110 @@
1
+ require 'spec_helper'
2
+
3
+ describe CapBlueGreenDeploy::Tasks do
4
+ subject do
5
+ CapBlueGreenDeploy::Tasks
6
+ end
7
+
8
+ before do
9
+ @config = double("config")
10
+ allow(@config).to receive(:load) { |&arg| arg.call }
11
+ end
12
+
13
+ describe ".load_into" do
14
+ before do
15
+ allow(subject).to receive(:load_libraries)
16
+ allow(subject).to receive(:load_variables)
17
+ allow(subject::Live).to receive(:task_load)
18
+ allow(subject::Rollback).to receive(:task_load)
19
+ allow(subject::Cleanup).to receive(:task_load)
20
+ end
21
+
22
+ after do
23
+ subject.load_into @config
24
+ end
25
+
26
+ it "should call load_libraries" do
27
+ expect(subject).to receive(:load_libraries).with(@config)
28
+ end
29
+
30
+ it "should call load_variables" do
31
+ expect(subject).to receive(:load_variables).with(@config)
32
+ end
33
+
34
+ it "should call Live.task_load" do
35
+ expect(subject::Live).to receive(:task_load).with(@config)
36
+ end
37
+
38
+ it "should call Rollback.task_load" do
39
+ expect(subject::Rollback).to receive(:task_load).with(@config)
40
+ end
41
+
42
+ it "should call Cleanup.task_load" do
43
+ expect(subject::Cleanup).to receive(:task_load).with(@config)
44
+ end
45
+ end
46
+
47
+ describe ".load_libraries" do
48
+ module CapBlueGreenDeploy::Tasks::Live
49
+ def test_live; end
50
+ end
51
+
52
+ module CapBlueGreenDeploy::Tasks::Rollback
53
+ def test_rollback; end
54
+ end
55
+
56
+ module CapBlueGreenDeploy::Tasks::Cleanup
57
+ def test_cleanup; end
58
+ end
59
+
60
+ module CapBlueGreenDeploy::Tasks::Common
61
+ def test_common; end
62
+ end
63
+
64
+ before do
65
+ subject.load_libraries @config
66
+ end
67
+
68
+ it "should load live tasks" do
69
+ expect(subject).to respond_to :test_live
70
+ end
71
+
72
+ it "should load rollback tasks" do
73
+ expect(subject).to respond_to :test_rollback
74
+ end
75
+
76
+ it "should load cleanup tasks" do
77
+ expect(subject).to respond_to :test_cleanup
78
+ end
79
+
80
+ it "should load common tasks" do
81
+ expect(subject).to respond_to :test_common
82
+ end
83
+ end
84
+
85
+ describe ".load_variables" do
86
+ before do
87
+ allow(subject).to receive(:_cset)
88
+ allow(subject).to receive(:deploy_to).and_return(deploy_to)
89
+ end
90
+
91
+ let :deploy_to do
92
+ "/home"
93
+ end
94
+
95
+ it "should set keep_releases variable" do
96
+ expect(subject).to receive(:_cset).with(:keep_releases, 5)
97
+ subject.load_variables @config
98
+ end
99
+
100
+ it "should set blue_green_live_path variable" do
101
+ expect(subject).to receive(:_cset).with(:blue_green_live_path, "#{deploy_to}/current_live")
102
+ subject.load_variables @config
103
+ end
104
+
105
+ it "should set blue_green_previous_path variable" do
106
+ expect(subject).to receive(:_cset).with(:blue_green_previous_path, "#{deploy_to}/previous_live")
107
+ subject.load_variables @config
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,83 @@
1
+ require "rake"
2
+ require "byebug"
3
+ require "capistrano"
4
+ require "cap_blue_green_deploy"
5
+
6
+ # This file was generated by the `rspec --init` command. Conventionally, all
7
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
8
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
9
+ # file to always be loaded, without a need to explicitly require it in any files.
10
+ #
11
+ # Given that it is always loaded, you are encouraged to keep this file as
12
+ # light-weight as possible. Requiring heavyweight dependencies from this file
13
+ # will add to the boot time of your test suite on EVERY test run, even for an
14
+ # individual file that may not need all of that loaded. Instead, make a
15
+ # separate helper file that requires this one and then use it only in the specs
16
+ # that actually need it.
17
+ #
18
+ # The `.rspec` file also contains a few flags that are not defaults but that
19
+ # users commonly want.
20
+ #
21
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
22
+ RSpec.configure do |config|
23
+ # The settings below are suggested to provide a good initial experience
24
+ # with RSpec, but feel free to customize to your heart's content.
25
+ # These two settings work together to allow you to limit a spec run
26
+ # to individual examples or groups you care about by tagging them with
27
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
28
+ # get run.
29
+ config.filter_run :focus
30
+ config.run_all_when_everything_filtered = true
31
+
32
+ # Many RSpec users commonly either run the entire suite or an individual
33
+ # file, and it's useful to allow more verbose output when running an
34
+ # individual spec file.
35
+ if config.files_to_run.one?
36
+ # Use the documentation formatter for detailed output,
37
+ # unless a formatter has already been configured
38
+ # (e.g. via a command-line flag).
39
+ config.default_formatter = 'doc'
40
+ end
41
+
42
+ # Print the 10 slowest examples and example groups at the
43
+ # end of the spec run, to help surface which specs are running
44
+ # particularly slow.
45
+ config.profile_examples = 10
46
+
47
+ # Run specs in random order to surface order dependencies. If you find an
48
+ # order dependency and want to debug it, you can fix the order by providing
49
+ # the seed, which is printed after each run.
50
+ # --seed 1234
51
+ config.order = :random
52
+
53
+ # Seed global randomization in this process using the `--seed` CLI option.
54
+ # Setting this allows you to use `--seed` to deterministically reproduce
55
+ # test failures related to randomization by passing the same `--seed` value
56
+ # as the one that triggered the failure.
57
+ Kernel.srand config.seed
58
+
59
+ # rspec-expectations config goes here. You can use an alternate
60
+ # assertion/expectation library such as wrong or the stdlib/minitest
61
+ # assertions if you prefer.
62
+ config.expect_with :rspec do |expectations|
63
+ # Enable only the newer, non-monkey-patching expect syntax.
64
+ # For more details, see:
65
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
66
+ expectations.syntax = :expect
67
+ end
68
+
69
+ # rspec-mocks config goes here. You can use an alternate test double
70
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
71
+ config.mock_with :rspec do |mocks|
72
+ # Enable only the newer, non-monkey-patching expect syntax.
73
+ # For more details, see:
74
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
75
+ mocks.syntax = :expect
76
+
77
+ # Prevents you from mocking or stubbing a method that does not exist on
78
+ # a real object. This is generally recommended.
79
+ mocks.verify_partial_doubles = false
80
+ end
81
+ end
82
+
83
+ Dir["./spec/support/**/*.rb"].sort.each { |f| require f; puts f}
metadata ADDED
@@ -0,0 +1,154 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cap_blue_green_deploy
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.pre.rc1
5
+ platform: ruby
6
+ authors:
7
+ - Rafael Biriba
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capistrano
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 2.0.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: 3.0.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 2.0.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: 3.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.3'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.3'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: byebug
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ description: Blue-Green deployment solution for Capistrano, using symbolic links between
90
+ releases.
91
+ email:
92
+ - biribarj@gmail.com
93
+ executables: []
94
+ extensions: []
95
+ extra_rdoc_files: []
96
+ files:
97
+ - ".gitignore"
98
+ - ".rspec"
99
+ - ".ruby-gemset"
100
+ - ".ruby-version"
101
+ - CHANGELOG.md
102
+ - Gemfile
103
+ - Gemfile.lock
104
+ - LICENSE.txt
105
+ - README.md
106
+ - Rakefile
107
+ - cap_blue_green_deploy.gemspec
108
+ - lib/cap_blue_green_deploy.rb
109
+ - lib/cap_blue_green_deploy/init.rb
110
+ - lib/cap_blue_green_deploy/tasks.rb
111
+ - lib/cap_blue_green_deploy/tasks/cleanup.rb
112
+ - lib/cap_blue_green_deploy/tasks/common.rb
113
+ - lib/cap_blue_green_deploy/tasks/live.rb
114
+ - lib/cap_blue_green_deploy/tasks/rollback.rb
115
+ - lib/cap_blue_green_deploy/version.rb
116
+ - spec/lib/cap_blue_green_deploy/init_spec.rb
117
+ - spec/lib/cap_blue_green_deploy/tasks/cleanup_spec.rb
118
+ - spec/lib/cap_blue_green_deploy/tasks/common_spec.rb
119
+ - spec/lib/cap_blue_green_deploy/tasks/live_spec.rb
120
+ - spec/lib/cap_blue_green_deploy/tasks/rollback_spec.rb
121
+ - spec/lib/cap_blue_green_deploy/tasks_spec.rb
122
+ - spec/spec_helper.rb
123
+ homepage: ''
124
+ licenses:
125
+ - MIT
126
+ metadata: {}
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">"
139
+ - !ruby/object:Gem::Version
140
+ version: 1.3.1
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 2.1.11
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: Blue-Green deployment solution for Capistrano
147
+ test_files:
148
+ - spec/lib/cap_blue_green_deploy/init_spec.rb
149
+ - spec/lib/cap_blue_green_deploy/tasks/cleanup_spec.rb
150
+ - spec/lib/cap_blue_green_deploy/tasks/common_spec.rb
151
+ - spec/lib/cap_blue_green_deploy/tasks/live_spec.rb
152
+ - spec/lib/cap_blue_green_deploy/tasks/rollback_spec.rb
153
+ - spec/lib/cap_blue_green_deploy/tasks_spec.rb
154
+ - spec/spec_helper.rb