mirror of
https://github.com/kdabir/has.git
synced 2024-11-10 21:26:50 +01:00
going away with the preselected groups as it is quite subjective matter. now build accepts patterns. Expose the app over web and have a shortened url long check strings.
This commit is contained in:
parent
8e3299d017
commit
2841d0f2f9
5
Gemfile
Normal file
5
Gemfile
Normal file
@ -0,0 +1,5 @@
|
||||
source 'https://rubygems.org'
|
||||
gem 'rack'
|
||||
gem 'guillotine'
|
||||
gem 'mongo'
|
||||
gem 'bson_ext'
|
29
Gemfile.lock
Normal file
29
Gemfile.lock
Normal file
@ -0,0 +1,29 @@
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
addressable (2.3.7)
|
||||
bson (1.12.0)
|
||||
bson_ext (1.12.0)
|
||||
bson (~> 1.12.0)
|
||||
guillotine (1.4.2)
|
||||
addressable (~> 2.3.0)
|
||||
sinatra (~> 1.4.0)
|
||||
mongo (1.12.0)
|
||||
bson (= 1.12.0)
|
||||
rack (1.5.2)
|
||||
rack-protection (1.5.3)
|
||||
rack
|
||||
sinatra (1.4.5)
|
||||
rack (~> 1.4)
|
||||
rack-protection (~> 1.4)
|
||||
tilt (~> 1.3, >= 1.3.4)
|
||||
tilt (1.4.1)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
bson_ext
|
||||
guillotine
|
||||
mongo
|
||||
rack
|
46
build.rb
46
build.rb
@ -1,31 +1,31 @@
|
||||
# encoding: utf-8
|
||||
|
||||
# Usage:
|
||||
# ruby build.rb <group1> <group2>... | sh
|
||||
# ruby build.rb <pattern1> <pattern2>... | bash
|
||||
# valid patterns:
|
||||
# `dir_name/command_name`
|
||||
# `dir_name/*`
|
||||
# `*/command_name`
|
||||
# `*/*`
|
||||
#
|
||||
# dir/command name can be found in `lib/`
|
||||
# do not include sh in command name
|
||||
# pattern can contain commas to include multiple patterns
|
||||
|
||||
|
||||
groups = {
|
||||
:all => "*/*",
|
||||
:core => "core/*",
|
||||
:shell => "shell/*",
|
||||
:java_dev => ["core/java", "java/*"],
|
||||
:clojure_dev => ["core/java", "clojure/*"],
|
||||
:groovy_dev => ["core/java","java/gradle", "groovy/*"],
|
||||
:scala_dev => ["core/java", "scala/*"],
|
||||
:ruby_dev => ["core/ruby", "ruby/*"],
|
||||
:frontend_dev => ["core/*", "frontend/*"],
|
||||
:db => ["db/*"]
|
||||
}
|
||||
|
||||
tap_it = Proc.new { |it| $stderr.puts "tapped - #{it}" }
|
||||
# debugging tip:
|
||||
# use `.tap(&tap_it)` at any point in chain to print the values
|
||||
# tap_it writes to `stderr`
|
||||
# `ruby build.rb > /dev/null` to exclude the stdout of the script
|
||||
|
||||
content =
|
||||
(ARGV.empty? ? ["core"] : ARGV) # groups_to_load
|
||||
.collect { |group| groups[group.to_sym] }.flatten.compact # patterns
|
||||
.collect { |pattern| Dir["lib/#{pattern}.sh"] }.flatten.uniq # sh files
|
||||
.sort { |x, y| File.basename(x) <=> File.basename(y) } # sort, remove if you dont want
|
||||
.collect { |file| File.read(file) }.join("\n") # concat
|
||||
def build *args
|
||||
tap_it = Proc.new { |it| $stderr.puts "tapped - #{it}" }
|
||||
content = args.collect { |it| it.split(',')}.flatten # comma seperated or multiple args
|
||||
.select { |pattern| File.fnmatch('lib/*/*.sh', "lib/#{pattern}.sh", File::FNM_PATHNAME)} # can potentially do ..
|
||||
.collect { |pattern| Dir["lib/#{pattern}.sh"] }.flatten.uniq # get all files
|
||||
.sort { |x, y| File.basename(x) <=> File.basename(y) } # sort alphabetically
|
||||
.collect { |file| File.read(file) }.join("\n") # concat
|
||||
|
||||
puts [File.read("include/setup.sh"), content, File.read("include/report.sh")].join("\n")
|
||||
[File.read("include/setup.sh"), content, File.read("include/report.sh")].join("\n")
|
||||
end
|
||||
|
||||
puts build *ARGV unless ARGV.empty?
|
||||
|
10
build.sh
10
build.sh
@ -1,10 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
rm -rf ./bin
|
||||
|
||||
for group in groovy_dev ruby_dev scala_dev java_dev db core shell clojure_dev all frontend_dev; do
|
||||
mkdir -p ./bin/$group/
|
||||
ruby build.rb $group > ./bin/$group/dq.sh
|
||||
done
|
||||
|
||||
find bin -type f -name \*.sh -exec chmod u+x {} +
|
33
config.ru
Normal file
33
config.ru
Normal file
@ -0,0 +1,33 @@
|
||||
# encoding: UTF-8
|
||||
|
||||
require './build'
|
||||
require 'mongo'
|
||||
require 'guillotine'
|
||||
|
||||
HEADERS_FOR_SHELL = {'Content-Type' => 'text/plain'}
|
||||
|
||||
## accepts only one parameter `check` with path patterns accepted by build
|
||||
map '/dq' do
|
||||
run Proc.new { |env|
|
||||
commands_to_check = Rack::Request.new(env).params[:check.to_s] || "core/*"
|
||||
[200, HEADERS_FOR_SHELL, [build(commands_to_check)]]
|
||||
}
|
||||
end
|
||||
|
||||
class Shorty < Guillotine::App
|
||||
adapter = begin
|
||||
mongo_uri = ENV['MONGOLAB_URI'] || 'mongodb://localhost:27017/dq'
|
||||
db_name = mongo_uri[%r{/([^/\?]+)(\?|$)}, 1]
|
||||
collection = Mongo::MongoClient.from_uri(mongo_uri).db(db_name).collection("shorty")
|
||||
Guillotine::MongoAdapter.new(collection)
|
||||
rescue
|
||||
Guillotine::MemoryAdapter.new
|
||||
end
|
||||
|
||||
set :service => Guillotine::Service.new(adapter, ENV['DOMAIN_RESTRICTION'])
|
||||
end
|
||||
|
||||
map '/check' do
|
||||
run Shorty
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user