chake 0.3.3 → 0.4
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/ChangeLog.md +15 -0
- data/README.md +12 -12
- data/Rakefile +20 -5
- data/chake.spec.erb +1 -1
- data/lib/chake.rb +11 -8
- data/lib/chake/backend.rb +2 -2
- data/lib/chake/backend/ssh.rb +6 -2
- data/lib/chake/node.rb +11 -0
- data/lib/chake/version.rb +1 -1
- data/spec/chake/backend/local_spec.rb +1 -1
- data/spec/chake/node_spec.rb +4 -4
- data/spec/spec_helper.rb +7 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7488361bba23f010e6873f567d922653ed2dcb3
|
4
|
+
data.tar.gz: e2166babc9c279160a4bd291418131d02fac9cfb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6a910451f2f1cd6c342441f2267fa75b1db5228ccb6be1d2580d9673f3a316b8dcc5ce6e8842129d5136b04d352d629df3a2b358f7a1cc3f9a1c56f61360dcb
|
7
|
+
data.tar.gz: dd3c5e2644fcff4aeffe72a858a102f5a23b453c7d9162f54e9594cfdd91812725cb5e5987b0ef2f36aa19d4586d63bb606ef7b4536c724852bb6e33594b681d
|
data/ChangeLog.md
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
# 0.4.0
|
2
|
+
|
3
|
+
* Redesign build of RPM package
|
4
|
+
* Output of command run on nodes is now aligned
|
5
|
+
* Change storage of temporary files from .tmp to tmp/chake
|
6
|
+
* The JSON node attributes files generated in tmp/chake are not readable
|
7
|
+
* SSH config file can now be controlled with the `$CHAKE_SSH_CONFIG`
|
8
|
+
environment variable
|
9
|
+
* Extra options for rsync can now be passed in the `$CHAKE_RSYNC_OPTIONS`
|
10
|
+
environment variable
|
11
|
+
* Chake::VERSION is now available in Rakefiles
|
12
|
+
* update test suite to use new rspec syntax instead the old one which is
|
13
|
+
obsolete in rspec 3.
|
14
|
+
* Thanks to Athos Ribeiro.
|
15
|
+
|
1
16
|
# 0.3.3
|
2
17
|
|
3
18
|
* rsync: exclude cache/ to work with the version of rsync in OSX
|
data/README.md
CHANGED
@@ -8,14 +8,6 @@ Simple host management with chef and rake. No chef server required.
|
|
8
8
|
|
9
9
|
## Creating the repository
|
10
10
|
|
11
|
-
Require chake on your `Rakefile`:
|
12
|
-
|
13
|
-
```ruby
|
14
|
-
require 'chake'
|
15
|
-
```
|
16
|
-
|
17
|
-
Initializing the repository:
|
18
|
-
|
19
11
|
```
|
20
12
|
$ chake init
|
21
13
|
[create] nodes.yaml
|
@@ -28,8 +20,8 @@ $ chake init
|
|
28
20
|
|
29
21
|
A brief explanation of the created files:
|
30
22
|
|
31
|
-
|
|
32
|
-
|
23
|
+
|File|Description|
|
24
|
+
|----|-----------|
|
33
25
|
| `nodes.yaml` | where you will list the hosts you will be managing, and what recipes to apply to each of them. |
|
34
26
|
| `config.rb` | contains the chef-solo configuration. You can modify it, but usually you won't need to. |
|
35
27
|
| `config/roles` | directory is where you can put your role definitions. |
|
@@ -158,8 +150,9 @@ of the configuration.
|
|
158
150
|
### repository-local SSH configuration
|
159
151
|
|
160
152
|
If you need special SSH configuration parameters, you can create a file called
|
161
|
-
`.ssh_config`
|
162
|
-
|
153
|
+
`.ssh_config` (or whatever name you have in the `$CHAKE_SSH_CONFIG` environment
|
154
|
+
variable, see below for details) in at the root of your repository, and chake
|
155
|
+
will use it when calling `ssh`.
|
163
156
|
|
164
157
|
### Converging local host
|
165
158
|
|
@@ -190,6 +183,13 @@ local://laptop:
|
|
190
183
|
When you run `rake converge` on `desktop`, `laptop` will be skipped, and
|
191
184
|
vice-versa.
|
192
185
|
|
186
|
+
### Environment variables
|
187
|
+
|
188
|
+
|Variable|Meaning|Default value|
|
189
|
+
|--------|-------|-------------|
|
190
|
+
| `$CHAKE_SSH_CONFIG` | local SSH configuration file | `.ssh_config` |
|
191
|
+
| `$CHAKE_RSYNC_OPTIONS` | extra options to pass to `rsync`. Useful to e.g. exclude large files from being upload to each server | _none_ |
|
192
|
+
|
193
193
|
## Contributing
|
194
194
|
|
195
195
|
1. Fork it ( http://github.com/terceiro/chake/fork )
|
data/Rakefile
CHANGED
@@ -6,25 +6,33 @@ end
|
|
6
6
|
|
7
7
|
pkg = Gem::Specification.load('chake.gemspec')
|
8
8
|
|
9
|
-
task :build do
|
9
|
+
task 'build:tarball' => [:build] do
|
10
10
|
chdir 'pkg' do
|
11
11
|
sh 'gem2tgz', "#{pkg.name}-#{pkg.version}.gem"
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
desc 'Create Debian source package'
|
16
|
-
task 'build:debsrc' => [:
|
16
|
+
task 'build:debsrc' => ['build:tarball'] do
|
17
17
|
dirname = "#{pkg.name}-#{pkg.version}"
|
18
18
|
chdir 'pkg' do
|
19
|
-
sh 'gem2deb', '--no-wnpp-check', '-s', '-p', pkg.name, "#{dirname}.
|
19
|
+
sh 'gem2deb', '--no-wnpp-check', '-s', '-p', pkg.name, "#{dirname}.tar.gz"
|
20
20
|
chdir dirname do
|
21
21
|
sh 'dpkg-buildpackage', '-S', '-us', '-uc'
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
+
desc 'Builds and installs Debian package'
|
27
|
+
task 'deb:install' => 'build:debsrc'do
|
28
|
+
chdir "pkg/#{pkg.name}-#{pkg.version}" do
|
29
|
+
sh 'fakeroot debian/rules binary'
|
30
|
+
end
|
31
|
+
sh 'sudo', 'dpkg', '-i', "pkg/#{pkg.name}_#{pkg.version}-1_all.deb"
|
32
|
+
end
|
33
|
+
|
26
34
|
desc 'Create source RPM package'
|
27
|
-
task 'build:rpmsrc' => [:
|
35
|
+
task 'build:rpmsrc' => ['build:tarball', 'pkg/chake.spec']
|
28
36
|
|
29
37
|
file 'pkg/chake.spec' => ['chake.spec.erb', 'lib/chake/version.rb'] do |t|
|
30
38
|
require 'erb'
|
@@ -80,6 +88,13 @@ task :changelog do
|
|
80
88
|
sh 'git', 'shortlog', last_tag + '..'
|
81
89
|
end
|
82
90
|
|
91
|
+
task :check_tag do
|
92
|
+
last_tag = `git tag | sort -V`.split.last
|
93
|
+
if last_tag == "v#{pkg.version}"
|
94
|
+
fail "Version #{pkg.version} was already released!"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
83
98
|
desc 'checks if the latest release is properly documented in ChangeLog.md'
|
84
99
|
task :check_changelog do
|
85
100
|
begin
|
@@ -90,6 +105,6 @@ task :check_changelog do
|
|
90
105
|
end
|
91
106
|
end
|
92
107
|
|
93
|
-
task :release => [:check_changelog, :test, :obs]
|
108
|
+
task :release => [:check_tag, :check_changelog, :test, :obs]
|
94
109
|
|
95
110
|
task :default => :test
|
data/chake.spec.erb
CHANGED
@@ -33,7 +33,7 @@ Requires: ruby, rubygem-rake
|
|
33
33
|
mkdir -p %{gembuilddir}
|
34
34
|
sed -i -e 's#spec.files\s*=.*#spec.files = Dir.glob("**/*")#' %{name}.gemspec
|
35
35
|
rake build
|
36
|
-
gem install --local --install-dir %{gembuilddir} --force pkg
|
36
|
+
gem install --local --install-dir %{gembuilddir} --force pkg/%{name}-%{version}.gem
|
37
37
|
mkdir -p %{buildroot}/%{_bindir}
|
38
38
|
mv %{gembuilddir}/bin/* %{buildroot}/%{_bindir}
|
39
39
|
rmdir %{gembuilddir}/bin
|
data/lib/chake.rb
CHANGED
@@ -5,12 +5,14 @@ require 'json'
|
|
5
5
|
require 'tmpdir'
|
6
6
|
require 'readline'
|
7
7
|
|
8
|
+
require 'chake/version'
|
8
9
|
require 'chake/node'
|
9
10
|
|
10
11
|
nodes_file = ENV['NODES'] || 'nodes.yaml'
|
11
12
|
node_data = File.exists?(nodes_file) && YAML.load_file(nodes_file) || {}
|
12
13
|
$nodes = node_data.map { |node,data| Chake::Node.new(node, data) }.reject(&:skip?).uniq(&:hostname)
|
13
|
-
|
14
|
+
$chake_tmpdir = 'tmp/chake'
|
15
|
+
FileUtils.mkdir_p($chake_tmpdir)
|
14
16
|
|
15
17
|
desc "Initializes current directory with sample structure"
|
16
18
|
task :init do
|
@@ -85,7 +87,7 @@ def if_files_changed(node, group_name, files)
|
|
85
87
|
return
|
86
88
|
end
|
87
89
|
hash = IO.popen(['sha1sum', *files]).read
|
88
|
-
hash_file = File.join(
|
90
|
+
hash_file = File.join($chake_tmpdir, node + '.' + group_name + '.sha1sum')
|
89
91
|
if !File.exists?(hash_file) || File.read(hash_file) != hash
|
90
92
|
yield
|
91
93
|
end
|
@@ -97,7 +99,7 @@ end
|
|
97
99
|
|
98
100
|
def write_json_file(file, data)
|
99
101
|
File.open(file, 'w') do |f|
|
100
|
-
f.write(JSON.
|
102
|
+
f.write(JSON.pretty_generate(data))
|
101
103
|
f.write("\n")
|
102
104
|
end
|
103
105
|
end
|
@@ -107,7 +109,7 @@ platforms = Dir.glob(File.expand_path('chake/bootstrap/*.sh', File.dirname(__FIL
|
|
107
109
|
$nodes.each do |node|
|
108
110
|
|
109
111
|
hostname = node.hostname
|
110
|
-
bootstrap_script = '
|
112
|
+
bootstrap_script = File.join($chake_tmpdir, 'bootstrap-' + hostname)
|
111
113
|
|
112
114
|
file bootstrap_script => platforms do |t|
|
113
115
|
mkdir_p(File.dirname(bootstrap_script))
|
@@ -125,8 +127,7 @@ $nodes.each do |node|
|
|
125
127
|
|
126
128
|
desc "bootstrap #{hostname}"
|
127
129
|
task "bootstrap:#{hostname}" => bootstrap_script do
|
128
|
-
|
129
|
-
config = '.tmp/' + hostname + '.json'
|
130
|
+
config = File.join($chake_tmpdir, hostname + '.json')
|
130
131
|
|
131
132
|
if File.exists?(config)
|
132
133
|
# already bootstrapped, just overwrite
|
@@ -150,8 +151,10 @@ $nodes.each do |node|
|
|
150
151
|
task "upload:#{hostname}" do
|
151
152
|
encrypted = encrypted_for(hostname)
|
152
153
|
rsync_excludes = (encrypted.values + encrypted.keys).map { |f| ["--exclude", f] }.flatten
|
154
|
+
rsync_excludes << "--exclude" << ".git/"
|
155
|
+
rsync_excludes << "--exclude" << "cache/"
|
153
156
|
|
154
|
-
rsync = node.rsync + ["-avp"
|
157
|
+
rsync = node.rsync + ["-avp"] + ENV.fetch('CHAKE_RSYNC_OPTIONS', '').split
|
155
158
|
rsync_logging = Rake.application.options.silent && '--quiet' || '--verbose'
|
156
159
|
|
157
160
|
files = Dir.glob("**/*").select { |f| !File.directory?(f) } - encrypted.keys - encrypted.values
|
@@ -174,7 +177,7 @@ $nodes.each do |node|
|
|
174
177
|
desc "converge #{hostname}"
|
175
178
|
task "converge:#{hostname}" => ["bootstrap:#{hostname}", "upload:#{hostname}"] do
|
176
179
|
chef_logging = Rake.application.options.silent && '-l fatal' || ''
|
177
|
-
node.run_as_root "chef-solo -c #{node.path}/config.rb #{chef_logging} -j #{node.path}
|
180
|
+
node.run_as_root "chef-solo -c #{node.path}/config.rb #{chef_logging} -j #{node.path}/#{$chake_tmpdir}/#{hostname}.json"
|
178
181
|
end
|
179
182
|
|
180
183
|
desc "run a command on #{hostname}"
|
data/lib/chake/backend.rb
CHANGED
@@ -22,10 +22,10 @@ module Chake
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def run(cmd)
|
25
|
-
|
25
|
+
printf "%#{Node.max_node_name_length}s: $ %s\n", node.hostname, cmd
|
26
26
|
output = IO.popen(command_runner + [cmd])
|
27
27
|
output.each_line do |line|
|
28
|
-
|
28
|
+
printf "%#{Node.max_node_name_length}s: %s\n", node.hostname, line.strip
|
29
29
|
end
|
30
30
|
output.close
|
31
31
|
if $?
|
data/lib/chake/backend/ssh.rb
CHANGED
@@ -27,11 +27,15 @@ module Chake
|
|
27
27
|
private
|
28
28
|
|
29
29
|
def rsync_ssh
|
30
|
-
File.exist?(
|
30
|
+
File.exist?(ssh_config_file) && ['-e', 'ssh -F ' + ssh_config_file ] || []
|
31
31
|
end
|
32
32
|
|
33
33
|
def ssh_config
|
34
|
-
File.exist?(
|
34
|
+
File.exist?(ssh_config_file) && ['-F', ssh_config_file] || []
|
35
|
+
end
|
36
|
+
|
37
|
+
def ssh_config_file
|
38
|
+
@ssh_config_file ||= ENV.fetch('CHAKE_SSH_CONFIG', '.ssh_config')
|
35
39
|
end
|
36
40
|
|
37
41
|
def ssh_target
|
data/lib/chake/node.rb
CHANGED
@@ -15,6 +15,13 @@ module Chake
|
|
15
15
|
attr_reader :path
|
16
16
|
attr_reader :data
|
17
17
|
|
18
|
+
def self.max_node_name_length
|
19
|
+
@max_node_name_length ||= 0
|
20
|
+
end
|
21
|
+
def self.max_node_name_length=(value)
|
22
|
+
@max_node_name_length = value
|
23
|
+
end
|
24
|
+
|
18
25
|
def initialize(hostname, data = {})
|
19
26
|
uri = URI.parse(hostname)
|
20
27
|
if !uri.scheme && !uri.host && uri.path
|
@@ -30,6 +37,10 @@ module Chake
|
|
30
37
|
@username = uri.user || Etc.getpwuid.name
|
31
38
|
@path = uri.path || "/var/tmp/chef.#{username}"
|
32
39
|
@data = data
|
40
|
+
|
41
|
+
if @hostname.length > self.class.max_node_name_length
|
42
|
+
self.class.max_node_name_length = @hostname.length
|
43
|
+
end
|
33
44
|
end
|
34
45
|
|
35
46
|
def backend
|
data/lib/chake/version.rb
CHANGED
@@ -11,7 +11,7 @@ describe Chake::Backend::Local do
|
|
11
11
|
it('rsyncs locally') { expect(backend.rsync_dest).to eq('/srv/chef/') }
|
12
12
|
|
13
13
|
it('skips if hostname is not the local hostname') do
|
14
|
-
Socket.
|
14
|
+
allow(Socket).to receive(:gethostname).and_return('otherhost')
|
15
15
|
expect(node.skip?).to eq(true)
|
16
16
|
end
|
17
17
|
end
|
data/spec/chake/node_spec.rb
CHANGED
@@ -4,8 +4,8 @@ describe Chake::Node do
|
|
4
4
|
|
5
5
|
before do
|
6
6
|
ent = double
|
7
|
-
ent.
|
8
|
-
Etc.
|
7
|
+
allow(ent).to receive(:name).and_return('jonhdoe')
|
8
|
+
allow(Etc).to receive(:getpwuid).and_return(ent)
|
9
9
|
end
|
10
10
|
|
11
11
|
let(:simple) { Chake::Node.new('hostname') }
|
@@ -40,9 +40,9 @@ describe Chake::Node do
|
|
40
40
|
|
41
41
|
backend = double
|
42
42
|
args = Object.new
|
43
|
-
node.
|
43
|
+
allow(node).to receive(:backend).and_return(backend)
|
44
44
|
|
45
|
-
backend.
|
45
|
+
expect(backend).to receive(method).with(args)
|
46
46
|
node.send(method, args)
|
47
47
|
end
|
48
48
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -13,21 +13,21 @@ shared_examples "Chake::Backend" do |backend_class|
|
|
13
13
|
|
14
14
|
it('runs commands') do
|
15
15
|
io = StringIO.new("line 1\nline 2\n")
|
16
|
-
IO.
|
17
|
-
backend.
|
18
|
-
backend.
|
19
|
-
backend.
|
16
|
+
expect(IO).to receive(:popen).with(backend.command_runner + ['something']).and_return(io)
|
17
|
+
expect(backend).to receive(:printf).with(anything, "myhost", "something")
|
18
|
+
expect(backend).to receive(:printf).with(anything, "myhost", "line 1")
|
19
|
+
expect(backend).to receive(:printf).with(anything, "myhost", "line 2")
|
20
20
|
backend.run('something')
|
21
21
|
end
|
22
22
|
|
23
23
|
it('runs as root') do
|
24
|
-
backend.
|
24
|
+
expect(backend).to receive(:run).with('sudo sh -c "something"')
|
25
25
|
backend.run_as_root('something')
|
26
26
|
end
|
27
27
|
|
28
28
|
it('does not use sudo if already root') do
|
29
|
-
backend.node.
|
30
|
-
backend.
|
29
|
+
allow(backend.node).to receive(:username).and_return('root')
|
30
|
+
expect(backend).to receive(:run).with('something')
|
31
31
|
backend.run_as_root('something')
|
32
32
|
end
|
33
33
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chake
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.4'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Antonio Terceiro
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|