checkit 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +41 -0
- data/Rakefile +1 -0
- data/bin/checkit +8 -0
- data/checkit.gemspec +22 -0
- data/lib/checkit.rb +16 -0
- data/lib/checkit/config_files.rb +38 -0
- data/lib/checkit/core.rb +61 -0
- data/lib/checkit/services.rb +90 -0
- data/lib/checkit/styled_io.rb +28 -0
- data/lib/checkit/version.rb +3 -0
- metadata +94 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Maximilian Schulz
|
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,41 @@
|
|
1
|
+
# Checkit
|
2
|
+
|
3
|
+
This gem provides a small executable which can be run from every ruby project in order to help new developers to check if they are ready to run the project. It checks for various dependencies:
|
4
|
+
|
5
|
+
* Bundled gems
|
6
|
+
* Config files
|
7
|
+
* Servers installed and running
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'checkit'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install checkit
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Change to your project directory and run ```checkit```, read the data and if something red is printed get some help ;)
|
26
|
+
|
27
|
+
## ToDo
|
28
|
+
|
29
|
+
* Check if foreman is installed and tell user to use it for running dependencies
|
30
|
+
* Check if a test suite is present and can be run
|
31
|
+
* Cleanup the existing code
|
32
|
+
* Create a central service repository whcih resolves all dependencies
|
33
|
+
* Check environments
|
34
|
+
|
35
|
+
## Contributing
|
36
|
+
|
37
|
+
1. Fork it
|
38
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
39
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
40
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
41
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/checkit
ADDED
data/checkit.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'checkit/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = 'checkit'
|
8
|
+
gem.version = CheckIt::VERSION
|
9
|
+
gem.authors = ['Maximilian Schulz']
|
10
|
+
gem.email = ['m.schulz@kulturfluss.de']
|
11
|
+
gem.description = %q{A little tool to check the your ruby project dependencies}
|
12
|
+
gem.summary = %q{This gem provides an executable which checks common project dependencies. It checks if the bundle is installed, all servers are running and if your config files are in place.}
|
13
|
+
gem.homepage = 'https://github.com/railslove/checkit'
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ['lib']
|
19
|
+
|
20
|
+
gem.add_dependency 'bundler'
|
21
|
+
gem.add_dependency 'ansi'
|
22
|
+
end
|
data/lib/checkit.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# Disable all warnings
|
2
|
+
$VERBOSE = nil
|
3
|
+
|
4
|
+
# Create namespace
|
5
|
+
CheckIt = Module.new
|
6
|
+
|
7
|
+
# Utility classes
|
8
|
+
require "checkit/version"
|
9
|
+
require "checkit/styled_io"
|
10
|
+
|
11
|
+
# Checks
|
12
|
+
require "checkit/config_files"
|
13
|
+
require "checkit/services"
|
14
|
+
|
15
|
+
# Core application
|
16
|
+
require "checkit/core"
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module CheckIt
|
2
|
+
class ConfigFiles
|
3
|
+
|
4
|
+
attr_accessor :io
|
5
|
+
|
6
|
+
def initialize(io)
|
7
|
+
self.io = io
|
8
|
+
end
|
9
|
+
|
10
|
+
def perform_checks
|
11
|
+
if File.directory?('config')
|
12
|
+
check_unmatched_example_files
|
13
|
+
else
|
14
|
+
io.puts colorize(:help, 'No config directory')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def check_unmatched_example_files
|
21
|
+
Dir['config/*sample*', 'config/*example*'].each do |example_file|
|
22
|
+
cleaned_file_name = example_file.gsub(/\.sample|\.example/, '')
|
23
|
+
io.print " #{cleaned_file_name}: "
|
24
|
+
output = if File.exists?(cleaned_file_name)
|
25
|
+
io.colorize(:notice, 'Ok')
|
26
|
+
else
|
27
|
+
if %w(.json .yml).include?(File.extname(cleaned_file_name))
|
28
|
+
io.colorize(:alert, 'Missing')
|
29
|
+
else
|
30
|
+
io.colorize(:warning, 'Probably not a config file or a duplicate')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
io.puts output
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
data/lib/checkit/core.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
|
3
|
+
module CheckIt
|
4
|
+
class Core
|
5
|
+
|
6
|
+
attr_accessor :io
|
7
|
+
|
8
|
+
def self.run(io = STDOUT)
|
9
|
+
self.new(io).perform_checks
|
10
|
+
io.puts
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(io)
|
14
|
+
self.io = StyledIO.new(io)
|
15
|
+
end
|
16
|
+
|
17
|
+
def perform_checks
|
18
|
+
check_bundle
|
19
|
+
check_dependencies
|
20
|
+
# TODO: check if foreman is installed
|
21
|
+
check_config_files
|
22
|
+
# TODO: notify about test suites
|
23
|
+
end
|
24
|
+
|
25
|
+
protected
|
26
|
+
|
27
|
+
def check_bundle
|
28
|
+
io.print_header('Bundled rubygems')
|
29
|
+
simple_check('bundle check', 'Bundle', %(Run 'bundle install'))
|
30
|
+
end
|
31
|
+
|
32
|
+
def check_dependencies
|
33
|
+
io.print_header('Server dependencies')
|
34
|
+
Services.new(io).perform_checks
|
35
|
+
end
|
36
|
+
|
37
|
+
def check_config_files
|
38
|
+
io.print_header('Configuration files')
|
39
|
+
ConfigFiles.new(io).perform_checks
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def simple_check(cmd, message, hint = nil)
|
45
|
+
%x[#{cmd}]
|
46
|
+
io.print " * #{message}: "
|
47
|
+
if $?.exitstatus == 1
|
48
|
+
io.print io.colorize(:alert, 'failed')
|
49
|
+
if hint
|
50
|
+
io.puts
|
51
|
+
io.print io.colorize(:help, " Hint: #{hint}")
|
52
|
+
end
|
53
|
+
else
|
54
|
+
io.print io.colorize(:notice, 'OK')
|
55
|
+
end
|
56
|
+
io.puts
|
57
|
+
$?.exitstatus == 0
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
module CheckIt
|
2
|
+
class Services
|
3
|
+
|
4
|
+
attr_accessor :io
|
5
|
+
|
6
|
+
DEPENDENCY_STATES = [:ok, :not_running, :not_installed]
|
7
|
+
|
8
|
+
EXTERNAL_DEPENDENCIES = {
|
9
|
+
'pg' => ['postgres'],
|
10
|
+
'mysql' => ['mysqld'],
|
11
|
+
'mysql2' => ['mysqld'],
|
12
|
+
'tire' => ['elasticsearch'],
|
13
|
+
'neography' => ['neo4j'],
|
14
|
+
'redis' => ['redis-server'],
|
15
|
+
'amqp' => ['rabbitmq-server'],
|
16
|
+
'sqlite3' => ['sqlite3'],
|
17
|
+
'carrierwave' => ['convert']
|
18
|
+
}
|
19
|
+
|
20
|
+
def initialize(io)
|
21
|
+
self.io = io
|
22
|
+
end
|
23
|
+
|
24
|
+
def perform_checks
|
25
|
+
dependency_states.each do |name, command_states|
|
26
|
+
io.puts " * Gem '#{name}' will need:"
|
27
|
+
command_states.each do |cmd, state|
|
28
|
+
io.puts " #{cmd}: #{human_state(state)}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def command_running?(cmd)
|
36
|
+
%x[ps acux | grep '#{grepable_command(cmd.clone)}'].class
|
37
|
+
$?.exitstatus == 0
|
38
|
+
end
|
39
|
+
|
40
|
+
def command_installed?(cmd)
|
41
|
+
%x[which #{cmd}]
|
42
|
+
$?.exitstatus == 0
|
43
|
+
end
|
44
|
+
|
45
|
+
def dependency_states
|
46
|
+
@dependency_states ||= begin
|
47
|
+
data = {}
|
48
|
+
EXTERNAL_DEPENDENCIES.each do |name, commands|
|
49
|
+
if bundled_gems.include?(name)
|
50
|
+
data[name] = gem_dependency_state(name, commands)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
data
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def gem_dependency_state(name, commands)
|
58
|
+
commands.reduce({}) { |memo, cmd| memo[cmd] = command_state(cmd); memo }
|
59
|
+
end
|
60
|
+
|
61
|
+
def command_state(cmd)
|
62
|
+
if command_installed?(cmd)
|
63
|
+
command_running?(cmd) ? :ok : :not_running
|
64
|
+
else
|
65
|
+
:not_installed
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def grepable_command(cmd)
|
70
|
+
cmd.insert(0, '[').insert(2, ']')
|
71
|
+
end
|
72
|
+
|
73
|
+
def bundled_gems
|
74
|
+
@bundled_gems = Bundler.definition.dependencies.map { |dep| dep.name }
|
75
|
+
end
|
76
|
+
|
77
|
+
def human_state(state)
|
78
|
+
case state
|
79
|
+
when :not_installed
|
80
|
+
io.colorize(:alert, 'not installed')
|
81
|
+
io.colorize(:help, " Hint: The command might not be in the PATH")
|
82
|
+
when :not_running
|
83
|
+
io.colorize(:alert, 'not running')
|
84
|
+
when :ok
|
85
|
+
io.colorize(:notice, 'OK')
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'ansi'
|
2
|
+
require 'delegate'
|
3
|
+
|
4
|
+
module CheckIt
|
5
|
+
class StyledIO < ::SimpleDelegator
|
6
|
+
def colorize(type, text)
|
7
|
+
color = case type
|
8
|
+
when :alert, :error
|
9
|
+
:red
|
10
|
+
when :notice, :ok
|
11
|
+
:green
|
12
|
+
when :help, :warning
|
13
|
+
:yellow
|
14
|
+
else
|
15
|
+
:white
|
16
|
+
end
|
17
|
+
ANSI.color(color) { text }
|
18
|
+
end
|
19
|
+
|
20
|
+
def print_header(txt)
|
21
|
+
self.puts
|
22
|
+
self.puts '+' + '-' * 78 + '+'
|
23
|
+
self.puts '| ' + txt.ljust(76) + ' |'
|
24
|
+
self.puts '+' + '-' * 78 + '+'
|
25
|
+
self.puts
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: checkit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Maximilian Schulz
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-06-24 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: ansi
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: A little tool to check the your ruby project dependencies
|
47
|
+
email:
|
48
|
+
- m.schulz@kulturfluss.de
|
49
|
+
executables:
|
50
|
+
- checkit
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- Gemfile
|
56
|
+
- LICENSE.txt
|
57
|
+
- README.md
|
58
|
+
- Rakefile
|
59
|
+
- bin/checkit
|
60
|
+
- checkit.gemspec
|
61
|
+
- lib/checkit.rb
|
62
|
+
- lib/checkit/config_files.rb
|
63
|
+
- lib/checkit/core.rb
|
64
|
+
- lib/checkit/services.rb
|
65
|
+
- lib/checkit/styled_io.rb
|
66
|
+
- lib/checkit/version.rb
|
67
|
+
homepage: https://github.com/railslove/checkit
|
68
|
+
licenses: []
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 1.8.24
|
88
|
+
signing_key:
|
89
|
+
specification_version: 3
|
90
|
+
summary: This gem provides an executable which checks common project dependencies.
|
91
|
+
It checks if the bundle is installed, all servers are running and if your config
|
92
|
+
files are in place.
|
93
|
+
test_files: []
|
94
|
+
has_rdoc:
|