kikubari 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 371a6f5fb3417f4522bf6cc728b110a78a7f8680
4
- data.tar.gz: 18d561160ad2b71271cf0b8166a9c5212a7bbb12
3
+ metadata.gz: 4e2e03ad197ee1cec9342335ed3faf4ac1464e0c
4
+ data.tar.gz: 5ca5c1981325542b2eeef95d6215aa913e9fd441
5
5
  SHA512:
6
- metadata.gz: 9c8d3fa771f5409136b799bbd766f0e4da51eedb276e55834092b7f71040f8146fe6b5ae9b5d3a8a9162f49b32b32ce1059d701954d13302fa97d53ce74f676a
7
- data.tar.gz: e897c459fd8c151b94c3b8096427132978e6e8232d3726acb5368855f3f19b10fb578c3551726241a9ec6d9fe501f4206351e69c77f56864866a80632b97a086
6
+ metadata.gz: 70c6cb5f75e0bd9aafb7fba030e68df8ba8b682a5dedc6bfe42eb06b8a8ca074a902a489475ff8f8fb368692f8bfb94927fbd269e297faf0508b835e29790195
7
+ data.tar.gz: 712c7532fb5e09c0118feb2238e15e8d6cca0139ce9ebbdf96138b43d5149b2f3b22f5f1c300777326d8fbb975270b6ac6f4aee87765cca0acfe896063580136
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kikubari (0.0.4)
4
+ kikubari (0.1.0)
5
5
  git (~> 1.3)
6
6
 
