sunzi 0.9.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4ffa01c88c6e07a1cad033e00d59dc101f5682eb
4
+ data.tar.gz: 292cbdf52feafdf63b92b8dac2b87d1f1469a219
5
+ SHA512:
6
+ metadata.gz: 3c46c9e363903f7e6440ae3b7c0d6685b695e1bf469df7f3b41f1b9d446b85d7c8dc0a131c49b9c71d777dff0f8c7632cbc746f5a6d77295df1a302d4def8696
7
+ data.tar.gz: 0ee5d4d9f5c9a00aa889e4a787be66a3b636d119f0506ff14d7915795c2025de3d33ecd8059bb5d1c2c1e150cf191f4da547e2fc3a6f0de5dc154ac6da69ed68
data/README.md CHANGED
@@ -30,7 +30,7 @@ Quickstart
30
30
  Install:
31
31
 
32
32
  ```bash
33
- $ gem install sunzi
33
+ $ [sudo] gem install sunzi
34
34
  ```
35
35
 
36
36
  Go into your project directory (if it's a Rails project, `config` would be a good place to start with), then:
@@ -63,13 +63,13 @@ Commands
63
63
  --------
64
64
 
65
65
  ```bash
66
- $ sunzi # Show command help
67
- $ sunzi compile # Compile Sunzi project
68
- $ sunzi create # Create a new Sunzi project
69
- $ sunzi deploy [user@host:port] [role] [--sudo] # Deploy Sunzi project
66
+ $ sunzi # Show command help
67
+ $ sunzi compile # Compile Sunzi project
68
+ $ sunzi create # Create a new Sunzi project
69
+ $ sunzi deploy [user@host:port] [role] [--sudo] # Deploy Sunzi project
70
70
 
71
- $ sunzi setup [linode|digital_ocean] # Setup a new VM on the Cloud services
72
- $ sunzi teardown [linode|digital_ocean] [name] # Teardown an existing VM on the Cloud services
71
+ $ sunzi setup [linode|digital_ocean] # Setup a new VM on the cloud services
72
+ $ sunzi teardown [linode|digital_ocean] [name] # Teardown an existing VM on the cloud services
73
73
  ```
74
74
 
75
75
  Directory structure
@@ -83,7 +83,7 @@ sunzi/
83
83
  sunzi.yml # add custom attributes and remote recipes here
84
84
 
85
85
  recipes/ # put commonly used scripts here, referred from install.sh
86
- ssh_key.sh
86
+ sunzi.sh
87
87
  roles/ # when role is specified, scripts here will be concatenated
88
88
  app.sh # to install.sh in the compile phase
89
89
  db.sh
@@ -171,7 +171,7 @@ The following screenshot says it all.
171
171
 
172
172
  ![Sunzi for Linode](http://farm8.staticflickr.com/7210/6783789868_ab89010d5c.jpg)
173
173
 
174
- Right now, only [Linode](http://www.linode.com/) is supported, but EC2 and Rackspace are coming.
174
+ Right now, only [Linode](http://www.linode.com/) and [DigitalOcean](https://www.digitalocean.com) are supported.
175
175
 
176
176
  For DNS, Linode and [Amazon Route 53](http://aws.amazon.com/route53/) are supported.
177
177
 
data/lib/sunzi.rb CHANGED
@@ -7,12 +7,10 @@ module Sunzi
7
7
  autoload :Dependency, 'sunzi/dependency'
8
8
  autoload :Logger, 'sunzi/logger'
9
9
  autoload :Utility, 'sunzi/utility'
10
- autoload :Version, 'sunzi/version'
11
10
 
12
11
  module Cloud
13
12
  autoload :Base, 'sunzi/cloud/base'
14
13
  autoload :Linode, 'sunzi/cloud/linode'
15
- autoload :EC2, 'sunzi/cloud/ec2'
16
14
  autoload :DigitalOcean, 'sunzi/cloud/digital_ocean'
17
15
  end
18
16
  end
data/lib/sunzi/cli.rb CHANGED
@@ -30,6 +30,11 @@ module Sunzi
30
30
  Cloud::Base.choose(self, target).teardown(name)
31
31
  end
32
32
 
33
+ desc 'version', 'Show version'
34
+ def version
35
+ puts Gem.loaded_specs['sunzi'].version.to_s
36
+ end
37
+
33
38
  no_tasks do
34
39
  include Sunzi::Utility
35
40
 
@@ -42,7 +47,6 @@ module Sunzi
42
47
  template 'templates/create/sunzi.yml', "#{project}/sunzi.yml"
43
48
  template 'templates/create/install.sh', "#{project}/install.sh"
44
49
  template 'templates/create/recipes/sunzi.sh', "#{project}/recipes/sunzi.sh"
45
- template 'templates/create/recipes/ssh_key.sh', "#{project}/recipes/ssh_key.sh"
46
50
  template 'templates/create/roles/app.sh', "#{project}/roles/app.sh"
47
51
  template 'templates/create/roles/db.sh', "#{project}/roles/db.sh"
48
52
  template 'templates/create/roles/web.sh', "#{project}/roles/web.sh"
@@ -9,8 +9,6 @@ module Sunzi
9
9
  case target
10
10
  when 'linode'
11
11
  Cloud::Linode.new(cli)
12
- when 'ec2'
13
- Cloud::EC2.new(cli)
14
12
  when 'digital_ocean'
15
13
  Cloud::DigitalOcean.new(cli)
16
14
  else
@@ -1,6 +1,6 @@
1
1
  #!/bin/bash
2
2
 
3
- # Load base utility functions like sunzi::silencer()
3
+ # Load base utility functions like sunzi.mute() and sunzi.install()
4
4
  source recipes/sunzi.sh
5
5
 
6
6
  # This line is necessary for automated provisioning for Debian/Ubuntu.
@@ -10,15 +10,40 @@ export DEBIAN_FRONTEND=noninteractive
10
10
  # Add Dotdeb repository. Recommended if you're using Debian. See http://www.dotdeb.org/about/
11
11
  # source recipes/dotdeb.sh
12
12
 
13
- # SSH key
14
- source recipes/ssh_key.sh $(cat attributes/ssh_key)
13
+ # Update installed packages
14
+ sunzi.mute "aptitude update"
15
+ sunzi.mute "aptitude -y safe-upgrade"
15
16
 
16
- # Update apt catalog. If you prefer less verbosity, use the sunzi::silencer version instead
17
- aptitude update
18
- aptitude -y safe-upgrade
19
- # sunzi::silencer "aptitude update"
20
- # sunzi::silencer "aptitude -y safe-upgrade"
17
+ # Install packages
18
+ sunzi.install "git-core ntp curl"
21
19
 
22
- # Install packages. If you prefer less verbosity, use the sunzi::silencer version instead
23
- aptitude -y install git-core ntp
24
- # sunzi::silencer "aptitude -y install git-core ntp"
20
+ # Set RAILS_ENV
21
+ environment=$(cat attributes/environment)
22
+
23
+ if ! grep -Fq "RAILS_ENV" ~/.bash_profile; then
24
+ echo 'Setting up RAILS_ENV...'
25
+ echo "export RAILS_ENV=$environment" >> ~/.bash_profile
26
+ source ~/.bash_profile
27
+ fi
28
+
29
+ # Install Ruby using RVM
30
+ source recipes/rvm.sh
31
+ ruby_version=$(cat attributes/ruby_version)
32
+
33
+ if [[ "$(which ruby)" != /usr/local/rvm/rubies/ruby-$ruby_version* ]]; then
34
+ echo "Installing ruby-$ruby_version"
35
+ sunzi.install build-essential libssl-dev libreadline6-dev
36
+ rvm install $ruby_version
37
+ rvm $ruby_version --default
38
+ echo 'gem: --no-ri --no-rdoc' > ~/.gemrc
39
+
40
+ # Install Bundler
41
+ gem update --system
42
+ gem install bundler
43
+ fi
44
+
45
+ # Install sysstat, then configure if this is a new install.
46
+ if sunzi.install "sysstat"; then
47
+ sed -i 's/ENABLED="false"/ENABLED="true"/' /etc/default/sysstat
48
+ /etc/init.d/sysstat restart
49
+ fi
@@ -1,6 +1,47 @@
1
- # This file is used to define functions under the sunzi:: namespace.
1
+ # This file is used to define functions under the sunzi.* namespace.
2
2
 
3
- function sunzi::silencer() {
3
+ # Set $sunzi_pkg to "aptitude" or "yum", or abort.
4
+ #
5
+ if which aptitude >/dev/null 2>&1; then
6
+ export sunzi_pkg=aptitude
7
+ elif which yum >/dev/null 2>&1; then
8
+ export sunzi_pkg=yum
9
+ fi
10
+
11
+ if [ "$sunzi_pkg" = '' ]; then
12
+ echo 'sunzi only supports aptitude and yum!' >&2
13
+ exit 1
14
+ fi
15
+
16
+ # Mute STDOUT and STDERR
17
+ #
18
+ function sunzi.mute() {
4
19
  echo "Running \"$@\""
5
- eval "$@ > /dev/null 2>&1"
20
+ `$@ >/dev/null 2>&1`
21
+ return $?
22
+ }
23
+
24
+ # Installer
25
+ #
26
+ function sunzi.installed() {
27
+ if [ "$sunzi_pkg" = 'aptitude' ]; then
28
+ dpkg -s $@ >/dev/null 2>&1
29
+ elif [ "$sunzi_pkg" = 'yum' ]; then
30
+ rpm -qa | grep $@ >/dev/null
31
+ fi
32
+ return $?
33
+ }
34
+
35
+ function sunzi.install() {
36
+ for name in $@
37
+ do
38
+ if sunzi.installed "$name"; then
39
+ echo "$name already installed"
40
+ return 1
41
+ else
42
+ echo "No packages found matching $name. Installing..."
43
+ sunzi.mute "$sunzi_pkg -y install $name"
44
+ return 0
45
+ fi
46
+ done
6
47
  }
@@ -1,9 +1,8 @@
1
1
  ---
2
2
  # Dynamic variables here will be compiled to individual files in compiled/attributes.
3
3
  attributes:
4
- ssh_key: id_rsa.pub
5
- environment: development
6
- ruby_version: 1.9.3
4
+ environment: production
5
+ ruby_version: 2.0.0
7
6
 
8
7
  # Remote recipes here will be downloaded to compiled/recipes.
9
8
  recipes:
@@ -12,8 +11,8 @@ recipes:
12
11
  # mongodb-10gen: https://raw.github.com/kenn/sunzi-recipes/master/debian/mongodb-10gen.sh
13
12
 
14
13
  # Files specified here will be copied to compiled/files.
15
- files:
16
- - ~/.ssh/id_rsa.pub
14
+ # files:
15
+ # - ~/.ssh/id_rsa.pub
17
16
 
18
17
  # Fine tune how Sunzi should work.
19
18
  preferences:
data/sunzi.gemspec CHANGED
@@ -1,25 +1,21 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "sunzi/version"
1
+ # coding: utf-8
4
2
 
5
- Gem::Specification.new do |s|
6
- s.name = "sunzi"
7
- s.version = Sunzi::VERSION
8
- s.authors = ["Kenn Ejima"]
9
- s.email = ["kenn.ejima@gmail.com"]
10
- s.homepage = "http://github.com/kenn/sunzi"
11
- s.summary = %q{Server provisioning utility for minimalists}
12
- s.description = %q{Server provisioning utility for minimalists}
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'sunzi'
5
+ spec.version = '1.0.0' # retrieve this value by: Gem.loaded_specs['sunzi'].version.to_s
6
+ spec.authors = ['Kenn Ejima']
7
+ spec.email = ['kenn.ejima@gmail.com']
8
+ spec.homepage = 'http://github.com/kenn/sunzi'
9
+ spec.summary = %q{Server provisioning utility for minimalists}
10
+ spec.description = %q{Server provisioning utility for minimalists}
11
+ spec.license = 'MIT'
13
12
 
14
- s.rubyforge_project = "sunzi"
13
+ spec.files = `git ls-files`.split($/)
14
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.require_paths = ['lib']
15
17
 
16
- s.files = `git ls-files`.split("\n")
17
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
- s.require_paths = ["lib"]
20
-
21
- # s.add_development_dependency "rspec"
22
- s.add_runtime_dependency "thor"
23
- s.add_runtime_dependency "rainbow"
24
- s.add_development_dependency "rake"
18
+ spec.add_runtime_dependency 'thor'
19
+ spec.add_runtime_dependency 'rainbow'
20
+ spec.add_development_dependency 'rake'
25
21
  end
metadata CHANGED
@@ -1,64 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sunzi
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.9.0
4
+ version: 1.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Kenn Ejima
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-02-20 00:00:00.000000000 Z
11
+ date: 2013-03-22 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
- version_requirements: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ! '>='
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- none: false
21
- prerelease: false
22
14
  name: thor
23
15
  requirement: !ruby/object:Gem::Requirement
24
16
  requirements:
25
- - - ! '>='
17
+ - - '>='
26
18
  - !ruby/object:Gem::Version
27
19
  version: '0'
28
- none: false
29
20
  type: :runtime
30
- - !ruby/object:Gem::Dependency
21
+ prerelease: false
31
22
  version_requirements: !ruby/object:Gem::Requirement
32
23
  requirements:
33
- - - ! '>='
24
+ - - '>='
34
25
  - !ruby/object:Gem::Version
35
26
  version: '0'
36
- none: false
37
- prerelease: false
27
+ - !ruby/object:Gem::Dependency
38
28
  name: rainbow
39
29
  requirement: !ruby/object:Gem::Requirement
40
30
  requirements:
41
- - - ! '>='
31
+ - - '>='
42
32
  - !ruby/object:Gem::Version
43
33
  version: '0'
44
- none: false
45
34
  type: :runtime
46
- - !ruby/object:Gem::Dependency
35
+ prerelease: false
47
36
  version_requirements: !ruby/object:Gem::Requirement
48
37
  requirements:
49
- - - ! '>='
38
+ - - '>='
50
39
  - !ruby/object:Gem::Version
51
40
  version: '0'
52
- none: false
53
- prerelease: false
41
+ - !ruby/object:Gem::Dependency
54
42
  name: rake
55
43
  requirement: !ruby/object:Gem::Requirement
56
44
  requirements:
57
- - - ! '>='
45
+ - - '>='
58
46
  - !ruby/object:Gem::Version
59
47
  version: '0'
60
- none: false
61
48
  type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
62
55
  description: Server provisioning utility for minimalists
63
56
  email:
64
57
  - kenn.ejima@gmail.com
@@ -76,15 +69,12 @@ files:
76
69
  - lib/sunzi/cli.rb
77
70
  - lib/sunzi/cloud/base.rb
78
71
  - lib/sunzi/cloud/digital_ocean.rb
79
- - lib/sunzi/cloud/ec2.rb
80
72
  - lib/sunzi/cloud/linode.rb
81
73
  - lib/sunzi/dependency.rb
82
74
  - lib/sunzi/logger.rb
83
75
  - lib/sunzi/utility.rb
84
- - lib/sunzi/version.rb
85
76
  - lib/templates/create/.gitignore
86
77
  - lib/templates/create/install.sh
87
- - lib/templates/create/recipes/ssh_key.sh
88
78
  - lib/templates/create/recipes/sunzi.sh
89
79
  - lib/templates/create/roles/app.sh
90
80
  - lib/templates/create/roles/db.sh
@@ -95,34 +85,29 @@ files:
95
85
  - sunzi.gemspec
96
86
  - test/test_cli.rb
97
87
  homepage: http://github.com/kenn/sunzi
98
- licenses: []
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
99
91
  post_install_message:
100
92
  rdoc_options: []
101
93
  require_paths:
102
94
  - lib
103
95
  required_ruby_version: !ruby/object:Gem::Requirement
104
96
  requirements:
105
- - - ! '>='
97
+ - - '>='
106
98
  - !ruby/object:Gem::Version
107
99
  version: '0'
108
- segments:
109
- - 0
110
- hash: 3774298767527921378
111
- none: false
112
100
  required_rubygems_version: !ruby/object:Gem::Requirement
113
101
  requirements:
114
- - - ! '>='
102
+ - - '>='
115
103
  - !ruby/object:Gem::Version
116
104
  version: '0'
117
- segments:
118
- - 0
119
- hash: 3774298767527921378
120
- none: false
121
105
  requirements: []
122
- rubyforge_project: sunzi
123
- rubygems_version: 1.8.24
106
+ rubyforge_project:
107
+ rubygems_version: 2.0.3
124
108
  signing_key:
125
- specification_version: 3
109
+ specification_version: 4
126
110
  summary: Server provisioning utility for minimalists
127
111
  test_files:
128
112
  - test/test_cli.rb
113
+ has_rdoc:
@@ -1,13 +0,0 @@
1
- module Sunzi
2
- module Cloud
3
- class EC2 < Base
4
- def setup
5
- Logger.error 'EC2 is not implemented yet!'
6
- end
7
-
8
- def teardown(target)
9
- Logger.error 'EC2 is not implemented yet!'
10
- end
11
- end
12
- end
13
- end
data/lib/sunzi/version.rb DELETED
@@ -1,3 +0,0 @@
1
- module Sunzi
2
- VERSION = "0.9.0"
3
- end
@@ -1,18 +0,0 @@
1
- # SSH key
2
- # $1: SSH key filename
3
-
4
- if [ -f ~/.ssh/authorized_keys ]; then
5
- echo 'authorized_keys already created'
6
- else
7
- if [ -f "files/$1" ]; then
8
- echo 'Creating authorized_keys'
9
- mkdir -p ~/.ssh
10
- cat "files/$1" > ~/.ssh/authorized_keys
11
- rm "files/$1"
12
- chmod 700 ~/.ssh
13
- chmod 600 ~/.ssh/authorized_keys
14
- else
15
- echo "The public key file \"$1\" is not found! Look into files section in sunzi.yml."
16
- exit 1
17
- fi
18
- fi