examine 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b2a1d5ed29dd05eb35da28ce3e86fa677d793e2e5d6c4bd5aefcf83aad061ee4
4
+ data.tar.gz: 1505a21f5bc90e47a5b32f52c3ca212254c519cfa3369e3562607646d8ab09e4
5
+ SHA512:
6
+ metadata.gz: 871169220ce9b4e092cc340da5e91d3593b2efa5cf9a23b51ad412f0c5e502969fadd9183ff37b8473c8fe694f9824be09cc5ab47ec33831de1f2dcc314c3fab
7
+ data.tar.gz: ec29a18745998923877749760080805ebf000049dbec1df08e1003df8f6160aaa088c9c77acf5f2791150dd9fa0b8048d67538f4b0680941ab16950385af95b2
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.gitlab-ci.yml ADDED
@@ -0,0 +1,36 @@
1
+ services:
2
+ - docker:stable-dind
3
+
4
+ stages:
5
+ - build
6
+ - test
7
+
8
+ include:
9
+ - template: Container-Scanning.gitlab-ci.yml
10
+
11
+ build:
12
+ image: docker:stable
13
+ stage: build
14
+ variables:
15
+ IMAGE: $CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG:$CI_COMMIT_SHA
16
+ script:
17
+ - docker info
18
+ - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
19
+ - docker build -t $IMAGE .
20
+ - docker push $IMAGE
21
+
22
+ rspec:
23
+ image:
24
+ name: $CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG:$CI_COMMIT_SHA
25
+ entrypoint: [""]
26
+ stage: test
27
+ script:
28
+ - bundle exec rspec
29
+
30
+ examine:
31
+ image:
32
+ name: $CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG:$CI_COMMIT_SHA
33
+ entrypoint: [""]
34
+ stage: test
35
+ script:
36
+ - bundle exec ./examine clair scan mokhan/minbox:latest
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/Dockerfile ADDED
@@ -0,0 +1,8 @@
1
+ FROM docker:stable
2
+ RUN apk add ruby git
3
+ RUN gem install bundler -v '~> 2.0' --no-document
4
+ RUN mkdir -p /examine
5
+ WORKDIR /examine
6
+ COPY . .
7
+ RUN bundle install --jobs "$(nproc)" --quiet
8
+ ENTRYPOINT ["bundle", "exec", "./exe/examine"]
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in examine.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,37 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ examine (0.1.0)
5
+ thor (~> 0.20)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.3)
11
+ rake (10.5.0)
12
+ rspec (3.8.0)
13
+ rspec-core (~> 3.8.0)
14
+ rspec-expectations (~> 3.8.0)
15
+ rspec-mocks (~> 3.8.0)
16
+ rspec-core (3.8.2)
17
+ rspec-support (~> 3.8.0)
18
+ rspec-expectations (3.8.4)
19
+ diff-lcs (>= 1.2.0, < 2.0)
20
+ rspec-support (~> 3.8.0)
21
+ rspec-mocks (3.8.1)
22
+ diff-lcs (>= 1.2.0, < 2.0)
23
+ rspec-support (~> 3.8.0)
24
+ rspec-support (3.8.2)
25
+ thor (0.20.3)
26
+
27
+ PLATFORMS
28
+ ruby
29
+
30
+ DEPENDENCIES
31
+ bundler (~> 2.0)
32
+ examine!
33
+ rake (~> 10.0)
34
+ rspec (~> 3.0)
35
+
36
+ BUNDLED WITH
37
+ 2.0.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 mo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Examine
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/examine`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'examine'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install examine
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/examine.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "examine"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/examine.gemspec ADDED
@@ -0,0 +1,30 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "examine/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "examine"
8
+ spec.version = Examine::VERSION
9
+ spec.authors = ["mo"]
10
+ spec.email = ["mo@mokhan.ca"]
11
+
12
+ spec.summary = %q{Examine your software.}
13
+ spec.description = %q{Examine your software.}
14
+ spec.homepage = "https://www.mokhan.ca/"
15
+ spec.license = "MIT"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_dependency "thor", "~> 0.20"
27
+ spec.add_development_dependency "bundler", "~> 2.0"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "rspec", "~> 3.0"
30
+ end
data/exe/examine ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "examine"
4
+
5
+ Examine::CLI::Application.start(ARGV)
@@ -0,0 +1,3 @@
1
+ module Examine
2
+ VERSION = "0.1.0"
3
+ end
data/lib/examine.rb ADDED
@@ -0,0 +1,64 @@
1
+ require "examine/version"
2
+
3
+ require 'socket'
4
+ require 'thor'
5
+
6
+ module Examine
7
+ class Error < StandardError; end
8
+
9
+ module CLI
10
+ class Clair < Thor
11
+
12
+ method_option :clair_url, desc: 'clair url', default: 'http://localhost:6060', type: :string
13
+ desc 'start', 'start a clair server'
14
+ def start
15
+ db_pid = spawn 'docker run -d --name clair-db arminc/clair-db:latest'
16
+ command = 'docker ps --filter="name=clair-db" --filter="status=running" --filter="expose=5432/tcp" | grep -v CONT'
17
+ print '.' until system(command)
18
+ puts "clair-db started. (PID: #{db_pid})"
19
+
20
+ clair_pid = spawn 'docker run --restart=unless-stopped -p 6060:6060 --link clair-db:postgres -d --name clair arminc/clair-local-scan:latest'
21
+
22
+ command = 'docker ps --filter="name=clair" --filter="status=running" --filter="expose=6060/tcp" | grep -v CONT'
23
+ print '.' until system(command)
24
+ print '.' until system("curl -s #{options[:clair_url]}/v1/namespaces > /dev/null")
25
+ puts "clair-local-scan started. (PID: #{clair_pid})"
26
+ end
27
+
28
+ method_option :ip, desc: 'ip address', default: nil, type: :string
29
+ method_option :clair_url, desc: 'clair url', default: 'http://localhost:6060', type: :string
30
+ desc 'scan <image>', 'scan a specific image'
31
+ def scan(image)
32
+ start unless started?
33
+
34
+ ip = options[:ip] || Socket.ip_address_list[1].ip_address
35
+ system "docker pull #{image}"
36
+ system "clair-scanner -c #{options[:clair_url]} --ip #{ip} #{image}"
37
+ end
38
+
39
+ desc 'status', 'status of clair server'
40
+ def status
41
+ system "docker ps -a | grep clair"
42
+ end
43
+
44
+ desc 'stop', 'stop all clair servers'
45
+ def stop
46
+ system "docker stop $(docker ps | grep -v CONT | grep clair- | awk '{ print $1 }')"
47
+ system "docker system prune -f"
48
+ end
49
+
50
+ private
51
+
52
+ def started?
53
+ status
54
+ end
55
+ end
56
+
57
+ class Application < Thor
58
+ package_name 'examine'
59
+
60
+ desc 'clair', 'manage clair'
61
+ subcommand :clair, Examine::CLI::Clair
62
+ end
63
+ end
64
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: examine
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - mo
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-07-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.20'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.20'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: Examine your software.
70
+ email:
71
+ - mo@mokhan.ca
72
+ executables:
73
+ - examine
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".gitlab-ci.yml"
79
+ - ".rspec"
80
+ - Dockerfile
81
+ - Gemfile
82
+ - Gemfile.lock
83
+ - LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - bin/console
87
+ - bin/setup
88
+ - examine.gemspec
89
+ - exe/examine
90
+ - lib/examine.rb
91
+ - lib/examine/version.rb
92
+ homepage: https://www.mokhan.ca/
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubygems_version: 3.0.3
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Examine your software.
115
+ test_files: []