summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2020-04-14 18:41:16 -0600
committermo khan <mo.khan@gmail.com>2020-04-14 18:41:16 -0600
commit1b2b95d957860dd25060a2175610e01df103c7b2 (patch)
treedd69f78be8e56b7921852022074cdc012f4e545a
parent7ca5e094766b70fe8a8783c0c2f33fdeba46d2c5 (diff)
Build a bootable docker image
-rw-r--r--Dockerfile4
-rw-r--r--Gemfile.lock9
-rwxr-xr-xbin/docker-build13
-rwxr-xr-xbin/docker-shell12
-rw-r--r--config/.gemrc4
-rw-r--r--config/install.sh24
-rw-r--r--lib/spandx/gitlab.rb6
-rw-r--r--spandx-gitlab.gemspec4
-rw-r--r--spec/integration/ruby/bundler_spec.rb16
-rw-r--r--spec/spec_helper.rb3
-rw-r--r--spec/support/integration_test_helper.rb6
-rw-r--r--spec/support/matchers.rb2
12 files changed, 85 insertions, 18 deletions
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..56d367c
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,4 @@
+FROM debian:stable-slim
+WORKDIR /root
+COPY config /root
+RUN bash /root/install.sh
diff --git a/Gemfile.lock b/Gemfile.lock
index 3074a65..9a18938 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -13,9 +13,10 @@ GEM
bundler-audit (0.6.1)
bundler (>= 1.2.0, < 3)
thor (~> 0.18)
- byebug (11.1.1)
diff-lcs (1.3)
jaro_winkler (1.5.4)
+ json-schema (2.8.1)
+ addressable (>= 2.4)
mini_portile2 (2.4.0)
net-hippie (0.3.2)
nokogiri (1.10.9)
@@ -51,21 +52,23 @@ GEM
rubocop-rspec (1.38.1)
rubocop (>= 0.68.1)
ruby-progressbar (1.10.1)
- spandx (0.11.0)
+ spandx (0.12.0)
addressable (~> 2.7)
bundler (>= 1.16, < 3.0.0)
net-hippie (~> 0.3)
nokogiri (~> 1.10)
thor
+ zeitwerk (~> 2.3)
thor (0.20.3)
unicode-display_width (1.7.0)
+ zeitwerk (2.3.0)
PLATFORMS
ruby
DEPENDENCIES
bundler-audit (~> 0.6)
- byebug (~> 11.1)
+ json-schema (~> 2.8)
rake (~> 13.0)
rspec (~> 3.0)
rubocop (~> 0.52)
diff --git a/bin/docker-build b/bin/docker-build
new file mode 100755
index 0000000..39a9160
--- /dev/null
+++ b/bin/docker-build
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+set -e
+
+cd "$(dirname "$0")/.."
+
+if command -v docker; then
+ IMAGE_NAME=${IMAGE_NAME:-$(basename "$PWD"):latest}
+ docker build -t "$IMAGE_NAME" .
+else
+ echo "Install docker: https://docs.docker.com/engine/installation/"
+ exit 1
+fi
diff --git a/bin/docker-shell b/bin/docker-shell
new file mode 100755
index 0000000..e577918
--- /dev/null
+++ b/bin/docker-shell
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+set -e
+
+cd "$(dirname "$0")/.."
+
+IMAGE_NAME=${IMAGE_NAME:-$(basename "$PWD"):latest}
+
+docker run --rm -it \
+ --entrypoint='' \
+ --volume "$PWD":/opt/spandx-gitlab \
+ "$IMAGE_NAME" /bin/bash -l
diff --git a/config/.gemrc b/config/.gemrc
new file mode 100644
index 0000000..ff5fcc7
--- /dev/null
+++ b/config/.gemrc
@@ -0,0 +1,4 @@
+:verbose: true
+:sources:
+- https://rubygems.org/
+gem: --no-document
diff --git a/config/install.sh b/config/install.sh
new file mode 100644
index 0000000..88f56aa
--- /dev/null
+++ b/config/install.sh
@@ -0,0 +1,24 @@
+#!/bin/bash
+set -euxo pipefail
+
+export DEBIAN_FRONTEND=noninteractive
+
+apt-get clean
+apt-get update -q
+apt-get install -y wget apt-utils libedit2 git
+apt-get install -y autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm6 libgdbm-dev
+
+cd /root
+wget https://cache.ruby-lang.org/pub/ruby/2.7/ruby-2.7.1.tar.gz
+tar -xf ruby-2.7.1.tar.gz
+cd ruby-2.7.1
+
+./configure
+make -j"$(nproc)"
+make install
+cd /root
+rm -fr ruby-2.7.1*
+
+gem update --system
+gem install bundler -v '~> 2.0'
+echo "Done"
diff --git a/lib/spandx/gitlab.rb b/lib/spandx/gitlab.rb
index f0e97ae..842aa84 100644
--- a/lib/spandx/gitlab.rb
+++ b/lib/spandx/gitlab.rb
@@ -6,5 +6,11 @@ require 'spandx/gitlab/version'
module Spandx
module Gitlab
class Error < StandardError; end
+
+ def self.root
+ Pathname.new(File.dirname(__FILE__)).join('../..')
+ end
end
end
+
+puts "YAHOO"
diff --git a/spandx-gitlab.gemspec b/spandx-gitlab.gemspec
index 5bbd3c1..27556a3 100644
--- a/spandx-gitlab.gemspec
+++ b/spandx-gitlab.gemspec
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
spec.metadata['changelog_uri'] = 'https://github.com/mokhan/spandx/blob/master/CHANGELOG.md'
spec.files = Dir.chdir(File.expand_path(__dir__)) do
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec)/}) }
+ Dir.glob('exe/*') + Dir.glob('lib/**/**/*.{rb}') + Dir.glob('*.{md,yml,json}')
end
spec.bindir = 'exe'
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
spec.add_dependency 'spandx', '~> 0.1'
spec.add_development_dependency 'bundler-audit', '~> 0.6'
- spec.add_development_dependency 'byebug', '~> 11.1'
+ spec.add_development_dependency 'json-schema', '~> 2.8'
spec.add_development_dependency 'rake', '~> 13.0'
spec.add_development_dependency 'rspec', '~> 3.0'
spec.add_development_dependency 'rubocop', '~> 0.52'
diff --git a/spec/integration/ruby/bundler_spec.rb b/spec/integration/ruby/bundler_spec.rb
index 1f87275..55f3764 100644
--- a/spec/integration/ruby/bundler_spec.rb
+++ b/spec/integration/ruby/bundler_spec.rb
@@ -123,20 +123,20 @@ RSpec.describe 'bundler' do
expect(report).to match_schema(version: '2.0')
expect(report[:licenses]).not_to be_empty
expect(report.find('net-hippie')).to eql({
- name: 'net-hippie',
- description: 'net/http for hippies. ☮️',
- url: 'https://github.com/mokhan/net-hippie/',
- paths: ['.'],
- licenses: ['MIT']
- })
+ name: 'net-hippie',
+ description: 'net/http for hippies. ☮️',
+ url: 'https://github.com/mokhan/net-hippie/',
+ paths: ['.'],
+ licenses: ['MIT']
+ })
end
end
context 'when passing custom options to license finder' do
it 'forwards the options to license finder' do
report = runner.scan(env: {
- 'LICENSE_FINDER_CLI_OPTS' => '--debug --aggregate-paths=. ruby'
- })
+ 'LICENSE_FINDER_CLI_OPTS' => '--debug --aggregate-paths=. ruby'
+ })
expect(report).to match_schema(version: '2.0')
end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index a08aa40..3509c56 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -17,9 +17,6 @@ RSpec.configure do |config|
config.define_derived_metadata(file_path: %r{/spec/integration}) do |metadata|
metadata[:type] = :integration
end
- config.before(:suite) do
- system('./bin/docker-build') unless ENV['LM_HOME']
- end
config.after(:example, type: :integration) do
runner.cleanup
end
diff --git a/spec/support/integration_test_helper.rb b/spec/support/integration_test_helper.rb
index d1ff14a..416438e 100644
--- a/spec/support/integration_test_helper.rb
+++ b/spec/support/integration_test_helper.rb
@@ -69,7 +69,11 @@ module IntegrationTestHelper
end
def scan(env: {})
- return {} unless execute(env, './bin/docker-test', project_path)
+ command = [
+ '/usr/local/bin/ruby -I /opt/spandx-gitlab/lib /usr/local/bin/spandx scan --format=json -r spandx/gitlab -R -l /dev/stderr',
+ project_path
+ ].join(' ')
+ return {} unless execute(env, command)
report_path = "#{project_path}/gl-license-management-report.json"
return {} unless File.exist?(report_path)
diff --git a/spec/support/matchers.rb b/spec/support/matchers.rb
index 038c593..937b7cf 100644
--- a/spec/support/matchers.rb
+++ b/spec/support/matchers.rb
@@ -2,7 +2,7 @@
RSpec::Matchers.define :match_schema do |version: '2.0'|
def schema_for(version)
- License::Management.root.join("spec/fixtures/schema/v#{version}.json").to_s
+ Spandx::Gitlab.root.join("spec/fixtures/schema/v#{version}.json").to_s
end
match do |actual|