sunzi 1.1.2 → 1.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1bd89f4ad65038f257a87cbcdd0ea8006d574b51
4
- data.tar.gz: f4db9e3e86a12dfddf1f55ce68f12203f2a1a4aa
3
+ metadata.gz: 4ec250a135b740f0a34196be384788cdebf33d5a
4
+ data.tar.gz: 27cf354835d55b8463964df7e8095c8880d3750a
5
5
  SHA512:
6
- metadata.gz: df36a11715d35f8e47f161ca44047996f310431e61cb94ddc8cbf6468c11ae9d0ae705604e2f221ef94830087925bb7fecc0a31a4abc4a32c338faac89a7e3d4
7
- data.tar.gz: 7ce6fc934da2816b045855621a773172ba6b1c770c59f27c1fd2eb630eb2c131ed051b73a7f871824f3bb4076f11402428f03983c6ec8bfe3e9761c9fcb92778
6
+ metadata.gz: 22a9585b4f2228b01509924b4c7509ca8b20b5ffd300a5a06338db32cbb12e8d1a6b23d129f9be2513d86435bb2c0c708f82b162ea708eeaefbf2cb412281414
7
+ data.tar.gz: d50ddebc4f553446f4c54fcec5099c7dfab232fc1e74888bdcdc1890b06506c401cac336e6c6e860806f277bd8263c31efedec045b443f715e7fdeae70dd4988
data/.gitignore CHANGED
@@ -2,3 +2,4 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ sandbox
data/README.md CHANGED
@@ -18,6 +18,7 @@ Its design goals are:
18
18
 
19
19
  ### What's new:
20
20
 
21
+ * v1.2: Evaluate everything as ERB templates by default. Added "files" folder.
21
22
  * v1.1: "set -e" by default. apt-get everywhere in place of aptitude. Linode DNS support for DigitalOcean instances.
22
23
  * v1.0: System functions are refactored into sunzi.mute() and sunzi.install().
