capistrano3-multiyaml 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2015 Oleg Yakovenko <olegykz@gmail.com>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,79 @@
1
+ YAML Multistage Extensions for Capistrano
2
+ =========================================
3
+ [![Gem Version](https://badge.fury.io/rb/capistrano-multiyaml.png)](http://badge.fury.io/rb/capistrano-multiyaml)
4
+
5
+ This gem is Capistrano 3 adaptation of [capistrano-multiyaml by Daniel Silverman](https://github.com/agperson/capistrano-multiyaml)
6
+
7
+ This extension is an alternative to Jamis Buck's multistage extension for Capistrano that stores multistage configuration in a single YAML file rather than in multiple Ruby files. It provides a simple and straightforward way to specify variables, callbacks, and roles for different deployment stages, and the file can be manipulated by any script that understands YAML. Even if the file is only managed by humans, there are still several benefits including centralizing stage/role configuration in one file, discouraging per-stage logic in deference to properly hooked before/after callbacks, and simplified configuration reuse.'
8
+
9
+ For more information about the general idea of multistage deployment, see the [docs for the original module](https://github.com/capistrano/capistrano/wiki/2.x-Multistage-Extension/).
10
+
11
+ ## Installation
12
+
13
+ 1. Install the **capistrano3-multiyaml** gem using RubyGems, Bundler, or your preferred system.
14
+ 2. Modify your `Capfile` or `deploy.rb` to set a few variables and include the gem:
15
+
16
+ set :multiyaml_stages, "config/stages.yml"`
17
+ require 'capistrano3-multiyaml'
18
+
19
+ ## Configure Stages
20
+
21
+ The easiest way to understand the capabilities of the YAML file is to see a complete one. This example incorporates all of the possible configuration options, and also uses YAML anchor/alias to avoid repetition. Note that while before/after callback hooks can be used to evaluate code, this is not recommended because the goal of this setup is to avoid putting deploy logic in the stage configuration file.
22
+
23
+ ```ruby
24
+ --- # stages for application "fooapp"
25
+ integration:
26
+ roles:
27
+ app:
28
+ '#{`hostname -f`}':
29
+ staging:
30
+ variables: &vars
31
+ :data_path: '/nfs/#{application}/#{stage}'
32
+ :clean_script: '/usr/local/bin/clean-cache.sh'
33
+ tasks: &tasks
34
+ - type : after_callback
35
+ target: 'deploy:setup'
36
+ action: 'fooapp:link_data_path'
37
+ - type : before_callback
38
+ target: 'deploy:restart'
39
+ action: 'fooapp:run_scripts'
40
+ roles:
41
+ web:
42
+ 'lb-stage1.foocorp.com':
43
+ db:
44
+ 'sql-stage1.db.foocorp.com':
45
+ app:
46
+ 'app-stage1.foocorp.com':
47
+ - :primary: true
48
+ 'app-stage2.foocorp.com':
49
+ production:
50
+ variables: *vars
51
+ tasks: *tasks
52
+ roles:
53
+ web:
54
+ 'lb-prod1.foocorp.com':
55
+ 'lb-prod2.foocorp.com':
56
+ db:
57
+ 'sql-prod1.db.foocorp.com':
58
+ app:
59
+ 'app-prod1.foocorp.com':
60
+ - :primary: true
61
+ 'app-prod2.foocorp.com':
62
+ 'app-prod3.foocorp.com':
63
+ 'app-prod4.foocorp.com':
64
+ - :read_only: true
65
+ ```
66
+
67
+ * Variable keys are symbols
68
+ * Variables and roles are interpolated. It is valid to use other variables within variables and roles, such as the staging data_path variable including the stage and application name, and the development app server role looking up the FQDN of localhost.
69
+ * Tasks can be one of `after_callback` (using the "after" hook) or `before_callback` (using the "before" hook). Action can be either another task or a code block to be evaluated.
70
+ * Additional parameters can be passed to servers in an array
71
+
72
+ ## Running Deploy Actions
73
+
74
+ Prefix deploy actions with the name of the stage, i.e. `cap production TASK`. If you do not set a stage and `default_stage` is set, it will be used instead.
75
+
76
+ ## Links
77
+
78
+ * [Daniel Silverman original gem for Capistrano2](https://github.com/agperson/capistrano-multiyaml)
79
+
@@ -0,0 +1,17 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'capistrano3-multiyaml'
3
+ s.version = '1.0.2'
4
+ s.platform = Gem::Platform::RUBY
5
+ s.authors = ["Oleg Yakovenko"]
6
+ s.email = 'olegykz@gmail.com'
7
+ s.homepage = 'http://github.com/olegykz/capistrano3-multiyaml'
8
+ s.summary = 'Capistrano 3 plugin for storing multistage configuration in a YAML file.'
9
+ s.description = 'This plugin simplifies and clarifies the multistage deploy process by reading settings from a simple YAML file that can be updated programatically. Even if the file is only managed by humans, there are still several benefits including centralizing stage/role configuration in one file, discouraging per-stage logic in deference to properly hooked before/after callbacks, and simplified configuration reuse.'
10
+
11
+ s.add_runtime_dependency "capistrano", "~>3"
12
+
13
+ s.files = `git ls-files`.split("\n")
14
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+ s.require_paths = ["lib"]
17
+ end
@@ -0,0 +1,84 @@
1
+ require 'fileutils'
2
+ require 'yaml'
3
+ require 'stages'
4
+
5
+ # Variable interpolation mechanism stolen from Ruby Facets 2.9.3 rather than
6
+ # requiring the whole library
7
+ def String.interpolate(&str)
8
+ eval "%{#{str.call}}", str.binding
9
+ end
10
+
11
+ begin
12
+ yamlfile = YAML.load_file(fetch(:multiyaml_stages, "config/stages.yml"))
13
+ rescue Errno::ENOENT
14
+ abort "Multistage deployment configuration file missing. "\
15
+ "Populate config/stages.yaml or set :multiyaml_stages to another location "\
16
+ "to use capistrano/multiyaml for multistage deployment."
17
+ rescue Exception => e
18
+ abort "Configuration file load failed with message: #{e.message}."
19
+ end
20
+
21
+ stages = yamlfile.keys
22
+ set(:yaml_stages, stages)
23
+
24
+ # Loop through YAML configuration file and create a task for each stage.
25
+ stages.each do |name|
26
+ desc "Set the target stage to `#{name}'."
27
+ Rake::Task.define_task(name) do
28
+ set(:stage, name.to_sym)
29
+ puts "Setting stage to #{name}"
30
+
31
+ # Load the corresponding stage's YAML configuration and iterate through,
32
+ # setting roles, variables, and callbacks as specified.
33
+ config = yamlfile[name.to_s]
34
+ abort "Invalid or missing stage configuration for #{name}." if config.nil?
35
+
36
+ invoke 'load:defaults'
37
+
38
+ load deploy_config_path
39
+ load "capistrano/#{fetch(:scm)}.rb"
40
+
41
+ I18n.locale = fetch(:locale, :en)
42
+
43
+ config.each do |section, contents|
44
+ case section.to_s
45
+ # Set variables first so they can be used in roles if necessary.
46
+ when "variables"
47
+ contents.each do |key, value|
48
+ value = value.is_a?(String) ? String.interpolate{value.to_s} : value
49
+ set(key.to_sym, value)
50
+ end
51
+ when "tasks"
52
+ contents.each do |task|
53
+ target = task['target'].to_s
54
+ action = task['action'].to_s
55
+ case task['type']
56
+ when "before_callback"
57
+ before(target, action)
58
+ when "after_callback"
59
+ after(target, action)
60
+ else
61
+ abort "Wrong callback type - #{task['type']}"
62
+ end
63
+ end
64
+ when "roles"
65
+ contents.each do |rolename, hosts|
66
+ hosts.each do |hostname, options|
67
+ hostname = String.interpolate{hostname.to_s}
68
+ puts "Processing host settings for #{hostname} (#{name})"
69
+ if options.is_a?(Hash) then
70
+ role(rolename.to_sym, hostname.to_s, options)
71
+ else
72
+ role(rolename.to_sym, hostname.to_s)
73
+ end
74
+ end
75
+ end
76
+ else
77
+ puts "Multistage YAML configuration section #{section} ignored by capistrano/multiyaml."
78
+ end
79
+
80
+ configure_backend
81
+ end
82
+ end
83
+ end
84
+
data/lib/stages.rb ADDED
@@ -0,0 +1,6 @@
1
+ module Capistrano::DSL::Stages
2
+ def stages
3
+ # Add stages defined in stages.yml to standard stages definitions (config/deploy/*.rb)
4
+ Dir[stage_definitions].map { |f| File.basename(f, '.rb') } + fetch(:yaml_stages, [])
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano3-multiyaml
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Oleg Yakovenko
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-03-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: capistrano
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '3'
30
+ description: This plugin simplifies and clarifies the multistage deploy process by
31
+ reading settings from a simple YAML file that can be updated programatically. Even
32
+ if the file is only managed by humans, there are still several benefits including
33
+ centralizing stage/role configuration in one file, discouraging per-stage logic
34
+ in deference to properly hooked before/after callbacks, and simplified configuration
35
+ reuse.
36
+ email: olegykz@gmail.com
37
+ executables: []
38
+ extensions: []
39
+ extra_rdoc_files: []
40
+ files:
41
+ - LICENSE
42
+ - README.md
43
+ - capistrano3-multiyaml.gemspec
44
+ - lib/capistrano3-multiyaml.rb
45
+ - lib/stages.rb
46
+ homepage: http://github.com/olegykz/capistrano3-multiyaml
47
+ licenses: []
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubyforge_project:
66
+ rubygems_version: 1.8.23.2
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: Capistrano 3 plugin for storing multistage configuration in a YAML file.
70
+ test_files: []