cap_blue_green_deploy 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +1 -1
- data/README.md +100 -2
- data/docs/1.server_clean.png +0 -0
- data/docs/2.deploy_setup.png +0 -0
- data/docs/3.1.releases.three_deploys.png +0 -0
- data/docs/3.2.three_deploys.png +0 -0
- data/docs/4.1.releases.deploy_blue_green_live.png +0 -0
- data/docs/4.2.deploy_blue_green_live.png +0 -0
- data/docs/5.1.releases.two_deploy.png +0 -0
- data/docs/5.2.two_deploy.png +0 -0
- data/docs/6.1.releases.deploy_blue_green_live.png +0 -0
- data/docs/6.2.deploy_blue_green_live.png +0 -0
- data/docs/7.1.releases.deploy_blue_green_rollback.png +0 -0
- data/docs/7.2.deploy_blue_green_rollback.png +0 -0
- data/docs/8.1.releases.one_deploy.png +0 -0
- data/docs/8.2.one_deploy.png +0 -0
- data/docs/9.1.deploy_blue_green_live.png +0 -0
- data/docs/architecture.png +0 -0
- data/docs/custom_variables.png +0 -0
- data/lib/cap_blue_green_deploy/tasks.rb +4 -2
- data/lib/cap_blue_green_deploy/tasks/deploy.rb +14 -0
- data/lib/cap_blue_green_deploy/version.rb +1 -1
- data/spec/lib/cap_blue_green_deploy/tasks/deploy_spec.rb +52 -0
- data/spec/lib/cap_blue_green_deploy/tasks_spec.rb +15 -2
- metadata +22 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d0abc2d30a99d73e2f5dc1dc5af4081f6d01ad5
|
4
|
+
data.tar.gz: 9fc38baddcc1e6e35d5f22ff5b949bcee25badf2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8342b6167486f372e5773105043f1a7e8743922320cfd3050192d967228bc08c09b36512983dee4cb1e28e8e4f6e096b98e3e77a06160ea552e0dda912092c58
|
7
|
+
data.tar.gz: 761b01ad9ea6d12bb1e2f48e3ef718c66e79c6a2d63a1feaa6626d5ac8d400994cfafbaaa7b954d3b6f64242879c794281ddeade969f531a6e662257a90dbc3a
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,24 @@
|
|
1
|
-
# Cap Blue Green Deploy (
|
1
|
+
# Cap Blue Green Deploy [![Gem Version](https://badge.fury.io/rb/cap_blue_green_deploy.svg)](http://badge.fury.io/rb/cap_blue_green_deploy) [![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) [![Coverage Status](https://coveralls.io/repos/rafaelbiriba/cap_blue_green_deploy/badge.png?branch=master)](https://coveralls.io/r/rafaelbiriba/cap_blue_green_deploy?branch=master)
|
2
2
|
|
3
3
|
Blue-Green deployment solution for Capistrano, using symbolic links between releases.
|
4
4
|
|
5
|
+
## Blue Green Concept
|
6
|
+
|
7
|
+
Learn more about
|
8
|
+
[Blue Green Deployment with Martin Fowler](http://martinfowler.com/bliki/BlueGreenDeployment.html)
|
9
|
+
|
10
|
+
## Introduction
|
11
|
+
|
12
|
+
**Cap Blue Green Deployment** is a non canonical Blue Green solution, based on symlinks. Instead of having **blue** and **green**, we have **pre** and **live**. Pre is always validation environment and live it's production environment.
|
13
|
+
|
14
|
+
![architecture](docs/architecture.png?a)
|
15
|
+
|
16
|
+
You can do as many deploys you need to **pre** without affecting the live env. Changing symlinks you can easily put your code from validation to production environment.
|
17
|
+
|
18
|
+
## Prerequisite
|
19
|
+
|
20
|
+
- Capistrano 2 (Capistrano 3 coming soon)
|
21
|
+
|
5
22
|
## Installation
|
6
23
|
|
7
24
|
Add this line to your application's Gemfile:
|
@@ -22,7 +39,88 @@ And then, require the gem script under your capistrano configuration file (Capfi
|
|
22
39
|
|
23
40
|
## Usage
|
24
41
|
|
25
|
-
|
42
|
+
### Understanding the deploy folder:
|
43
|
+
|
44
|
+
- **current**: Pre environment. Used to test and validate your application.
|
45
|
+
- **current_live**: Live environment. You production access goes here. *This dir name can be customized in custom variables, see below*
|
46
|
+
- **previous_live**: Last live release. Used to do the rollback action of current_live. *This dir name can be customized in custom variables, see below*
|
47
|
+
|
48
|
+
### Deploy Commands:
|
49
|
+
|
50
|
+
* **Going to Pre** `cap deploy:blue_green:pre`
|
51
|
+
|
52
|
+
This command is an alias for `cap deploy` default task. It will run the deploy process and will create the `current` release
|
53
|
+
|
54
|
+
* **Going to Live** `cap deploy:blue_green:live`
|
55
|
+
|
56
|
+
This command will change symlinks of `current_live` dir to keep the the same release path of `current` dir. And also create the `previous_live` symlink to track the last current live release used.
|
57
|
+
|
58
|
+
**More explanations**
|
59
|
+
|
60
|
+
If `current_live` already exists, the `previous_live` dir will be created/updated, copying the same symlink of `current live` release, to keep traking the last valid release.
|
61
|
+
|
62
|
+
Finally, the command will create/update the `current_live` symlink, copying the same symlink of `current` release.
|
63
|
+
|
64
|
+
* **Rollbacking** `cap deploy:blue_green:rollback`
|
65
|
+
|
66
|
+
This command will change the `current_live` symlink to use the same destination of `previous_live` symlink.
|
67
|
+
|
68
|
+
* **Cleanup** `cap deploy:blue_green:cleanup`
|
69
|
+
|
70
|
+
This is the same behavior of the default capistrano cleanup `deploy:cleanup`, but the `current_live` and `previous_live` releases will be preserved and not removed.
|
71
|
+
|
72
|
+
**This lib automatically rewrite the default deploy:cleanup to use this new cleanup function.**
|
73
|
+
|
74
|
+
**Don't forget that you need to add the cleanup callback manually in your capistrano file:** `after "deploy:update", "deploy:cleanup"`
|
75
|
+
|
76
|
+
* **Custom Variables**
|
77
|
+
|
78
|
+
You can change the default value setting new variable in your capistrano file. The default values is:
|
79
|
+
- keep_releases: 5
|
80
|
+
- blue_green_live_dir: "current_live"
|
81
|
+
- blue_green_previous_dir: "previous_live"
|
82
|
+
|
83
|
+
## How to Play
|
84
|
+
**Custom Variables used**
|
85
|
+
- `set :keep_releases, 2`
|
86
|
+
- `set :blue_green_live_dir, "current_live"`
|
87
|
+
- `set :blue_green_previous_dir, "previous_live"`
|
88
|
+
|
89
|
+
**1. Starting with clean server**
|
90
|
+
![Clean server](docs/1.server_clean.png)
|
91
|
+
|
92
|
+
**2. Running `cap deploy:setup` to prepare the server**
|
93
|
+
![Deploy setup](docs/2.deploy_setup.png)
|
94
|
+
|
95
|
+
**3. Running `cap deploy` three times to populate the release folder (cleanup code removes one old release)**
|
96
|
+
![Deploy](docs/3.1.releases.three_deploys.png)
|
97
|
+
![Deploy](docs/3.2.three_deploys.png)
|
98
|
+
|
99
|
+
**4. Going to live `cap deploy:blue_green:live` (current_live dir will be created. No changes in releases dir)**
|
100
|
+
![Blue Green Live](docs/4.1.releases.deploy_blue_green_live.png)
|
101
|
+
![Blue Green Live](docs/4.2.deploy_blue_green_live.png)
|
102
|
+
|
103
|
+
**5. Running two more deploy with `cap deploy` (current_live will not change. Cleanup remove one old release.)**
|
104
|
+
![Deploy](docs/5.1.releases.two_deploy.png)
|
105
|
+
![Deploy](docs/5.2.two_deploy.png)
|
106
|
+
|
107
|
+
**6. Going to live again with `cap deploy:blue_green:live` (At this time, previous_live will be created, targeting the current_live release before change it. No changes in releases dir)**
|
108
|
+
![Blue Green Live](docs/6.1.releases.deploy_blue_green_live.png)
|
109
|
+
![Blue Green Live](docs/6.2.deploy_blue_green_live.png)
|
110
|
+
|
111
|
+
**7. Something goes wrong... Rollbacking with `cap deploy:blue_green:rollback` (The current_live will change to target the same release of previous_live. No changes in releases dir)**
|
112
|
+
![Blue Green Rollback](docs/7.1.releases.deploy_blue_green_rollback.png)
|
113
|
+
![Blue Green Rollback](docs/7.2.deploy_blue_green_rollback.png)
|
114
|
+
|
115
|
+
**8. Running one more deploy with `cap deploy` (current_live and previous_live will not change. Cleanup remove one old release.)***
|
116
|
+
![Deploy](docs/8.1.releases.one_deploy.png)
|
117
|
+
![Deploy](docs/8.2.one_deploy.png)
|
118
|
+
|
119
|
+
**9. Going to live again with `cap deploy:blue_green:live`**
|
120
|
+
![Deploy](docs/9.1.deploy_blue_green_live.png)
|
121
|
+
|
122
|
+
**Changing current_live and previous_live variables to use custom names (custom_live_path, custom_rollback_path)**
|
123
|
+
![Custom names](docs/custom_variables.png)
|
26
124
|
|
27
125
|
## Contributing
|
28
126
|
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -8,6 +8,7 @@ module CapBlueGreenDeploy::Tasks
|
|
8
8
|
Live.task_load config
|
9
9
|
Rollback.task_load config
|
10
10
|
Cleanup.task_load config
|
11
|
+
Deploy.task_load config
|
11
12
|
end
|
12
13
|
|
13
14
|
def self.load_libraries config
|
@@ -16,14 +17,15 @@ module CapBlueGreenDeploy::Tasks
|
|
16
17
|
extend Live
|
17
18
|
extend Rollback
|
18
19
|
extend Cleanup
|
20
|
+
extend Deploy
|
19
21
|
end
|
20
22
|
end
|
21
23
|
|
22
24
|
def self.load_variables config
|
23
25
|
config.load do
|
24
26
|
_cset :keep_releases, 5
|
25
|
-
_cset :
|
26
|
-
_cset :
|
27
|
+
_cset :blue_green_live_dir, "#{deploy_to}/current_live"
|
28
|
+
_cset :blue_green_previous_dir, "#{deploy_to}/previous_live"
|
27
29
|
end
|
28
30
|
end
|
29
31
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module CapBlueGreenDeploy::Tasks::Deploy
|
2
|
+
def self.task_load config
|
3
|
+
config.load do
|
4
|
+
namespace :deploy do
|
5
|
+
namespace :blue_green do
|
6
|
+
desc "Deploy your project to pre environment"
|
7
|
+
task :pre, :roles => :app, :except => { :no_release => true } {}
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
after "deploy:blue_green:pre", "deploy"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CapBlueGreenDeploy::Tasks::Deploy do
|
4
|
+
|
5
|
+
class TestClass
|
6
|
+
include CapBlueGreenDeploy::Tasks::Deploy
|
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::Deploy
|
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 blue green pre task" do
|
31
|
+
before do
|
32
|
+
expect(subject).to receive(:namespace).with(:deploy) { |&arg| arg.call }
|
33
|
+
expect(subject).to receive(:namespace).with(:blue_green) { |&arg| arg.call }
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should define pre task description" do
|
37
|
+
expect(subject).to receive(:desc).with("Deploy your project to pre environment")
|
38
|
+
subject.task_load(@config)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should set pre task action" do
|
42
|
+
expect(subject).to receive(:task).with(:pre, roles: :app, except: { no_release: true })
|
43
|
+
subject.task_load(@config)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should create callback to run capistrano deploy after pre action" do
|
47
|
+
expect(subject).to receive(:after).with("deploy:blue_green:pre", "deploy")
|
48
|
+
subject.task_load(@config)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -17,6 +17,7 @@ describe CapBlueGreenDeploy::Tasks do
|
|
17
17
|
allow(subject::Live).to receive(:task_load)
|
18
18
|
allow(subject::Rollback).to receive(:task_load)
|
19
19
|
allow(subject::Cleanup).to receive(:task_load)
|
20
|
+
allow(subject::Deploy).to receive(:task_load)
|
20
21
|
end
|
21
22
|
|
22
23
|
after do
|
@@ -42,6 +43,10 @@ describe CapBlueGreenDeploy::Tasks do
|
|
42
43
|
it "should call Cleanup.task_load" do
|
43
44
|
expect(subject::Cleanup).to receive(:task_load).with(@config)
|
44
45
|
end
|
46
|
+
|
47
|
+
it "should call Cleanup.task_load" do
|
48
|
+
expect(subject::Deploy).to receive(:task_load).with(@config)
|
49
|
+
end
|
45
50
|
end
|
46
51
|
|
47
52
|
describe ".load_libraries" do
|
@@ -61,6 +66,10 @@ describe CapBlueGreenDeploy::Tasks do
|
|
61
66
|
def test_common; end
|
62
67
|
end
|
63
68
|
|
69
|
+
module CapBlueGreenDeploy::Tasks::Deploy
|
70
|
+
def test_deploy; end
|
71
|
+
end
|
72
|
+
|
64
73
|
before do
|
65
74
|
subject.load_libraries @config
|
66
75
|
end
|
@@ -80,6 +89,10 @@ describe CapBlueGreenDeploy::Tasks do
|
|
80
89
|
it "should load common tasks" do
|
81
90
|
expect(subject).to respond_to :test_common
|
82
91
|
end
|
92
|
+
|
93
|
+
it "should load common deploy" do
|
94
|
+
expect(subject).to respond_to :test_deploy
|
95
|
+
end
|
83
96
|
end
|
84
97
|
|
85
98
|
describe ".load_variables" do
|
@@ -98,12 +111,12 @@ describe CapBlueGreenDeploy::Tasks do
|
|
98
111
|
end
|
99
112
|
|
100
113
|
it "should set blue_green_live_path variable" do
|
101
|
-
expect(subject).to receive(:_cset).with(:
|
114
|
+
expect(subject).to receive(:_cset).with(:blue_green_live_dir, "#{deploy_to}/current_live")
|
102
115
|
subject.load_variables @config
|
103
116
|
end
|
104
117
|
|
105
118
|
it "should set blue_green_previous_path variable" do
|
106
|
-
expect(subject).to receive(:_cset).with(:
|
119
|
+
expect(subject).to receive(:_cset).with(:blue_green_previous_dir, "#{deploy_to}/previous_live")
|
107
120
|
subject.load_variables @config
|
108
121
|
end
|
109
122
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cap_blue_green_deploy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rafael Biriba
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capistrano
|
@@ -119,17 +119,36 @@ files:
|
|
119
119
|
- README.md
|
120
120
|
- Rakefile
|
121
121
|
- cap_blue_green_deploy.gemspec
|
122
|
+
- docs/1.server_clean.png
|
123
|
+
- docs/2.deploy_setup.png
|
124
|
+
- docs/3.1.releases.three_deploys.png
|
125
|
+
- docs/3.2.three_deploys.png
|
126
|
+
- docs/4.1.releases.deploy_blue_green_live.png
|
127
|
+
- docs/4.2.deploy_blue_green_live.png
|
128
|
+
- docs/5.1.releases.two_deploy.png
|
129
|
+
- docs/5.2.two_deploy.png
|
130
|
+
- docs/6.1.releases.deploy_blue_green_live.png
|
131
|
+
- docs/6.2.deploy_blue_green_live.png
|
132
|
+
- docs/7.1.releases.deploy_blue_green_rollback.png
|
133
|
+
- docs/7.2.deploy_blue_green_rollback.png
|
134
|
+
- docs/8.1.releases.one_deploy.png
|
135
|
+
- docs/8.2.one_deploy.png
|
136
|
+
- docs/9.1.deploy_blue_green_live.png
|
137
|
+
- docs/architecture.png
|
138
|
+
- docs/custom_variables.png
|
122
139
|
- lib/cap_blue_green_deploy.rb
|
123
140
|
- lib/cap_blue_green_deploy/init.rb
|
124
141
|
- lib/cap_blue_green_deploy/tasks.rb
|
125
142
|
- lib/cap_blue_green_deploy/tasks/cleanup.rb
|
126
143
|
- lib/cap_blue_green_deploy/tasks/common.rb
|
144
|
+
- lib/cap_blue_green_deploy/tasks/deploy.rb
|
127
145
|
- lib/cap_blue_green_deploy/tasks/live.rb
|
128
146
|
- lib/cap_blue_green_deploy/tasks/rollback.rb
|
129
147
|
- lib/cap_blue_green_deploy/version.rb
|
130
148
|
- spec/lib/cap_blue_green_deploy/init_spec.rb
|
131
149
|
- spec/lib/cap_blue_green_deploy/tasks/cleanup_spec.rb
|
132
150
|
- spec/lib/cap_blue_green_deploy/tasks/common_spec.rb
|
151
|
+
- spec/lib/cap_blue_green_deploy/tasks/deploy_spec.rb
|
133
152
|
- spec/lib/cap_blue_green_deploy/tasks/live_spec.rb
|
134
153
|
- spec/lib/cap_blue_green_deploy/tasks/rollback_spec.rb
|
135
154
|
- spec/lib/cap_blue_green_deploy/tasks_spec.rb
|
@@ -162,6 +181,7 @@ test_files:
|
|
162
181
|
- spec/lib/cap_blue_green_deploy/init_spec.rb
|
163
182
|
- spec/lib/cap_blue_green_deploy/tasks/cleanup_spec.rb
|
164
183
|
- spec/lib/cap_blue_green_deploy/tasks/common_spec.rb
|
184
|
+
- spec/lib/cap_blue_green_deploy/tasks/deploy_spec.rb
|
165
185
|
- spec/lib/cap_blue_green_deploy/tasks/live_spec.rb
|
166
186
|
- spec/lib/cap_blue_green_deploy/tasks/rollback_spec.rb
|
167
187
|
- spec/lib/cap_blue_green_deploy/tasks_spec.rb
|