7
7
  GEM
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
- Create a *deploy.yml* file in your deploy target folder
12
- Run *kikubari*:: */path_to_folder* or ./ *"environment_name"*
13
- Have a beer and see it work
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
- # Examples of a deploy.yml's files
15
+ ```
16
+ project
17
+ │ deploy.yml
18
+ │ ...
16
19
 
17
- ## PHP
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/iromegane.git"
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/#{environment}'
31
- uploads: 'uploads/#{environment}'
32
- config: 'config/#{environment}'
33
- coda_cache: 'coda_cache/#{environment}'
57
+ log: 'log'
58
+ uploads: 'uploads'
59
+ config: 'config'
60
+ coda_cache: 'coda_cache'
34
61
 
35
- folder_symbolic_links:
62
+ link_files:
36
63
  uploads: 'wp-content/uploads'
37
64
  coda_cache: 'wp-content/themes/coda/cache'
38
65
 
39
- file_symbolic_link:
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
 
@@ -8,7 +8,7 @@ require "stringio"
8
8
  require 'open3'
9
9
  require 'git'
10
10
 
11
- require '../lib/kikubari'
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
- if (!ARGV.first.nil? and File.directory? ARGV.first.to_s)
43
- folder = ARGV.first.to_s
44
- else
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
- end until begin
52
-
53
- ##FileUtils.cd folder
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
- if( !ARGV[1].nil? )
69
-
70
- env_folder = ARGV[1].to_s
71
-
72
- else
73
-
74
- begin
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
 
@@ -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.4"
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 = YAML::load_file(file)
31
+ @deploy_file = parse_config_file(file)
33
32
 
34
- @config = @deploy_file["config"] || {}
35
- @do = @deploy_file["do"] || {}
36
- @after = @deploy_file["after"] || {}
37
- @before = @deploy_file["before"] || {}
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 = "#{@deploy_folder}/#{@environment}"
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 = "#{@deploy_folder}/#{@environment}/#{@date_folder}"
55
- @current_deploy_folder = "#{@deploy_folder}/#{@environment}/current"
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.has_key?("framework") ) ? @config["framework"].downcase.capitalize : ""
65
- fw_system = ( @config.has_key?("system") ) ? @config["system"].downcase.capitalize : ""
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 parse_strcuture_folders
94
- tmp = Array.new
95
- environment = @environment
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
 
@@ -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
- raise( ArgumentError, "Invalid directory #{ folder }") unless File.directory? folder
17
- limit = Integer(limit)
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
@@ -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["folder_structure"].each do |command|
26
- unless File.directory? command.first[1]
27
- @logger.print "Creating Structure folder: #{command.first[1]}"
28
- FileUtils.mkdir_p command.first[1]
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 create_version_folder
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
- destination = @config.current_deploy_folder
60
- origin = Pathname.new( @config.env_time_folder ).relative_path_from( Pathname.new( @config.current_deploy_folder.gsub(/\/[^\/]*?$/, "") ) ).to_s
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["test_files"].each do |command|
72
- y command
73
- unless File.exist? command.first[1]
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
- @config.do["folder_symbolic_links"].each do |folder|
85
- @logger.print "- linking: #{@config.env_time_folder}/#{folder[1]}"
86
- raise "Folder: #{@config.env_time_folder}/#{folder[1]} already exists and the symlink can't be created" if File.directory?("#{@config.env_time_folder}/#{folder[1]}")
87
- create_symlink( folder )
88
- end
89
- self
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
- destination = "#{@config.env_time_folder}/#{folder[1]}"
97
- raise ArgumentError , "Origin folder #{@config.get_structure_folder(folder[0])} is not a valid folder" unless File.directory?("#{@config.get_structure_folder(folder[0])}")
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
- @logger.print "Creating Files symbolic links"
104
- @config.do["file_symbolic_link"].each do |folder|
105
- destination = "#{@config.env_time_folder}/#{folder[1]}"
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.has_key?("folder_structure") && !@config.do["folder_structure"].empty?
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["history_limit"] )
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.has_key?("run") && !@config.after["run"].empty?
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["run"].each do |run_task|
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.has_key?("run") && !@config.before["run"].empty?
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["run"].each do |run_task|
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} ; #{command} "
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.has_key?("test_files") && !@config.do["test_files"].empty?
164
+ test_files if @config.do.test_files
182
165
  do_deploy
183
- create_sylinked_folders if @config.do.has_key?("folder_symbolic_links") && !@config.do["folder_symbolic_links"].empty?
184
- create_symlinked_files if @config.do.has_key?("file_symbolic_link") && !@config.do["file_symbolic_link"].empty?
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
@@ -36,7 +36,7 @@ module Kikubari
36
36
  private
37
37
 
38
38
  def get_deployer config
39
- eval(deployer_class).new(config)
39
+ eval(config.get_deployer_class).new(config)
40
40
  end
41
41
 
42
42
 
@@ -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/#{environment}'
30
- backup_files: 'backups/files/#{environment}'
31
- cache: 'cache/#{environment}'
32
- log: 'log/#{environment}'
33
- uploads: 'uploads/#{environment}'
34
- config: 'config/#{environment}'
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
- # Folder links from project folder and matainance folders
37
- folder_symbolic_links:
38
- cache: cache
39
- log: log
40
- uploads: web/uploads
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/#{environment}'
15
- log: 'log/#{environment}'
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/#{environment}'
15
- log: 'log/#{environment}'
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/#{environment}/test.yml'
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/#{environment}'
18
- config: 'config/#{environment}'
17
+ cache: 'cache'
18
+ config: 'config'
19
+ blank: ''
19
20
 
20
- # Folder links from project folder and matainance folders
21
- folder_symbolic_links:
22
- #name: #destination_name
23
- cache: cache
24
- config: config
25
-
26
- # Files to be tested before deployment. This files must exists or deployment will rise an exception
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/#{environment}'
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/#{environment}/databases.yml'
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/#{environment}'
10
+ backup_mysql: 'backups/mysql'
@@ -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.create_version_folder).to satisfy do |deployer|
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.create_version_folder.create_current_symlink_folder).to satisfy do |deployer|
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
- # [environment]
54
- # [environment]
46
+ # releases
55
47
  # [version_folder]
56
- # cache: Symlink to cache/[environment]
57
- # config: Symlink to config/[environment]
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.create_environment_folder
63
- deployer.create_version_folder
64
- deployer.create_current_symlink_folder
54
+ deployer.create_release_folder
55
+ deployer.create_structure
56
+ deployer.create_sylinked_folders
65
57
 
66
- expect(deployer.create_structure).to satisfy do
67
- File.directory?("#{deployer.config.deploy_folder}/cache/#{deployer.config.environment}") &&
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 "creates a symlink to inside the version folder pointing to the corresponding folder inside the structure" do
63
+ it 'does not create a symlink when target folder is blank is blank' do
74
64
  subject.tap do |deployer|
75
- deployer.create_environment_folder
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.create_sylinked_folders).to satisfy do
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.create_environment_folder.create_version_folder.create_current_symlink_folder
99
- expect{subject.test_files}.to raise_error
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.create_environment_folder.create_version_folder.create_current_symlink_folder
104
- expect{subject.test_files}.to raise_error
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.create_deploy_structure
109
- ## Faking the config folder that should come with the repository
110
- FileUtils.mkdir_p "#{config.env_time_folder}/config"
111
- `echo "DB data...." >> #{config.deploy_folder}/config/#{config.environment}/databases.yml`
112
- subject.create_symlinked_files.should satisfy do |deployer|
113
- File.symlink?( "#{config.env_time_folder}/config/databases.yml")
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.create_deploy_structure
121
- FileUtils.mkdir_p "#{config.env_time_folder}/config"
122
- `echo "DB data..." >> #{config.deploy_folder}/config/#{config.environment}/databases.yml`
123
- subject.after_deploy_run.should satisfy do |deployer|
124
- File.directory?("#{config.env_time_folder}/new_folder")
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.create_deploy_structure
130
- subject.config.after['run'] = [ 'This is not a command' ]
131
- out = subject.after_deploy_run
132
- out.count.should == 1
133
- out[0][:stdout].should == ""
134
- out[0][:stderr].should_not == ""
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.create_deploy_structure
139
- subject.config.after['run'] = [ 'ls -lah' ]
140
- out = subject.after_deploy_run
141
- out.count.should == 1
142
- out[0][:stdout].should_not == ""
143
- out[0][:stderr].should == ""
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
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kikubari
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jose Antonio Pio Gil