catfish 0.0.2
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 +7 -0
- data/.gitignore +34 -0
- data/.rubocop.yml +15 -0
- data/Gemfile +4 -0
- data/LICENSE +13 -0
- data/README.md +70 -0
- data/Rakefile +4 -0
- data/bin/catfish +4 -0
- data/catfish.gemspec +24 -0
- data/lib/catfish/cli/init.rb +36 -0
- data/lib/catfish/cli/provision.rb +66 -0
- data/lib/catfish/cli/resolve.rb +17 -0
- data/lib/catfish/cli.rb +57 -0
- data/lib/catfish/dsl.rb +24 -0
- data/lib/catfish/templates/Catfishfile.tt +3 -0
- data/lib/catfish/templates/Vagrantfile.tt +26 -0
- data/lib/catfish/version.rb +3 -0
- data/lib/catfish.rb +5 -0
- metadata +120 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b63b69165aada8de23e53e4022a6acf0b3500093
|
4
|
+
data.tar.gz: 34bd5c4600e0d32a6ef1be3ab07426041093b921
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 19103395e52ac6776a15947222b5f5323b71bea9e30baf17589388069b5f1869bfb6d998e1df4e4a2a70f140c491515c7bb6de113f2331dab623495300c50c5d
|
7
|
+
data.tar.gz: cb8bb9b8117ea866d22594496486e559c24764514a55e35cc22348bdcd44d24585ded1c0c38a7589dfdc69fc5c686e65a7033904b2a4a410523251e2d6e0a261
|
data/.gitignore
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/lib/bundler/man/
|
26
|
+
|
27
|
+
# for a library or gem, you might want to ignore these files since the code is
|
28
|
+
# intended to run in multiple environments; otherwise, check them in:
|
29
|
+
# Gemfile.lock
|
30
|
+
# .ruby-version
|
31
|
+
# .ruby-gemset
|
32
|
+
|
33
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
34
|
+
.rvmrc
|
data/.rubocop.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright 2014 Cimpress
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
catfish
|
2
|
+
=======
|
3
|
+
|
4
|
+
Catfish is a command line tool and set of associated Vagrantfile templates that makes provisioning existing servers with vagrant-managed-servers easy. It is designed from the ground up to be cross-platform, with first class support for Windows, Linux, and Mac.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'catfish'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install catfish
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
### Initialize your repository
|
25
|
+
Initialize a catfish repository in the current directory, which will create a
|
26
|
+
Catfishfile and a Vagrantfile at a minimum.
|
27
|
+
|
28
|
+
$ catfish init
|
29
|
+
|
30
|
+
Specify connection options for ssh
|
31
|
+
|
32
|
+
$ catfish init --ssh-username=YOUR_USERNAME --ssh-private-key-path=YOUR_SSH_KEY_PATH
|
33
|
+
|
34
|
+
Include two shell provisioners
|
35
|
+
|
36
|
+
$ catfish init --provisioners=shell --shell-paths=./script/a.sh ./script/b.sh
|
37
|
+
|
38
|
+
### Add the target servers in your Catfishfile
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
server 'myserver1.mydomain.com'
|
42
|
+
server 'myserver2.mydomain.com'
|
43
|
+
```
|
44
|
+
|
45
|
+
### Provision your servers
|
46
|
+
|
47
|
+
$ catfish provision
|
48
|
+
|
49
|
+
And you can even run the provisioning in parallel
|
50
|
+
|
51
|
+
$ catfish provision --parallel
|
52
|
+
|
53
|
+
### Getting help
|
54
|
+
|
55
|
+
$ catfish help
|
56
|
+
|
57
|
+
## TODO
|
58
|
+
|
59
|
+
- Perform resolve as part of provision to simplify the flow
|
60
|
+
- Puppet provisioner support
|
61
|
+
- Vagrant plugin support in Catfishfile
|
62
|
+
- WinRM support
|
63
|
+
|
64
|
+
## Contributing
|
65
|
+
|
66
|
+
1. Fork it ( https://github.com/chrisbaldauf/catfish/fork )
|
67
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
68
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
69
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
70
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/catfish
ADDED
data/catfish.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'catfish/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'catfish'
|
8
|
+
spec.version = Catfish::VERSION
|
9
|
+
spec.authors = ['Christopher Baldauf']
|
10
|
+
spec.email = ['cbaldauf@cimpress.com']
|
11
|
+
spec.summary = 'Command line tool and set of templates that makes using vagrant-managed-servers easy across platforms.'
|
12
|
+
spec.homepage = 'https://github.com/chrisbaldauf/catfish'
|
13
|
+
spec.license = 'Apache 2'
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = %w(lib bin)
|
19
|
+
|
20
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
21
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
22
|
+
spec.add_development_dependency 'rubocop', '~> 0.27'
|
23
|
+
spec.add_dependency 'thor', '~> 0.19.1'
|
24
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Catfish
|
2
|
+
class CLI
|
3
|
+
class Init
|
4
|
+
attr_reader :options, :thor
|
5
|
+
|
6
|
+
def initialize(options, thor)
|
7
|
+
@options = options
|
8
|
+
@thor = thor
|
9
|
+
end
|
10
|
+
|
11
|
+
def run
|
12
|
+
p 'Initializing Catfish repository'
|
13
|
+
|
14
|
+
templates = {
|
15
|
+
'Catfishfile.tt' => 'Catfishfile',
|
16
|
+
'Vagrantfile.tt' => 'Vagrantfile'
|
17
|
+
}
|
18
|
+
|
19
|
+
opts = {
|
20
|
+
ssh_username: options['ssh-username'] || '{{YOUR_SSH_USERNAME}}',
|
21
|
+
ssh_private_key_path: options['ssh-private-key-path'] || '{{PATH_TO_YOUR_SSH_PRIVATE_KEY}}',
|
22
|
+
provisioners: options[:provisioners] || [],
|
23
|
+
shell_paths: options['shell-paths'] || ['{{PATH_TO_YOUR_SCRIPT}}']
|
24
|
+
}
|
25
|
+
|
26
|
+
templates.each do |src, dst|
|
27
|
+
thor.template(src, dst, opts)
|
28
|
+
end
|
29
|
+
p 'Repository initialized. Remember to:'
|
30
|
+
p ' - Check your Vagrantfile and replace any placeholders'
|
31
|
+
p ' - Edit your Catfish file and list target servers'
|
32
|
+
p ' - Run catfish resolve'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Catfish
|
2
|
+
class CLI::Provision
|
3
|
+
attr_reader :options
|
4
|
+
|
5
|
+
def initialize(options)
|
6
|
+
@options = options
|
7
|
+
end
|
8
|
+
|
9
|
+
def run
|
10
|
+
p 'Provisioning to servers using Catfishfile.lock'
|
11
|
+
vagrant_version
|
12
|
+
vagrant_plugins
|
13
|
+
begin
|
14
|
+
# Connect to the servers. The --provider=managed is the key here.
|
15
|
+
system("vagrant up --provider=#{options[:provider]}")
|
16
|
+
|
17
|
+
# Confirm the connectivity
|
18
|
+
status = `vagrant status --machine-readable`
|
19
|
+
if status.include? 'not reachable'
|
20
|
+
abort 'ERROR DEPLOYING: One or more servers could not be connected to'
|
21
|
+
end
|
22
|
+
|
23
|
+
provision
|
24
|
+
|
25
|
+
ensure
|
26
|
+
|
27
|
+
# Disconnect from all of the servers
|
28
|
+
system 'vagrant destroy -f'
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def vagrant_version
|
36
|
+
vagrant_version = 'Vagrant 1.6'
|
37
|
+
fail "#{vagrant_version} or greater is a prerequisite" unless `vagrant --version`.include? vagrant_version
|
38
|
+
end
|
39
|
+
|
40
|
+
def vagrant_plugins
|
41
|
+
# Make sure that the vagrant-managed-servers plugin is installed
|
42
|
+
plugins = ['vagrant-managed-servers']
|
43
|
+
plugins.each do |plugin|
|
44
|
+
system("vagrant plugin install #{plugin}") unless `vagrant plugin list`.include? plugin
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def provision
|
49
|
+
if options[:parallel]
|
50
|
+
machines = status.split("\n").collect do |line|
|
51
|
+
line.split(',')[1]
|
52
|
+
end
|
53
|
+
threads = []
|
54
|
+
machines.uniq!.each do |machine|
|
55
|
+
threads << Thread.new do
|
56
|
+
system "vagrant provision #{machine}"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
threads.each(&:join)
|
61
|
+
else
|
62
|
+
system 'vagrant provision'
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Catfish
|
2
|
+
class CLI::Resolve
|
3
|
+
attr_reader :options, :thor
|
4
|
+
|
5
|
+
def initialize(options, thor)
|
6
|
+
@options = options
|
7
|
+
@thor = thor
|
8
|
+
end
|
9
|
+
|
10
|
+
def run
|
11
|
+
builder = Dsl.new
|
12
|
+
builder.eval_catfishfile
|
13
|
+
IO.write('Catfishfile.lock', builder.servers.join("\n"))
|
14
|
+
p "#{builder.servers.size} servers found"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/catfish/cli.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'catfish'
|
2
|
+
require 'thor'
|
3
|
+
|
4
|
+
module Catfish
|
5
|
+
class CLI < Thor
|
6
|
+
include Thor::Actions
|
7
|
+
|
8
|
+
# def self.start(*)
|
9
|
+
# super
|
10
|
+
# rescue Exception => e
|
11
|
+
# Bundler.ui = UI::Shell.new
|
12
|
+
# raise e
|
13
|
+
# ensure
|
14
|
+
# Bundler.cleanup
|
15
|
+
# end
|
16
|
+
|
17
|
+
def initialize(*args)
|
18
|
+
super
|
19
|
+
rescue UnknownArgumentError => e
|
20
|
+
raise InvalidOption, e.message
|
21
|
+
ensure
|
22
|
+
self.options ||= {}
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.source_root
|
26
|
+
File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
|
27
|
+
end
|
28
|
+
|
29
|
+
desc 'init [OPTIONS]', 'Generates a templated catfish repo in the current working directory'
|
30
|
+
long_desc <<-D
|
31
|
+
TODO: Long description
|
32
|
+
D
|
33
|
+
method_option 'provisioners', type: :array, banner: 'A list of vagrant provisiners to use'
|
34
|
+
method_option 'shell-paths', type: :array, banner: 'A list of paths to use if shell provisioning is selected'
|
35
|
+
method_option 'ssh-username', type: :string, banner: 'SSH username'
|
36
|
+
method_option 'ssh-private-key-path', type: :string, banner: 'Path to SSH private key'
|
37
|
+
def init
|
38
|
+
require 'catfish/cli/init'
|
39
|
+
Init.new(options.dup, self).run
|
40
|
+
end
|
41
|
+
|
42
|
+
desc 'resolve [OPTIONS]', 'Resolves the servers listed in Catfishfile to .lock'
|
43
|
+
def resolve
|
44
|
+
require 'catfish/cli/resolve'
|
45
|
+
Resolve.new(options.dup, self).run
|
46
|
+
end
|
47
|
+
|
48
|
+
desc 'provision [OPTIONS]', 'Provision to the servers specified in Catfishfile.lock'
|
49
|
+
method_option 'provider', type: :string, default: 'managed', banner: 'Vagrant provider to use.'
|
50
|
+
method_option 'parallel', type: :boolean, default: 'false', banner: 'Run provisioning in parallel'
|
51
|
+
def provision
|
52
|
+
invoke :resolve
|
53
|
+
require 'catfish/cli/provision'
|
54
|
+
Provision.new(options.dup).run
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/lib/catfish/dsl.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
module Catfish
|
2
|
+
class Dsl
|
3
|
+
def self.evaluate
|
4
|
+
builder = new
|
5
|
+
builder.eval_catfishfile
|
6
|
+
end
|
7
|
+
|
8
|
+
attr_accessor :servers
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@servers = []
|
12
|
+
end
|
13
|
+
|
14
|
+
def eval_catfishfile
|
15
|
+
catfishfile = 'Catfishfile'
|
16
|
+
contents = File.read(catfishfile).strip
|
17
|
+
instance_eval(contents, catfishfile.to_s, 1)
|
18
|
+
end
|
19
|
+
|
20
|
+
def server(name, *_args)
|
21
|
+
servers << name
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- mode: ruby -*-
|
2
|
+
# vi: set ft=ruby :
|
3
|
+
|
4
|
+
Vagrant.configure("2") do |config|
|
5
|
+
|
6
|
+
config.vm.box = "tknerr/managed-server-dummy"
|
7
|
+
<% config[:provisioners].each do |provisioner| -%>
|
8
|
+
<% if provisioner == 'shell' -%>
|
9
|
+
<% config[:shell_paths].each do |path| -%>
|
10
|
+
config.vm.provision 'shell', path: '<%= path %>'
|
11
|
+
<% end -%>
|
12
|
+
<% end -%>
|
13
|
+
<% end -%>
|
14
|
+
|
15
|
+
instances = File.readlines('Catfishfile.lock').map(&:chomp)
|
16
|
+
instances.each do |instance|
|
17
|
+
next if instance.start_with? '#'
|
18
|
+
config.vm.define "#{instance}" do |box|
|
19
|
+
box.vm.provider :managed do |managed, override|
|
20
|
+
managed.server = instance
|
21
|
+
override.ssh.username = '<%= config[:ssh_username] %>'
|
22
|
+
override.ssh.private_key_path = '<%= config[:ssh_private_key_path] %>'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/catfish.rb
ADDED
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: catfish
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Christopher Baldauf
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubocop
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.27'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.27'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: thor
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.19.1
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.19.1
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- cbaldauf@cimpress.com
|
72
|
+
executables:
|
73
|
+
- catfish
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- .gitignore
|
78
|
+
- .rubocop.yml
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- bin/catfish
|
84
|
+
- catfish.gemspec
|
85
|
+
- lib/catfish.rb
|
86
|
+
- lib/catfish/cli.rb
|
87
|
+
- lib/catfish/cli/init.rb
|
88
|
+
- lib/catfish/cli/provision.rb
|
89
|
+
- lib/catfish/cli/resolve.rb
|
90
|
+
- lib/catfish/dsl.rb
|
91
|
+
- lib/catfish/templates/Catfishfile.tt
|
92
|
+
- lib/catfish/templates/Vagrantfile.tt
|
93
|
+
- lib/catfish/version.rb
|
94
|
+
homepage: https://github.com/chrisbaldauf/catfish
|
95
|
+
licenses:
|
96
|
+
- Apache 2
|
97
|
+
metadata: {}
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
- bin
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - '>='
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - '>='
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
requirements: []
|
114
|
+
rubyforge_project:
|
115
|
+
rubygems_version: 2.0.14
|
116
|
+
signing_key:
|
117
|
+
specification_version: 4
|
118
|
+
summary: Command line tool and set of templates that makes using vagrant-managed-servers
|
119
|
+
easy across platforms.
|
120
|
+
test_files: []
|