kikubari 0.0.4 → 0.1.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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +39 -27
- data/bin/kikubari +24 -55
- data/kikubari.gemspec +1 -7
- data/lib/configuration/deploy_configuration.rb +13 -55
- data/lib/deploy_dir.rb +5 -9
- data/lib/deployer/deployer.rb +37 -54
- data/lib/kikubari.rb +1 -1
- data/spec/deploy_files/deploy.yml +24 -24
- data/spec/deploy_files/deploy_git.yml +2 -7
- data/spec/deploy_files/deploy_git_test_file.yml +3 -3
- data/spec/deploy_files/deploy_symlink.yml +10 -17
- data/spec/deploy_files/one_file_test.yml +3 -3
- data/spec/deploy_files/one_folder.yml +2 -2
- data/spec/lib/deploy_spec.rb +67 -64
- data/spec/lib/deployers/git.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e2e03ad197ee1cec9342335ed3faf4ac1464e0c
|
4
|
+
data.tar.gz: 5ca5c1981325542b2eeef95d6215aa913e9fd441
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70c6cb5f75e0bd9aafb7fba030e68df8ba8b682a5dedc6bfe42eb06b8a8ca074a902a489475ff8f8fb368692f8bfb94927fbd269e297faf0508b835e29790195
|
7
|
+
data.tar.gz: 712c7532fb5e09c0118feb2238e15e8d6cca0139ce9ebbdf96138b43d5149b2f3b22f5f1c300777326d8fbb975270b6ac6f4aee87765cca0acfe896063580136
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -8,50 +8,62 @@ If you need a more complex solution maybe you want to take a look on Capistrano.
|
|
8
8
|
|
9
9
|
## Usage:
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
* Create a *deploy.yml* file in your deploy target folder
|
12
|
+
* Run *kikubari*:: */path_to_folder* or ./
|
13
|
+
* Have a beer and see it work
|
14
14
|
|
15
|
-
|
15
|
+
```
|
16
|
+
project
|
17
|
+
│ deploy.yml
|
18
|
+
│ ...
|
16
19
|
|
17
|
-
|
20
|
+
```
|
21
|
+
|
22
|
+
```bash
|
23
|
+
kikubari .
|
24
|
+
```
|
25
|
+
|
26
|
+
|
27
|
+
Result:
|
28
|
+
|
29
|
+
```
|
30
|
+
project
|
31
|
+
│ deploy.yml
|
32
|
+
│
|
33
|
+
└── releases
|
34
|
+
│ │ 12345678
|
35
|
+
│ │ current
|
36
|
+
│
|
37
|
+
└── your_folder
|
38
|
+
│ your_files
|
39
|
+
|
40
|
+
```
|
41
|
+
|
42
|
+
# Examples
|
18
43
|
|
19
44
|
### Wordpress
|
20
45
|
|
46
|
+
```ruby
|
47
|
+
|
21
48
|
config:
|
22
49
|
framework: wordpress
|
23
50
|
system: git
|
24
|
-
origin: "git@github.com:josetonyp/
|
51
|
+
origin: "git@github.com:josetonyp/path_to_project.git"
|
25
52
|
branch: master
|
26
53
|
history_limit: 10
|
27
54
|
|
28
55
|
do:
|
29
56
|
folder_structure:
|
30
|
-
log: 'log
|
31
|
-
uploads: 'uploads
|
32
|
-
config: 'config
|
33
|
-
coda_cache: 'coda_cache
|
57
|
+
log: 'log'
|
58
|
+
uploads: 'uploads'
|
59
|
+
config: 'config'
|
60
|
+
coda_cache: 'coda_cache'
|
34
61
|
|
35
|
-
|
62
|
+
link_files:
|
36
63
|
uploads: 'wp-content/uploads'
|
37
64
|
coda_cache: 'wp-content/themes/coda/cache'
|
38
65
|
|
39
|
-
|
40
|
-
config: 'wp-config.php'
|
41
|
-
|
42
|
-
test_files:
|
43
|
-
config: 'config/#{environment}/wp-config.php'
|
44
|
-
|
45
|
-
|
46
|
-
### Symfony
|
47
|
-
|
48
|
-
On proccess...
|
49
|
-
|
50
|
-
## Ruby
|
51
|
-
|
52
|
-
### Rails
|
53
|
-
|
54
|
-
On proccess...
|
66
|
+
```
|
55
67
|
|
56
68
|
# Contributing to kikubari
|
57
69
|
|
data/bin/kikubari
CHANGED
@@ -8,7 +8,7 @@ require "stringio"
|
|
8
8
|
require 'open3'
|
9
9
|
require 'git'
|
10
10
|
|
11
|
-
|
11
|
+
require_relative '../lib/kikubari'
|
12
12
|
|
13
13
|
##Globals
|
14
14
|
debug, dry_run, rollback = false, false, false
|
@@ -39,65 +39,34 @@ loop do
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
begin
|
47
|
-
|
42
|
+
if (!ARGV.first.nil? and File.directory? ARGV.first.to_s)
|
43
|
+
folder = ARGV.first.to_s
|
44
|
+
else
|
45
|
+
begin
|
48
46
|
print "Please insert the project folder to deploy: "
|
49
47
|
folder = gets.chomp
|
48
|
+
end until begin
|
50
49
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
puts "Deploying to #{folder}"
|
55
|
-
true
|
56
|
-
rescue Exception => e
|
57
|
-
print e.message
|
58
|
-
puts e.backtrace.inspect
|
59
|
-
false
|
60
|
-
end
|
50
|
+
##FileUtils.cd folder
|
51
|
+
puts "Deploying to #{folder}"
|
52
|
+
true
|
61
53
|
|
54
|
+
rescue Exception => e
|
55
|
+
print e.message
|
56
|
+
puts e.backtrace.inspect
|
57
|
+
false
|
62
58
|
end
|
59
|
+
end
|
63
60
|
|
64
|
-
|
61
|
+
folder = Pathname.new(folder).realpath
|
65
62
|
p "Deploying to #{ Pathname.new( folder ).realpath }/..."
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
print "Production [1] or preproduction [2] ? (1,2) : "
|
77
|
-
environment = gets.chomp
|
78
|
-
|
79
|
-
end until begin
|
80
|
-
if environment =~ /1|2/
|
81
|
-
true
|
82
|
-
else
|
83
|
-
false
|
84
|
-
end
|
85
|
-
rescue Exception => e
|
86
|
-
print e.message
|
87
|
-
puts e.backtrace.inspect
|
88
|
-
false
|
89
|
-
end
|
90
|
-
|
91
|
-
case environment
|
92
|
-
when "1"
|
93
|
-
env_folder = "production"
|
94
|
-
when "2"
|
95
|
-
env_folder = "preproduction"
|
96
|
-
end
|
97
|
-
|
98
|
-
end
|
99
|
-
|
100
|
-
p "Deploying on environment < #{ env_folder } >..."
|
101
|
-
|
102
|
-
Kikubari::Deploy.new(Kikubari::Deploy::Configuration.new( "#{folder}/deploy.yml", :deploy_folder => folder, :debug => debug, :dry_run => dry_run , :environment => env_folder, :rollback => rollback ))
|
63
|
+
p "Deploying ..."
|
64
|
+
|
65
|
+
Kikubari::Deploy.new(
|
66
|
+
Kikubari::Deploy::Configuration.new(
|
67
|
+
"#{folder}/deploy.yml",
|
68
|
+
deploy_folder: folder,
|
69
|
+
debug: debug,
|
70
|
+
dry_run: dry_run,
|
71
|
+
rollback: rollback ))
|
103
72
|
|
data/kikubari.gemspec
CHANGED
@@ -1,12 +1,6 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: kikubari 0.0.3 ruby lib
|
6
|
-
|
7
1
|
Gem::Specification.new do |s|
|
8
2
|
s.name = "kikubari"
|
9
|
-
s.version = "0.0
|
3
|
+
s.version = "0.1.0"
|
10
4
|
|
11
5
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
6
|
s.require_paths = ["lib"]
|
@@ -10,7 +10,6 @@ module Kikubari
|
|
10
10
|
attr_accessor :deploy_folder,
|
11
11
|
:debug,
|
12
12
|
:dry_run,
|
13
|
-
:environment,
|
14
13
|
:rollback,
|
15
14
|
:deploy_file,
|
16
15
|
:config,
|
@@ -29,12 +28,12 @@ module Kikubari
|
|
29
28
|
raise "Deploy guide file doesn't exists: #{file}"
|
30
29
|
end
|
31
30
|
|
32
|
-
@deploy_file =
|
31
|
+
@deploy_file = parse_config_file(file)
|
33
32
|
|
34
|
-
@config = @deploy_file
|
35
|
-
@do = @deploy_file
|
36
|
-
@after = @deploy_file
|
37
|
-
@before = @deploy_file
|
33
|
+
@config = @deploy_file.config || {}
|
34
|
+
@do = @deploy_file.do || {}
|
35
|
+
@after = @deploy_file.after
|
36
|
+
@before = @deploy_file.before
|
38
37
|
|
39
38
|
raise ArgumentError, "There is no params for deploy" if params.size == 0
|
40
39
|
|
@@ -49,65 +48,24 @@ module Kikubari
|
|
49
48
|
raise ArgumentError , "Deploy folder #{@deploy_folder} is not a valid deploy folder"
|
50
49
|
end
|
51
50
|
|
52
|
-
@environment_folder =
|
51
|
+
@environment_folder = @deploy_folder.join "releases"
|
53
52
|
@date_folder = DateTime.now.strftime("%Y%m%d%H%M%S%L")
|
54
|
-
@env_time_folder =
|
55
|
-
@current_deploy_folder = "
|
56
|
-
|
57
|
-
parse_strcuture_folders if @do.has_key?("folder_structure") && !@do["folder_structure"].empty?
|
58
|
-
parse_test_files if @do.has_key?("test_files") && !@do["test_files"].empty?
|
59
|
-
|
53
|
+
@env_time_folder = @environment_folder.join @date_folder
|
54
|
+
@current_deploy_folder = @environment_folder.join "current"
|
60
55
|
end
|
61
56
|
|
62
57
|
# Return a class name for create a deployer instance for deployment process
|
63
58
|
def get_deployer_class
|
64
|
-
fw_class = ( @config.
|
65
|
-
fw_system = ( @config.
|
59
|
+
fw_class = ( @config.framework ) ? @config.framework.downcase.capitalize : ""
|
60
|
+
fw_system = ( @config.system ) ? @config.system.downcase.capitalize : ""
|
66
61
|
"#{fw_class}#{fw_system}Deployer"
|
67
62
|
end
|
68
63
|
|
69
|
-
# Return a class name for create a backup worker instance for backup process
|
70
|
-
def get_backup_class
|
71
|
-
fw_class = ( @config.has_key?("framework") ) ? @config["framework"].downcase.capitalize : ""
|
72
|
-
return "" unless @config.has_key?("database") && @config["database"].has_key?("driver")
|
73
|
-
driver = @config["database"]["driver"].downcase.capitalize
|
74
|
-
"#{fw_class}#{driver}Backup"
|
75
|
-
end
|
76
|
-
|
77
|
-
def get_structure_folder ( name )
|
78
|
-
@do["folder_structure"].each do |folder|
|
79
|
-
return folder.first[1] if folder.first[0] == name
|
80
|
-
end
|
81
|
-
""
|
82
|
-
end
|
83
|
-
|
84
|
-
def get_test_file ( name )
|
85
|
-
@do["test_files"].each do |folder|
|
86
|
-
return folder.first[1] if folder.first[0] == name
|
87
|
-
end
|
88
|
-
""
|
89
|
-
end
|
90
|
-
|
91
64
|
private
|
92
65
|
|
93
|
-
def
|
94
|
-
|
95
|
-
|
96
|
-
@do["folder_structure"].each do |folder|
|
97
|
-
tmp.push Hash[ { folder[0] => "#{@deploy_folder}/#{eval(%Q["#{folder[1]}"])}" } ]
|
98
|
-
end
|
99
|
-
@do["folder_structure"] = tmp
|
100
|
-
end
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
def parse_test_files
|
105
|
-
tmp = Array.new
|
106
|
-
environment = @environment
|
107
|
-
@do["test_files"].each do |folder|
|
108
|
-
tmp.push Hash[ { folder[0] => "#{@deploy_folder}/#{eval(%Q["#{folder[1]}"])}" } ]
|
109
|
-
end
|
110
|
-
@do["test_files"] = tmp
|
66
|
+
def parse_config_file(file)
|
67
|
+
@deploy_file = YAML::load_file(file)
|
68
|
+
JSON.parse(@deploy_file.to_json, object_class: OpenStruct)
|
111
69
|
end
|
112
70
|
|
113
71
|
|
data/lib/deploy_dir.rb
CHANGED
@@ -12,16 +12,12 @@ class DeployDir < Dir
|
|
12
12
|
# [+folder+] <b>String</b> A valid folder for deploys
|
13
13
|
# [+limit+] <b>Integer</b> Limit the folders left in deploy folder
|
14
14
|
def self.rotate_folders(folder , limit)
|
15
|
+
raise(ArgumentError, "Invalid directory #{folder}") unless exists?(folder)
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
list = Dir["#{folder}/*"]
|
20
|
-
folders = list.select {|v| v =~ /\d+?/ }
|
21
|
-
was = folders.length
|
22
|
-
FileUtils.rm_f folders.reverse.slice( limit , folders.length ) if folders.length > limit
|
23
|
-
return was - limit
|
17
|
+
glob(folder.join("*")).select {|file| file =~ /\d+?/ }.tap do |list|
|
18
|
+
FileUtils.rm_rf(list.reverse.slice(limit.to_i, list.length)) if list.length > limit.to_i
|
19
|
+
end
|
24
20
|
end
|
25
21
|
|
26
22
|
|
27
|
-
end
|
23
|
+
end
|
data/lib/deployer/deployer.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'ostruct'
|
3
|
+
|
1
4
|
# Describe the deployment process for each deployer
|
2
5
|
#
|
3
6
|
# Basically a deployment consist on gathering the code from a <b>Repository</b> writed in a <b>Framework</b> (In some language) and copying on deployment folder.
|
@@ -22,32 +25,19 @@ module Kikubari
|
|
22
25
|
# Create te the folder structure as is in the YAML
|
23
26
|
#
|
24
27
|
def create_structure
|
25
|
-
@config.do
|
26
|
-
unless File.directory?
|
27
|
-
@logger.print "Creating Structure folder: #{
|
28
|
-
FileUtils.mkdir_p
|
28
|
+
@config.do.folder_structure.each_pair do |folder, target_folder|
|
29
|
+
unless !target_folder.empty? && File.directory?(@config.deploy_folder.join(folder.to_s))
|
30
|
+
@logger.print "Creating Structure folder: #{folder}"
|
31
|
+
FileUtils.mkdir_p @config.deploy_folder.join(folder.to_s)
|
29
32
|
end
|
30
33
|
end
|
31
34
|
self
|
32
35
|
end
|
33
36
|
|
34
|
-
|
35
|
-
##
|
36
|
-
# Create the environment folder as requested in the configuration
|
37
|
-
#
|
38
|
-
def create_environment_folder
|
39
|
-
environment = @config.environment
|
40
|
-
unless File.directory? @config.environment_folder
|
41
|
-
@logger.print "Creating Environment folder: #{ @config.environment_folder}"
|
42
|
-
FileUtils.mkdir_p @config.environment_folder
|
43
|
-
end
|
44
|
-
self
|
45
|
-
end
|
46
|
-
|
47
37
|
##
|
48
38
|
# Create the folder where you will deploy the actual version of the code based on the configuration
|
49
39
|
#
|
50
|
-
def
|
40
|
+
def create_release_folder
|
51
41
|
FileUtils.mkdir_p(@config.env_time_folder) unless File.directory? @config.env_time_folder
|
52
42
|
self
|
53
43
|
end
|
@@ -56,10 +46,8 @@ module Kikubari
|
|
56
46
|
# Create the current symlink to the deploy version folder
|
57
47
|
#
|
58
48
|
def create_current_symlink_folder
|
59
|
-
|
60
|
-
|
61
|
-
FileUtils.rm_f(destination) if File.symlink?(destination)
|
62
|
-
FileUtils.ln_s origin, destination
|
49
|
+
FileUtils.rm_f(@config.current_deploy_folder) if File.symlink?(@config.current_deploy_folder)
|
50
|
+
FileUtils.ln_s @config.env_time_folder, @config.current_deploy_folder
|
63
51
|
self
|
64
52
|
end
|
65
53
|
|
@@ -68,10 +56,9 @@ module Kikubari
|
|
68
56
|
# Test if selected file already exist
|
69
57
|
#
|
70
58
|
def test_files
|
71
|
-
@config.do
|
72
|
-
|
73
|
-
|
74
|
-
raise "Please verify this file exist: #{command.first[1]}"
|
59
|
+
@config.do.link_files.each_pair do |source, target|
|
60
|
+
unless File.exist? @config.deploy_folder.join(source.to_s)
|
61
|
+
raise ArgumentError, "Please verify this file exist: #{@config.deploy_folder.join(source.to_s)}"
|
75
62
|
end
|
76
63
|
end
|
77
64
|
self
|
@@ -81,30 +68,28 @@ module Kikubari
|
|
81
68
|
# Create the Symlinked folders
|
82
69
|
#
|
83
70
|
def create_sylinked_folders
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
71
|
+
@config.do.folder_structure.each_pair do |folder, target_folder|
|
72
|
+
next if target_folder.empty?
|
73
|
+
@logger.print "- linking: #{@config.env_time_folder}/#{target_folder}"
|
74
|
+
raise "Folder: #{@config.env_time_folder.join(target_folder.to_s)} already exists and the symlink can't be created" if File.directory?(@config.env_time_folder.join(target_folder.to_s))
|
75
|
+
create_symlink( @config.deploy_folder.join(folder.to_s), @config.env_time_folder.join(target_folder.to_s) )
|
76
|
+
end
|
77
|
+
self
|
90
78
|
end
|
91
79
|
|
92
80
|
##
|
93
81
|
# Execute creation of symlinked folder
|
94
82
|
#
|
95
|
-
def create_symlink( folder )
|
96
|
-
|
97
|
-
|
98
|
-
origin = Pathname.new( "#{@config.get_structure_folder(folder[0])}" ).relative_path_from( Pathname.new( destination.gsub(/\/[^\/]*?$/, "") ) ).to_s ## Origin as a relative path from destination
|
99
|
-
FileUtils.ln_s origin, destination
|
83
|
+
def create_symlink( folder, target_folder )
|
84
|
+
raise ArgumentError , "Origin folder #{folder} is not a valid folder" unless File.directory?(folder)
|
85
|
+
FileUtils.ln_s folder, target_folder
|
100
86
|
end
|
101
87
|
|
88
|
+
|
102
89
|
def create_symlinked_files
|
103
|
-
@
|
104
|
-
|
105
|
-
|
106
|
-
origin = Pathname.new( "#{@config.get_test_file(folder[0])}" ).relative_path_from(Pathname.new( destination.gsub(/\/[^\/]*?$/, "") )).to_s
|
107
|
-
FileUtils.ln_s origin , destination
|
90
|
+
@config.do.link_files.each_pair do |source, target|
|
91
|
+
@logger.print "- linking: #{@config.env_time_folder.join(target.to_s)}"
|
92
|
+
FileUtils.ln_s(@config.deploy_folder.join(source.to_s), @config.env_time_folder.join(target.to_s))
|
108
93
|
end
|
109
94
|
end
|
110
95
|
|
@@ -113,8 +98,7 @@ module Kikubari
|
|
113
98
|
# Create deployment structure
|
114
99
|
#
|
115
100
|
def create_deploy_structure
|
116
|
-
create_structure if @config.do.
|
117
|
-
create_environment_folder.create_version_folder
|
101
|
+
create_structure if @config.do.folder_structure
|
118
102
|
self
|
119
103
|
end
|
120
104
|
|
@@ -122,12 +106,12 @@ module Kikubari
|
|
122
106
|
# Rotate old version folders
|
123
107
|
#
|
124
108
|
def rotate_folders
|
125
|
-
DeployDir.rotate_folders( @config.environment_folder , @config.config
|
109
|
+
DeployDir.rotate_folders( @config.environment_folder , @config.config.history_limit )
|
126
110
|
end
|
127
111
|
|
128
112
|
|
129
113
|
def has_after_deploy_run_commands
|
130
|
-
@config.after.
|
114
|
+
@config.after && @config.after.run && !@config.after.run.empty?
|
131
115
|
end
|
132
116
|
|
133
117
|
##
|
@@ -137,22 +121,21 @@ module Kikubari
|
|
137
121
|
return unless has_after_deploy_run_commands
|
138
122
|
out = Array.new
|
139
123
|
@logger.head "Executing After Deploy"
|
140
|
-
@config.after
|
124
|
+
@config.after.run.each do |run_task|
|
141
125
|
out.push(execute_shell(run_task) )
|
142
126
|
end
|
143
127
|
out
|
144
128
|
end
|
145
129
|
|
146
|
-
|
147
130
|
def has_before_deploy_run_commands
|
148
|
-
@config.before.
|
131
|
+
@config.before && @config.before.run && !@config.before.run.empty?
|
149
132
|
end
|
150
133
|
|
151
134
|
def before_deploy_run
|
152
135
|
return unless has_before_deploy_run_commands
|
153
136
|
out = Array.new
|
154
137
|
@logger.head "Executing Before Deploy"
|
155
|
-
@config.before
|
138
|
+
@config.before.run.each do |run_task|
|
156
139
|
out.push(execute_shell(run_task) )
|
157
140
|
end
|
158
141
|
out
|
@@ -160,7 +143,7 @@ module Kikubari
|
|
160
143
|
|
161
144
|
def execute_shell(command)
|
162
145
|
@logger.run(command, @config.env_time_folder)
|
163
|
-
temp = capture_stderr "cd #{@config.env_time_folder}
|
146
|
+
temp = capture_stderr "cd #{@config.env_time_folder.to_s.strip} && #{command} "
|
164
147
|
@logger.result(temp[:stdout]) if temp[:stdout] != ""
|
165
148
|
@logger.error(temp[:stderr]) if temp[:stderr] != ""
|
166
149
|
temp
|
@@ -178,10 +161,10 @@ module Kikubari
|
|
178
161
|
def deploy
|
179
162
|
before_deploy_run
|
180
163
|
@logger.head "Executing Deploy"
|
181
|
-
test_files if @config.do.
|
164
|
+
test_files if @config.do.test_files
|
182
165
|
do_deploy
|
183
|
-
create_sylinked_folders
|
184
|
-
create_symlinked_files if @config.do.
|
166
|
+
create_sylinked_folders
|
167
|
+
create_symlinked_files if @config.do.link_files
|
185
168
|
create_current_symlink_folder
|
186
169
|
rotate_folders
|
187
170
|
after_deploy_run
|
data/lib/kikubari.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Deploy example sheet for a Symfony 1.4 and MySQL project
|
2
2
|
#
|
3
3
|
# Author:: Jose A Pio (mailto:josetonyp@latizana.com)
|
4
|
-
# Copyright:: Copyright (c) 2011
|
4
|
+
# Copyright:: Copyright (c) 2011
|
5
5
|
# License:: Distributes under the same terms as Ruby
|
6
6
|
#
|
7
7
|
|
@@ -12,38 +12,38 @@ config:
|
|
12
12
|
origin: "git@github.com:xxx"
|
13
13
|
branch: master
|
14
14
|
history_limit: 10
|
15
|
-
# Databases for projects are optionals. In case of having one plase fill the next section to configure the backup process
|
15
|
+
# Databases for projects are optionals. In case of having one plase fill the next section to configure the backup process
|
16
16
|
database:
|
17
17
|
backup: true
|
18
18
|
dirver: mysql
|
19
19
|
user: root
|
20
|
-
pass:
|
21
|
-
|
22
|
-
|
20
|
+
pass:
|
21
|
+
|
22
|
+
|
23
23
|
## Task actions for deployers
|
24
|
-
## At versión 1 deployers should know the task order
|
24
|
+
## At versión 1 deployers should know the task order
|
25
25
|
do:
|
26
26
|
|
27
27
|
# Folder structure defining the backup and mantainance folder behind the deployment process
|
28
|
+
and it relative symlink inside the release folder
|
29
|
+
# folder_structure:
|
30
|
+
# folder_name: linked_name
|
31
|
+
# translates into:
|
32
|
+
# /deploy_path/'folder_name': /release_path/'linked_name'
|
28
33
|
folder_structure:
|
29
|
-
backup_mysql: 'backups/mysql
|
30
|
-
backup_files: 'backups/files
|
31
|
-
cache: 'cache
|
32
|
-
log: 'log
|
33
|
-
uploads: 'uploads
|
34
|
-
config: '
|
34
|
+
backup_mysql: 'backups/mysql'
|
35
|
+
backup_files: 'backups/files'
|
36
|
+
cache: 'cache'
|
37
|
+
log: 'log'
|
38
|
+
uploads: 'web/uploads'
|
39
|
+
config: ''
|
35
40
|
|
36
|
-
#
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
+
# Link this files from structure foldes into the release folder path.
|
42
|
+
# link_files:
|
43
|
+
# folder_name: source_file_name
|
44
|
+
# translates into:
|
45
|
+
# /deploy_path/'source_file_name': /release_path/'folder_name'
|
46
|
+
link_files:
|
47
|
+
'config/databases.yml': 'databases.yml'
|
41
48
|
|
42
|
-
# Links to be build from mantainance falders files and project files.
|
43
|
-
file_symbolic_link:
|
44
|
-
config: 'config/databases.yml'
|
45
|
-
|
46
|
-
# Files to be tested before deployment. This files must exists or deployment will rise an exception
|
47
|
-
test_files:
|
48
|
-
config: 'config/#{environment}/databases.yml'
|
49
49
|
|
@@ -11,10 +11,5 @@ do:
|
|
11
11
|
|
12
12
|
# Folder structure defining the backup and mantainance folder behind the deployment process
|
13
13
|
folder_structure:
|
14
|
-
cache: 'cache
|
15
|
-
log: 'log
|
16
|
-
|
17
|
-
# Folder links from project folder and matainance folders
|
18
|
-
folder_symbolic_links:
|
19
|
-
cache: cache
|
20
|
-
log: log
|
14
|
+
cache: 'cache'
|
15
|
+
log: 'log'
|
@@ -11,8 +11,8 @@ do:
|
|
11
11
|
|
12
12
|
# Folder structure defining the backup and mantainance folder behind the deployment process
|
13
13
|
folder_structure:
|
14
|
-
cache: 'cache
|
15
|
-
log: 'log
|
14
|
+
cache: 'cache'
|
15
|
+
log: 'log'
|
16
16
|
|
17
17
|
# Folder links from project folder and matainance folders
|
18
18
|
folder_symbolic_links:
|
@@ -21,7 +21,7 @@ do:
|
|
21
21
|
|
22
22
|
# Files to be tested before deployment. This files must exists or deployment will rise an exception
|
23
23
|
test_files:
|
24
|
-
test: 'log
|
24
|
+
test: 'log/test.yml'
|
25
25
|
|
26
26
|
# Links to be build from tested files. Only tested files can be converted in symlinks to the project
|
27
27
|
file_symbolic_link:
|
@@ -14,24 +14,17 @@ do:
|
|
14
14
|
|
15
15
|
# Folder structure defining the backup and mantainance folder behind the deployment process
|
16
16
|
folder_structure:
|
17
|
-
cache: 'cache
|
18
|
-
config: 'config
|
17
|
+
cache: 'cache'
|
18
|
+
config: 'config'
|
19
|
+
blank: ''
|
19
20
|
|
20
|
-
#
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
# named_file: origin
|
28
|
-
test_files:
|
29
|
-
config: 'config/#{environment}/databases.yml'
|
30
|
-
|
31
|
-
# Links to be build from tested files. Only tested files can be converted in symlinks to the project
|
32
|
-
# named_file: destination
|
33
|
-
file_symbolic_link:
|
34
|
-
config: 'config/databases.yml'
|
21
|
+
# Link this files from structure foldes into the release folder path.
|
22
|
+
# link_files:
|
23
|
+
# folder_name: source_file_name
|
24
|
+
# translates into:
|
25
|
+
# /deploy_path/'source_file_name': /release_path/'folder_name'
|
26
|
+
link_files:
|
27
|
+
'config/databases.yml': 'databases.yml'
|
35
28
|
|
36
29
|
after:
|
37
30
|
run:
|
@@ -3,9 +3,9 @@ config:
|
|
3
3
|
|
4
4
|
do:
|
5
5
|
folder_structure:
|
6
|
-
config: 'config
|
7
|
-
|
6
|
+
config: 'config'
|
7
|
+
|
8
8
|
# Files to be tested before deployment. This files must exists or deployment will rise an exception
|
9
9
|
test_files:
|
10
|
-
config: 'config
|
10
|
+
config: 'config/databases.yml'
|
11
11
|
|
@@ -2,9 +2,9 @@
|
|
2
2
|
|
3
3
|
config:
|
4
4
|
## Task actions for deployers
|
5
|
-
## At versión 1 deployers should know the task order
|
5
|
+
## At versión 1 deployers should know the task order
|
6
6
|
|
7
7
|
do:
|
8
8
|
# Folder structure defining the backup and mantainance folder behind the deployment process
|
9
9
|
folder_structure:
|
10
|
-
backup_mysql: 'backups/mysql
|
10
|
+
backup_mysql: 'backups/mysql'
|
data/spec/lib/deploy_spec.rb
CHANGED
@@ -19,21 +19,14 @@ describe Kikubari::Deploy::Deployer do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
context 'Folder Structure' do
|
22
|
-
|
23
|
-
it "creates an environment folder to host the structure" do
|
24
|
-
expect(subject.create_environment_folder).to satisfy do |deployer|
|
25
|
-
File.directory?(deployer.config.environment_folder)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
22
|
it "creates a target version folder with a the current time stamp as name" do
|
30
|
-
expect(subject.
|
23
|
+
expect(subject.create_release_folder).to satisfy do |deployer|
|
31
24
|
File.directory?(deployer.config.env_time_folder)
|
32
25
|
end
|
33
26
|
end
|
34
27
|
|
35
28
|
it "createa a symlink 'current' to the actual target version folder" do
|
36
|
-
expect(subject.
|
29
|
+
expect(subject.create_release_folder.create_current_symlink_folder).to satisfy do |deployer|
|
37
30
|
File.symlink?(deployer.config.current_deploy_folder)
|
38
31
|
end
|
39
32
|
end
|
@@ -44,103 +37,113 @@ describe Kikubari::Deploy::Deployer do
|
|
44
37
|
# folder_structure:
|
45
38
|
# cache: 'cache/#{environment}'
|
46
39
|
# config: 'config/#{environment}'
|
40
|
+
# blank: ''
|
47
41
|
#
|
48
42
|
# Example:
|
49
43
|
# project:
|
50
44
|
# cache
|
51
|
-
# [environment]
|
52
45
|
# config
|
53
|
-
#
|
54
|
-
# [environment]
|
46
|
+
# releases
|
55
47
|
# [version_folder]
|
56
|
-
# cache: Symlink to cache
|
57
|
-
# config: Symlink to config
|
48
|
+
# cache: Symlink to cache
|
49
|
+
# config: Symlink to config
|
58
50
|
# current: Symlink to [version_folder]
|
59
51
|
#
|
60
52
|
it "creates the cache and condig folder inside" do
|
61
53
|
subject.tap do |deployer|
|
62
|
-
deployer.
|
63
|
-
deployer.
|
64
|
-
deployer.
|
54
|
+
deployer.create_release_folder
|
55
|
+
deployer.create_structure
|
56
|
+
deployer.create_sylinked_folders
|
65
57
|
|
66
|
-
expect(deployer.
|
67
|
-
|
68
|
-
File.directory?("#{deployer.config.deploy_folder}/config/#{deployer.config.environment}")
|
69
|
-
end
|
58
|
+
expect(File.symlink?("#{deployer.config.env_time_folder}/cache")).to be_truthy
|
59
|
+
expect(File.symlink?("#{deployer.config.env_time_folder}/config")).to be_truthy
|
70
60
|
end
|
71
61
|
end
|
72
62
|
|
73
|
-
it
|
63
|
+
it 'does not create a symlink when target folder is blank is blank' do
|
74
64
|
subject.tap do |deployer|
|
75
|
-
deployer.
|
76
|
-
deployer.create_version_folder
|
65
|
+
deployer.create_release_folder
|
77
66
|
deployer.create_structure
|
67
|
+
deployer.create_sylinked_folders
|
78
68
|
|
79
|
-
expect(deployer.
|
80
|
-
File.symlink?( "#{deployer.config.env_time_folder}/cache") &&
|
81
|
-
File.symlink?( "#{deployer.config.env_time_folder}/config")
|
82
|
-
end
|
69
|
+
expect(File.symlink?("#{deployer.config.env_time_folder}/blank")).to be_falsy
|
83
70
|
end
|
84
71
|
end
|
85
|
-
|
86
|
-
it "should not create the symlinked folder is folder already exist" do
|
87
|
-
subject.create_environment_folder.create_version_folder.create_current_symlink_folder
|
88
|
-
subject.create_structure
|
89
|
-
FileUtils.mkdir_p "#{config.env_time_folder}/cache"
|
90
|
-
expect {
|
91
|
-
subject.create_sylinked_folders
|
92
|
-
}.to raise_error
|
93
|
-
end
|
94
72
|
end
|
95
73
|
|
96
74
|
context 'File linking' do
|
97
75
|
it "verifies a file in the folder and raise an error" do
|
98
|
-
subject.
|
99
|
-
|
76
|
+
subject.tap do |deployer|
|
77
|
+
deployer.create_release_folder
|
78
|
+
deployer.create_current_symlink_folder
|
79
|
+
expect{deployer.test_files}.to raise_error ArgumentError
|
80
|
+
end
|
100
81
|
end
|
101
82
|
|
102
83
|
it "verifies a file in the folder" do
|
103
|
-
subject.
|
104
|
-
|
84
|
+
subject.tap do |deployer|
|
85
|
+
deployer.create_release_folder
|
86
|
+
deployer.create_structure
|
87
|
+
deployer.create_current_symlink_folder
|
88
|
+
`echo "DB data...." >> #{deployer.config.deploy_folder}/config/databases.yml`
|
89
|
+
|
90
|
+
expect{deployer.test_files}.to_not raise_error ArgumentError
|
91
|
+
end
|
105
92
|
end
|
106
93
|
|
107
94
|
it "creates a symlink file from tested files" do
|
108
|
-
subject.
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
95
|
+
subject.tap do |deployer|
|
96
|
+
deployer.create_release_folder
|
97
|
+
deployer.create_structure
|
98
|
+
deployer.create_current_symlink_folder
|
99
|
+
`echo "DB data...." >> #{deployer.config.deploy_folder}/config/databases.yml`
|
100
|
+
|
101
|
+
deployer.create_symlinked_files
|
102
|
+
expect(File.symlink?( "#{config.env_time_folder}/databases.yml")).to be_truthy
|
114
103
|
end
|
115
104
|
end
|
116
105
|
end
|
117
106
|
|
118
107
|
context 'Execution' do
|
119
108
|
it "should execute the after run tasks" do
|
120
|
-
subject.
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
109
|
+
subject.tap do |deployer|
|
110
|
+
deployer.create_release_folder
|
111
|
+
deployer.create_structure
|
112
|
+
deployer.create_current_symlink_folder
|
113
|
+
deployer.after_deploy_run
|
114
|
+
|
115
|
+
expect(File.directory?("#{config.env_time_folder}/new_folder")).to be_truthy
|
125
116
|
end
|
126
117
|
end
|
127
118
|
|
128
119
|
it "should capture STDERR messages in a variable is command is not valid" do
|
129
|
-
subject.
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
120
|
+
subject.tap do |deployer|
|
121
|
+
deployer.create_release_folder
|
122
|
+
deployer.create_structure
|
123
|
+
deployer.create_current_symlink_folder
|
124
|
+
|
125
|
+
deployer.config.after.run = [ 'This is not a command' ]
|
126
|
+
deployer.after_deploy_run.tap do |out|
|
127
|
+
expect(out.count).to eq(1)
|
128
|
+
expect(out[0][:stdout]).to eq("")
|
129
|
+
expect(out[0][:stderr]).to_not eq("")
|
130
|
+
end
|
131
|
+
end
|
135
132
|
end
|
136
133
|
|
137
134
|
it "should not capture STDERR messages in a variable if command is valid" do
|
138
|
-
subject.
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
135
|
+
subject.tap do |deployer|
|
136
|
+
deployer.create_release_folder
|
137
|
+
deployer.create_structure
|
138
|
+
deployer.create_current_symlink_folder
|
139
|
+
|
140
|
+
deployer.config.after.run = [ 'ls -lah' ]
|
141
|
+
deployer.after_deploy_run.tap do |out|
|
142
|
+
expect(out.count).to eq(1)
|
143
|
+
expect(out[0][:stdout]).to_not eq("")
|
144
|
+
expect(out[0][:stderr]).to eq("")
|
145
|
+
end
|
146
|
+
end
|
144
147
|
end
|
145
148
|
end
|
146
149
|
end
|
data/spec/lib/deployers/git.rb
CHANGED
@@ -15,7 +15,6 @@ describe Kikubari::Deploy::GitDeployer do
|
|
15
15
|
|
16
16
|
before :all do
|
17
17
|
clear_target_project
|
18
|
-
|
19
18
|
end
|
20
19
|
|
21
20
|
it "clones the repository in the version folder" do
|
@@ -28,5 +27,6 @@ describe Kikubari::Deploy::GitDeployer do
|
|
28
27
|
deployer.create_deploy_structure
|
29
28
|
deployer.deploy
|
30
29
|
expect(Dir.exist?("#{deployer.config.env_time_folder}/.git")).to be_falsy
|
30
|
+
binding.pry
|
31
31
|
end
|
32
32
|
end
|