bootlace 0.1.5
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.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +47 -0
- data/Rakefile +11 -0
- data/bootlace.gemspec +22 -0
- data/lib/bootlace.rb +14 -0
- data/lib/bootlace/bundler.rb +41 -0
- data/lib/bootlace/logger.rb +19 -0
- data/lib/bootlace/os.rb +26 -0
- data/lib/bootlace/package.rb +83 -0
- data/lib/bootlace/rake.rb +25 -0
- data/lib/bootlace/version.rb +3 -0
- data/test/bootlace/bundler_test.rb +31 -0
- data/test/bootlace/os_test.rb +61 -0
- data/test/bootlace/package_test.rb +107 -0
- data/test/bootlace/rake_test.rb +36 -0
- data/test/bootlace_test.rb +24 -0
- data/test/test_helper.rb +30 -0
- metadata +121 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Will Farrington
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# Bootlace
|
2
|
+
|
3
|
+
A simple gem for bootstrapping Ruby applications based upon the GitHub script/bootstrap model, but with a tiny DSL on top.
|
4
|
+
|
5
|
+
Right now it's very lightweight, and the DSL is expected to change as we use it on more projects and find we need to revise
|
6
|
+
how we're doing things.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'bootlace', require: false
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install bootlace
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
You may use Bootlace stand-alone or integrated with Rails.
|
25
|
+
|
26
|
+
Create a `script/bootstrap` file in your app that looks like so:
|
27
|
+
|
28
|
+
```
|
29
|
+
#!/bin/env ruby
|
30
|
+
|
31
|
+
require 'bootlace'
|
32
|
+
include Bootlace
|
33
|
+
|
34
|
+
package mac: "redis", ubuntu: "redis-server"
|
35
|
+
|
36
|
+
bundler
|
37
|
+
|
38
|
+
rake 'db:create', environment: { "RAILS_ENV" => "test" }
|
39
|
+
```
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
1. Fork it
|
44
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
45
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
46
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
47
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/bootlace.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/bootlace/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Will Farrington"]
|
6
|
+
gem.email = ["will@highgroove.com"]
|
7
|
+
gem.description = %q{Simple gem for bootstrapping Ruby applications}
|
8
|
+
gem.summary = %q{A simple gem for bootstrapping Ruby applications based upon the GitHub script/bootstrap model, but with a tiny DSL on top.}
|
9
|
+
gem.homepage = "https://github.com/highgroove/bootlace"
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = "bootlace"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Bootlace::VERSION
|
17
|
+
|
18
|
+
gem.add_development_dependency('mocha')
|
19
|
+
gem.add_development_dependency('activesupport')
|
20
|
+
gem.add_development_dependency('turn')
|
21
|
+
gem.add_development_dependency('pry')
|
22
|
+
end
|
data/lib/bootlace.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "bootlace/version"
|
2
|
+
require "bootlace/logger"
|
3
|
+
require "bootlace/os"
|
4
|
+
require "bootlace/package"
|
5
|
+
require "bootlace/rake"
|
6
|
+
require "bootlace/bundler"
|
7
|
+
|
8
|
+
module Bootlace
|
9
|
+
include Bootlace::OS
|
10
|
+
include Bootlace::Logger
|
11
|
+
include Bootlace::Package
|
12
|
+
include Bootlace::Rake
|
13
|
+
include Bootlace::Bundler
|
14
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require_relative 'logger'
|
2
|
+
require 'digest'
|
3
|
+
|
4
|
+
module Bootlace
|
5
|
+
module Bundler
|
6
|
+
include Bootlace::Logger
|
7
|
+
|
8
|
+
def bundler
|
9
|
+
checksum = get_bundle_checksum
|
10
|
+
|
11
|
+
begin
|
12
|
+
installed = File.read('.bundle/checksum')
|
13
|
+
rescue Errno::ENOENT
|
14
|
+
logger.info "No checksum cache file, will bundle."
|
15
|
+
end
|
16
|
+
|
17
|
+
unless installed == checksum
|
18
|
+
logger.info "Bundling"
|
19
|
+
system 'bundle install --quiet'
|
20
|
+
else
|
21
|
+
logger.info "Bundle up-to-date; not bundling"
|
22
|
+
end
|
23
|
+
|
24
|
+
unless Dir.exist? '.bundle'
|
25
|
+
Dir.mkdir '.bundle'
|
26
|
+
end
|
27
|
+
|
28
|
+
File.open('.bundle/checksum', 'w+') do |f|
|
29
|
+
f.write checksum
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
def get_bundle_checksum
|
35
|
+
md5 = ""
|
36
|
+
md5 << File.read('Gemfile')
|
37
|
+
md5 << File.read('Gemfile.lock')
|
38
|
+
Digest::MD5.hexdigest md5
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
module Bootlace
|
4
|
+
module Logger
|
5
|
+
def logger
|
6
|
+
if ENV["TEST"]
|
7
|
+
@logger ||= ::Logger.new('/tmp/bootlace.log')
|
8
|
+
else
|
9
|
+
@logger ||= ::Logger.new(STDOUT)
|
10
|
+
end
|
11
|
+
|
12
|
+
@logger.formatter = proc do |severity, datetime, progname, msg|
|
13
|
+
"[#{progname}] #{severity}: #{msg}\n"
|
14
|
+
end
|
15
|
+
|
16
|
+
@logger
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/bootlace/os.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
module Bootlace
|
2
|
+
module OS
|
3
|
+
def os
|
4
|
+
if RUBY_PLATFORM.downcase.include? 'darwin'
|
5
|
+
:mac
|
6
|
+
elsif RUBY_PLATFORM.downcase.include? "linux"
|
7
|
+
fetch_distribution
|
8
|
+
else
|
9
|
+
:unsupported
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
def fetch_distribution
|
15
|
+
if File.exist? '/etc/redhat-release'
|
16
|
+
:centos
|
17
|
+
elsif File.exist? '/etc/debian_version'
|
18
|
+
:debian
|
19
|
+
elsif File.exist? '/etc/ubuntu_version'
|
20
|
+
:ubuntu
|
21
|
+
else
|
22
|
+
:unsupported
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require_relative 'logger'
|
2
|
+
require_relative 'os'
|
3
|
+
|
4
|
+
module Bootlace
|
5
|
+
module Package
|
6
|
+
include Bootlace::OS
|
7
|
+
include Bootlace::Logger
|
8
|
+
|
9
|
+
attr_reader :noop
|
10
|
+
|
11
|
+
def noop!
|
12
|
+
@noop = true
|
13
|
+
end
|
14
|
+
|
15
|
+
def package(arg)
|
16
|
+
case arg.class.name
|
17
|
+
when "String"
|
18
|
+
install_package_from_string arg
|
19
|
+
when "Hash"
|
20
|
+
install_package_from_hash arg
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def install_package_from_string(s)
|
25
|
+
unless package_installed? s
|
26
|
+
if noop
|
27
|
+
logger.info("Would have installed package '#{s}' via #{package_manager}")
|
28
|
+
else
|
29
|
+
logger.info("Installing package '#{s}' via #{package_manager}")
|
30
|
+
install_package s
|
31
|
+
end
|
32
|
+
else
|
33
|
+
logger.info("Package '#{s}' already installed; skipping")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def install_package_from_hash(hash)
|
38
|
+
unless package_installed? hash[os]
|
39
|
+
if noop
|
40
|
+
logger.info("Would have installed package '#{hash[os]}' via #{package_manager}")
|
41
|
+
else
|
42
|
+
logger.info("Installing package '#{hash[os]}' via #{package_manager}")
|
43
|
+
install_package hash[os]
|
44
|
+
end
|
45
|
+
else
|
46
|
+
logger.info("Package '#{hash[os]}' already installed; skipping")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
def install_package(name)
|
52
|
+
system [
|
53
|
+
os == :mac ? "" : "sudo",
|
54
|
+
package_manager,
|
55
|
+
"install",
|
56
|
+
name
|
57
|
+
].join(" ").strip
|
58
|
+
end
|
59
|
+
|
60
|
+
def package_installed?(name)
|
61
|
+
case os
|
62
|
+
when :mac
|
63
|
+
system "brew list | grep #{name} > /dev/null"
|
64
|
+
when :ubuntu
|
65
|
+
system "sudo aptitude show #{name} | grep installed > /dev/null"
|
66
|
+
when :debian
|
67
|
+
system "sudo aptitude show #{name} | grep installed > /dev/null"
|
68
|
+
when :centos
|
69
|
+
system "sudo yum list #{name} | grep installed > /dev/null"
|
70
|
+
end
|
71
|
+
$? == 0 ? true : false
|
72
|
+
end
|
73
|
+
|
74
|
+
def package_manager
|
75
|
+
{
|
76
|
+
mac: 'brew',
|
77
|
+
ubuntu: 'apt-get',
|
78
|
+
debian: 'apt-get',
|
79
|
+
centos: 'yum'
|
80
|
+
}.fetch(os)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative 'logger'
|
2
|
+
|
3
|
+
module Bootlace
|
4
|
+
module Rake
|
5
|
+
include Bootlace::Logger
|
6
|
+
|
7
|
+
def rake(task, o = {})
|
8
|
+
options = {
|
9
|
+
environment: {}
|
10
|
+
}.merge(o)
|
11
|
+
|
12
|
+
options[:environment].each do |key,val|
|
13
|
+
ENV[key] = val
|
14
|
+
end
|
15
|
+
|
16
|
+
logger.info("Executing rake task '#{task}'")
|
17
|
+
system "#{detect_bundle} rake #{task}".strip
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
def detect_bundle
|
22
|
+
File.exist?('Gemfile') ? "bundle exec" : ""
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.expand_path("../../../lib/bootlace/bundler", __FILE__)
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class BootstrapBundler
|
5
|
+
include Bootlace::Bundler
|
6
|
+
end
|
7
|
+
|
8
|
+
class BundlerTest < Test::Unit::TestCase
|
9
|
+
include TestHelpers
|
10
|
+
|
11
|
+
attr_accessor :bootstrap
|
12
|
+
|
13
|
+
def setup
|
14
|
+
@bootstrap = BootstrapBundler.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_bundles_when_content_out_of_date
|
18
|
+
bootstrap.stubs(:get_bundle_checksum).returns("foobar")
|
19
|
+
File.stubs(:read).with(".bundle/checksum").returns("barbaz")
|
20
|
+
bootstrap.expects(:system).with("bundle install --quiet")
|
21
|
+
bootstrap.bundler
|
22
|
+
assert_match /Bundling/, last_log
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_does_not_bundle_when_content_out_of_date
|
26
|
+
bootstrap.stubs(:get_bundle_checksum).returns("foobar")
|
27
|
+
File.stubs(:read).with(".bundle/checksum").returns("foobar")
|
28
|
+
bootstrap.bundler
|
29
|
+
assert_match /Bundle up-to-date; not bundling/, last_log
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require File.expand_path("../../../lib/bootlace/os", __FILE__)
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class BootstrapOS
|
5
|
+
include Bootlace::OS
|
6
|
+
end
|
7
|
+
|
8
|
+
class OsTest < Test::Unit::TestCase
|
9
|
+
include TestHelpers
|
10
|
+
|
11
|
+
attr_accessor :bootstrap
|
12
|
+
|
13
|
+
def setup
|
14
|
+
@bootstrap = BootstrapOS.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_os_when_mac
|
18
|
+
with_constants RUBY_PLATFORM: 'darwin' do
|
19
|
+
assert_equal :mac, bootstrap.os
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_os_when_centos
|
24
|
+
with_constants RUBY_PLATFORM: 'linux' do
|
25
|
+
File.expects(:exist?).with('/etc/redhat-release').returns(true)
|
26
|
+
assert_equal :centos, bootstrap.os
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_os_when_ubuntu
|
31
|
+
with_constants RUBY_PLATFORM: 'linux' do
|
32
|
+
File.expects(:exist?).with('/etc/redhat-release').returns(false)
|
33
|
+
File.expects(:exist?).with('/etc/debian_version').returns(false)
|
34
|
+
File.expects(:exist?).with('/etc/ubuntu_version').returns(true)
|
35
|
+
assert_equal :ubuntu, bootstrap.os
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_os_when_debian
|
40
|
+
with_constants RUBY_PLATFORM: 'linux' do
|
41
|
+
File.expects(:exist?).with('/etc/redhat-release').returns(false)
|
42
|
+
File.expects(:exist?).with('/etc/debian_version').returns(true)
|
43
|
+
assert_equal :debian, bootstrap.os
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_os_linux_unsupported
|
48
|
+
with_constants RUBY_PLATFORM: 'linux' do
|
49
|
+
File.expects(:exist?).with('/etc/redhat-release').returns(false)
|
50
|
+
File.expects(:exist?).with('/etc/debian_version').returns(false)
|
51
|
+
File.expects(:exist?).with('/etc/ubuntu_version').returns(false)
|
52
|
+
assert_equal :unsupported, bootstrap.os
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_os_unsupported
|
57
|
+
with_constants RUBY_PLATFORM: 'win32' do
|
58
|
+
assert_equal :unsupported, bootstrap.os
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require File.expand_path("../../../lib/bootlace/package", __FILE__)
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class BootstrapPackage
|
5
|
+
include Bootlace::Package
|
6
|
+
end
|
7
|
+
|
8
|
+
class PackageTest < Test::Unit::TestCase
|
9
|
+
include TestHelpers
|
10
|
+
|
11
|
+
attr_accessor :bootstrap
|
12
|
+
|
13
|
+
def setup
|
14
|
+
@bootstrap = BootstrapPackage.new
|
15
|
+
after_setup_hook
|
16
|
+
end
|
17
|
+
|
18
|
+
def after_setup_hook
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class NoopPackageTest < PackageTest
|
23
|
+
def after_setup_hook
|
24
|
+
bootstrap.noop!
|
25
|
+
bootstrap.stubs(:package_installed?).returns(false)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_package_without_hash_defaults_to_current_platform
|
29
|
+
bootstrap.package 'redis'
|
30
|
+
assert_match /Would have installed package 'redis' via brew/, last_log
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_accepts_hash_of_package_names
|
34
|
+
bootstrap.stubs(:os).returns(:mac)
|
35
|
+
bootstrap.package mac: 'redis', ubuntu: 'redis-server'
|
36
|
+
assert_match /Would have installed package 'redis' via brew/, last_log
|
37
|
+
|
38
|
+
bootstrap.stubs(:os).returns(:ubuntu)
|
39
|
+
bootstrap.package mac: 'redis', ubuntu: 'redis-server'
|
40
|
+
assert_match /Would have installed package 'redis-server' via apt-get/, last_log
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class RealPackageTest < PackageTest
|
45
|
+
def test_package_without_hash_defaults_to_current_platform
|
46
|
+
bootstrap.stubs(:os).returns(:mac)
|
47
|
+
bootstrap.stubs(:package_installed?).returns(false)
|
48
|
+
bootstrap.expects(:system).with('brew install redis').returns(0)
|
49
|
+
bootstrap.package 'redis'
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_accepts_hash_of_package_names_mac
|
53
|
+
bootstrap.stubs(:os).returns(:mac)
|
54
|
+
bootstrap.stubs(:package_installed?).returns(false)
|
55
|
+
bootstrap.expects(:system).with('brew install redis').returns(0)
|
56
|
+
bootstrap.package mac: 'redis', ubuntu: 'redis-server'
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_accepts_hash_of_package_names_ubuntu
|
60
|
+
bootstrap.stubs(:os).returns(:ubuntu)
|
61
|
+
bootstrap.stubs(:package_installed?).returns(false)
|
62
|
+
bootstrap.expects(:system).with('sudo apt-get install redis-server').returns(0)
|
63
|
+
bootstrap.package mac: 'redis', ubuntu: 'redis-server'
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_accepts_hash_of_package_names_debian
|
67
|
+
bootstrap.stubs(:os).returns(:debian)
|
68
|
+
bootstrap.stubs(:package_installed?).returns(false)
|
69
|
+
bootstrap.expects(:system).with('sudo apt-get install redis-server').returns(0)
|
70
|
+
bootstrap.package mac: 'redis', debian: 'redis-server'
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_accepts_hash_of_package_names_centos
|
74
|
+
bootstrap.stubs(:os).returns(:centos)
|
75
|
+
bootstrap.stubs(:package_installed?).returns(false)
|
76
|
+
bootstrap.expects(:system).with('sudo yum install redis-server').returns(0)
|
77
|
+
bootstrap.package mac: 'redis', centos: 'redis-server'
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_does_not_attempt_to_reinstall_already_installed_package_mac
|
81
|
+
bootstrap.stubs(:os).returns(:mac)
|
82
|
+
bootstrap.expects(:system).with('brew list | grep redis > /dev/null').returns(0)
|
83
|
+
bootstrap.package mac: 'redis'
|
84
|
+
assert_match /Package 'redis' already installed; skipping/, last_log
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_does_not_attempt_to_reinstall_already_installed_package_ubuntu
|
88
|
+
bootstrap.stubs(:os).returns(:ubuntu)
|
89
|
+
bootstrap.expects(:system).with('sudo aptitude show redis-server | grep installed > /dev/null').returns(0)
|
90
|
+
bootstrap.package ubuntu: 'redis-server'
|
91
|
+
assert_match /Package 'redis-server' already installed; skipping/, last_log
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_does_not_attempt_to_reinstall_already_installed_package_debian
|
95
|
+
bootstrap.stubs(:os).returns(:debian)
|
96
|
+
bootstrap.expects(:system).with('sudo aptitude show redis-server | grep installed > /dev/null').returns(0)
|
97
|
+
bootstrap.package debian: 'redis-server'
|
98
|
+
assert_match /Package 'redis-server' already installed; skipping/, last_log
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_does_not_attempt_to_reinstall_already_installed_package_centos
|
102
|
+
bootstrap.stubs(:os).returns(:centos)
|
103
|
+
bootstrap.expects(:system).with('sudo yum list redis-server | grep installed > /dev/null').returns(0)
|
104
|
+
bootstrap.package centos: 'redis-server'
|
105
|
+
assert_match /Package 'redis-server' already installed; skipping/, last_log
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require File.expand_path("../../../lib/bootlace/rake", __FILE__)
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class BootstrapRake
|
5
|
+
include Bootlace::Rake
|
6
|
+
end
|
7
|
+
|
8
|
+
class RakeTest < Test::Unit::TestCase
|
9
|
+
include TestHelpers
|
10
|
+
|
11
|
+
attr_accessor :bootstrap
|
12
|
+
|
13
|
+
def setup
|
14
|
+
@bootstrap = BootstrapRake.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_rake_task_no_gemfile
|
18
|
+
File.stubs(:exist?).with('Gemfile').returns(false)
|
19
|
+
bootstrap.expects(:system).with("rake foo:bar:baz")
|
20
|
+
bootstrap.rake "foo:bar:baz"
|
21
|
+
assert_match /Executing rake task 'foo:bar:baz'/, last_log
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_rake_task_with_gemfile
|
25
|
+
File.stubs(:exist?).with('Gemfile').returns(true)
|
26
|
+
bootstrap.expects(:system).with("bundle exec rake foo:bar:baz")
|
27
|
+
bootstrap.rake "foo:bar:baz"
|
28
|
+
assert_match /Executing rake task 'foo:bar:baz'/, last_log
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_rake_task_with_environment
|
32
|
+
bootstrap.stubs(:system).returns(0)
|
33
|
+
bootstrap.rake "foo:bar:baz", environment: { "SOMEOPT" => "SET" }
|
34
|
+
assert_equal "SET", ENV['SOMEOPT']
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.expand_path("../../lib/bootlace", __FILE__)
|
2
|
+
require_relative 'test_helper.rb'
|
3
|
+
|
4
|
+
class Bootstrap
|
5
|
+
include Bootlace
|
6
|
+
end
|
7
|
+
|
8
|
+
class BootlaceTest < Test::Unit::TestCase
|
9
|
+
include TestHelpers
|
10
|
+
|
11
|
+
attr_accessor :bootstrap
|
12
|
+
|
13
|
+
def setup
|
14
|
+
@bootstrap = Bootstrap.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_reality
|
18
|
+
bootstrap.stubs(:system).returns(0)
|
19
|
+
bootstrap.bundler
|
20
|
+
bootstrap.rake 'foo'
|
21
|
+
bootstrap.package 'bar'
|
22
|
+
true
|
23
|
+
end
|
24
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'mocha'
|
3
|
+
require 'turn'
|
4
|
+
require 'pry'
|
5
|
+
|
6
|
+
ENV["TEST"] = "true"
|
7
|
+
|
8
|
+
module TestHelpers
|
9
|
+
require 'active_support/core_ext/kernel'
|
10
|
+
|
11
|
+
def last_log
|
12
|
+
IO.readlines("/tmp/bootlace.log").last
|
13
|
+
end
|
14
|
+
|
15
|
+
def with_constants(constants, &block)
|
16
|
+
saved_constants = {}
|
17
|
+
constants.each do |constant, val|
|
18
|
+
saved_constants[ constant ] = Object.const_get( constant )
|
19
|
+
Kernel::silence_warnings { Object.const_set( constant, val ) }
|
20
|
+
end
|
21
|
+
|
22
|
+
begin
|
23
|
+
block.call
|
24
|
+
ensure
|
25
|
+
constants.each do |constant, val|
|
26
|
+
Kernel::silence_warnings { Object.const_set( constant, saved_constants[ constant ] ) }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bootlace
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.5
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Will Farrington
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-20 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: mocha
|
16
|
+
requirement: &70201076898840 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70201076898840
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: activesupport
|
27
|
+
requirement: &70201076897300 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70201076897300
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: turn
|
38
|
+
requirement: &70201076895780 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70201076895780
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: pry
|
49
|
+
requirement: &70201077316640 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70201077316640
|
58
|
+
description: Simple gem for bootstrapping Ruby applications
|
59
|
+
email:
|
60
|
+
- will@highgroove.com
|
61
|
+
executables: []
|
62
|
+
extensions: []
|
63
|
+
extra_rdoc_files: []
|
64
|
+
files:
|
65
|
+
- .gitignore
|
66
|
+
- Gemfile
|
67
|
+
- LICENSE
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bootlace.gemspec
|
71
|
+
- lib/bootlace.rb
|
72
|
+
- lib/bootlace/bundler.rb
|
73
|
+
- lib/bootlace/logger.rb
|
74
|
+
- lib/bootlace/os.rb
|
75
|
+
- lib/bootlace/package.rb
|
76
|
+
- lib/bootlace/rake.rb
|
77
|
+
- lib/bootlace/version.rb
|
78
|
+
- test/bootlace/bundler_test.rb
|
79
|
+
- test/bootlace/os_test.rb
|
80
|
+
- test/bootlace/package_test.rb
|
81
|
+
- test/bootlace/rake_test.rb
|
82
|
+
- test/bootlace_test.rb
|
83
|
+
- test/test_helper.rb
|
84
|
+
homepage: https://github.com/highgroove/bootlace
|
85
|
+
licenses: []
|
86
|
+
post_install_message:
|
87
|
+
rdoc_options: []
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
92
|
+
requirements:
|
93
|
+
- - ! '>='
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
segments:
|
97
|
+
- 0
|
98
|
+
hash: 4064085767876468573
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
102
|
+
- - ! '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
segments:
|
106
|
+
- 0
|
107
|
+
hash: 4064085767876468573
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 1.8.16
|
111
|
+
signing_key:
|
112
|
+
specification_version: 3
|
113
|
+
summary: A simple gem for bootstrapping Ruby applications based upon the GitHub script/bootstrap
|
114
|
+
model, but with a tiny DSL on top.
|
115
|
+
test_files:
|
116
|
+
- test/bootlace/bundler_test.rb
|
117
|
+
- test/bootlace/os_test.rb
|
118
|
+
- test/bootlace/package_test.rb
|
119
|
+
- test/bootlace/rake_test.rb
|
120
|
+
- test/bootlace_test.rb
|
121
|
+
- test/test_helper.rb
|