Commit cd73a57
Changed files (4)
exe/examine
@@ -1,3 +1,5 @@
#!/usr/bin/env ruby
require "examine"
+
+Examine::CLI::Application.start(ARGV)
lib/examine.rb
@@ -1,6 +1,41 @@
require "examine/version"
+require 'thor'
+
module Examine
class Error < StandardError; end
- # Your code goes here...
+
+ module CLI
+ class Clair < Thor
+ desc 'start', 'start a clair server'
+ def start
+ db_pid = spawn 'docker run -d --name clair-db arminc/clair-db:latest'
+ puts "clair-db started. (PID: #{db_pid})"
+
+ command = 'docker ps --filter="name=clair-db" --filter="status=running" --filter="expose=5432/tcp" | grep -v CONT'
+ print '.' until system(command)
+
+ clair_pid = spawn 'docker run --restart=unless-stopped -p 6060 --link clair-db:postgres -d --name clair arminc/clair-local-scan:latest'
+ puts "clair-local-scan started. (PID: #{clair_pid})"
+ end
+
+ desc 'status', 'status of clair server'
+ def status
+ system "docker ps -a | grep clair"
+ end
+
+ desc 'stop', 'stop all clair servers'
+ def stop
+ system "docker stop $(docker ps | grep -v CONT | grep clair- | awk '{ print $1 }')"
+ system "docker system prune -f"
+ end
+ end
+
+ class Application < Thor
+ package_name 'examine'
+
+ desc 'clair', 'manage clair'
+ subcommand :clair, Examine::CLI::Clair
+ end
+ end
end
examine.gemspec
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
+ spec.add_dependency "thor", "~> 0.20"
spec.add_development_dependency "bundler", "~> 2.0"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "rspec", "~> 3.0"
Gemfile.lock
@@ -2,6 +2,7 @@ PATH
remote: .
specs:
examine (0.1.0)
+ thor (~> 0.20)
GEM
remote: https://rubygems.org/
@@ -21,6 +22,7 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-support (3.8.2)
+ thor (0.20.3)
PLATFORMS
ruby