23
24
  * v0.9: Support for [DigitalOcean](https://www.digitalocean.com) setup / teardown.
@@ -89,25 +90,24 @@ sunzi/
89
90
  roles/ # when role is specified, scripts here will be concatenated
90
91
  db.sh # to install.sh in the compile phase
91
92
  web.sh
93
+ files/ # put any files to be transferred
92
94
  compiled/ # everything under this folder will be transferred to the
93
95
  # remote server (do not edit directly)
94
96
  ```
95
97
 
96
- How do you pass dynamic values to a recipe?
97
- -------------------------------------------
98
+ How do you pass dynamic values?
99
+ -------------------------------
98
100
 
99
- In the compile phase, attributes defined in `sunzi.yml` are split into multiple files in `compiled/attributes`, one per attribute. We use filesystem as a sort of key-value storage so that it's easy to use from shell scripts.
101
+ There are two ways to pass dynamic values to the script - ruby and bash.
100
102
 
101
- The convention for argument passing to a recipe is to use `$1`, `$2`, etc. and put a comment line for each argument.
103
+ **For ruby (recommended)**: Make sure `eval_erb: true` is set in `sunzi.yml`. In the compile phase, attributes defined in `sunzi.yml` are accessible from any files in the form of `<%= @attributes.ruby_version %>`.
102
104
 
103
- For instance, given a recipe `greeting.sh`:
105
+ **For bash**: In the compile phase, attributes defined in `sunzi.yml` are split into multiple files in `compiled/attributes`, one per attribute. Now you can refer to it by `$(cat attributes/ruby_version)` in the script.
104
106
 
105
- ```bash
106
- # Greeting
107
- # $1: Name for goodbye
108
- # $2: Name for hello
107
+ For instance, given the following `install.sh`:
109
108
 
110
- echo "Goodbye $1, Hello $2!"
109
+ ```bash
110
+ echo "Goodbye <%= @attributes.goodbye %>, Hello <%= @attributes.hello %>!"
111
111
  ```
112
112
 
113
113
  With `sunzi.yml`:
@@ -118,13 +118,7 @@ attributes:
118
118
  hello: Sunzi
119
119
  ```
120
120
 
121
- Then, include the recipe in `install.sh`:
122
-
123
- ```bash
124
- source recipes/greeting.sh $(cat attributes/goodbye) $(cat attributes/hello)
125
- ```
126
-
127
- Now, you get the following result. Isn't it awesome?
121
+ Now, you get the following result.
128
122
 
129
123
  ```
130
124
  Goodbye Chef, Hello Sunzi!
data/lib/sunzi/cli.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'open3'
2
+ require 'ostruct'
2
3
 
3
4
  module Sunzi
4
5
  class Cli < Thor
@@ -43,12 +44,13 @@ module Sunzi
43
44
  end
44
45
 
45
46
  def do_create(project)
46
- template 'templates/create/.gitignore', "#{project}/.gitignore"
47
- template 'templates/create/sunzi.yml', "#{project}/sunzi.yml"
48
- template 'templates/create/install.sh', "#{project}/install.sh"
49
- template 'templates/create/recipes/sunzi.sh', "#{project}/recipes/sunzi.sh"
50
- template 'templates/create/roles/db.sh', "#{project}/roles/db.sh"
51
- template 'templates/create/roles/web.sh', "#{project}/roles/web.sh"
47
+ copy_file 'templates/create/.gitignore', "#{project}/.gitignore"
48
+ copy_file 'templates/create/sunzi.yml', "#{project}/sunzi.yml"
49
+ copy_file 'templates/create/install.sh', "#{project}/install.sh"
50
+ copy_file 'templates/create/recipes/sunzi.sh', "#{project}/recipes/sunzi.sh"
51
+ copy_file 'templates/create/roles/db.sh', "#{project}/roles/db.sh"
52
+ copy_file 'templates/create/roles/web.sh', "#{project}/roles/web.sh"
53
+ copy_file 'templates/create/files/.gitkeep', "#{project}/files/.gitkeep"
52
54
  end
53
55
 
54
56
  def do_deploy(target, role, force_sudo)
@@ -102,7 +104,7 @@ module Sunzi
102
104
  @config = YAML.load(File.read('sunzi.yml'))
103
105
 
104
106
  # Break down attributes into individual files
105
- (@config['attributes'] || []).each {|key, value| create_file "compiled/attributes/#{key}", value }
107
+ (@config['attributes'] || {}).each {|key, value| create_file "compiled/attributes/#{key}", value }
106
108
 
107
109
  # Retrieve remote recipes via HTTP
108
110
  cache_remote_recipes = @config['preferences'] && @config['preferences']['cache_remote_recipes']
@@ -112,15 +114,23 @@ module Sunzi
112
114
  end
113
115
 
114
116
  # Copy local files
115
- Dir['recipes/*'].each {|file| copy_file File.expand_path(file), "compiled/recipes/#{File.basename(file)}" }
116
- Dir['roles/*'].each {|file| copy_file File.expand_path(file), "compiled/roles/#{File.basename(file)}" }
117
- (@config['files'] || []).each {|file| copy_file File.expand_path(file), "compiled/files/#{File.basename(file)}" }
117
+ @attributes = OpenStruct.new(@config['attributes'])
118
+ copy_or_template = (@config['preferences'] && @config['preferences']['eval_erb']) ? :template : :copy_file
119
+ Dir['recipes/*'].each {|file| send copy_or_template, File.expand_path(file), "compiled/recipes/#{File.basename(file)}" }
120
+ Dir['roles/*'].each {|file| send copy_or_template, File.expand_path(file), "compiled/roles/#{File.basename(file)}" }
121
+ Dir['files/*'].each {|file| send copy_or_template, File.expand_path(file), "compiled/files/#{File.basename(file)}" }
122
+ (@config['files'] || []).each {|file| send copy_or_template, File.expand_path(file), "compiled/files/#{File.basename(file)}" }
118
123
 
119
124
  # Build install.sh
120
125
  if role
121
- create_file 'compiled/install.sh', File.binread('install.sh') << "\n" << File.binread("roles/#{role}.sh")
126
+ if copy_or_template == :template
127
+ template File.expand_path('install.sh'), 'compiled/_install.sh'
128
+ create_file 'compiled/install.sh', File.binread('compiled/_install.sh') << "\n" << File.binread("compiled/roles/#{role}.sh")
129
+ else
130
+ create_file 'compiled/install.sh', File.binread('install.sh') << "\n" << File.binread("roles/#{role}.sh")
131
+ end
122
132
  else
123
- copy_file File.expand_path('install.sh'), 'compiled/install.sh'
133
+ send copy_or_template, File.expand_path('install.sh'), 'compiled/install.sh'
124
134
  end
125
135
  end
126
136
 
File without changes
@@ -25,7 +25,7 @@ if sunzi.install "sysstat"; then
25
25
  fi
26
26
 
27
27
  # Set RAILS_ENV
28
- environment=$(cat attributes/environment)
28
+ environment=<%= @attributes.environment %>
29
29
 
30
30
  if ! grep -Fq "RAILS_ENV" ~/.bash_profile; then
31
31
  echo 'Setting up RAILS_ENV...'
@@ -35,7 +35,7 @@ fi
35
35
 
36
36
  # Install Ruby using RVM
37
37
  source recipes/rvm.sh
38
- ruby_version=$(cat attributes/ruby_version)
38
+ ruby_version=<%= @attributes.ruby_version %>
39
39
 
40
40
  if [[ "$(which ruby)" != /usr/local/rvm/rubies/ruby-$ruby_version* ]]; then
41
41
  echo "Installing ruby-$ruby_version"
@@ -23,3 +23,7 @@ preferences:
23
23
  # Skip retrieving remote recipes when local copies already exist. This setting helps
24
24
  # iterative deploy testing considerably faster, when you have a lot of remote recipes.
25
25
  cache_remote_recipes: false
26
+
27
+ # Evaluate files as ERB templates. When enabled, you can pass dynamic values in the form
28
+ # of <%= @attributes.environment %> in recipes, roles, files and install.sh.
29
+ eval_erb: true
data/sunzi.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'sunzi'
5
- spec.version = '1.1.2' # retrieve this value by: Gem.loaded_specs['sunzi'].version.to_s
5
+ spec.version = '1.2.0' # retrieve this value by: Gem.loaded_specs['sunzi'].version.to_s
6
6
  spec.authors = ['Kenn Ejima']
7
7
  spec.email = ['kenn.ejima@gmail.com']
8
8
  spec.homepage = 'http://github.com/kenn/sunzi'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sunzi
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kenn Ejima
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-12 00:00:00.000000000 Z
11
+ date: 2013-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -79,6 +79,7 @@ files:
79
79
  - lib/sunzi/logger.rb
80
80
  - lib/sunzi/utility.rb
81
81
  - lib/templates/create/.gitignore
82
+ - lib/templates/create/files/.gitkeep
82
83
  - lib/templates/create/install.sh
83
84
  - lib/templates/create/recipes/sunzi.sh
84
85
  - lib/templates/create/roles/db.sh
@@ -108,9 +109,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
109
  version: '0'
109
110
  requirements: []
110
111
  rubyforge_project:
111
- rubygems_version: 2.0.2
112
+ rubygems_version: 2.0.3
112
113
  signing_key:
113
114
  specification_version: 4
114
115
  summary: Server provisioning utility for minimalists
115
116
  test_files:
116
117
  - test/test_cli.rb
118
+ has_rdoc: