gem-src-srv 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: cac6ea3bf7198076c0055fa6f6d81da31836d94e8f81ee55b61f1545d691278b
4
+ data.tar.gz: dd0573345b33a24d185f9c3d63e9372eb119d4c0a184237ec83e757f22844b8c
5
+ SHA512:
6
+ metadata.gz: efcecead3447218afdf071cfe9ab95c996ef42cd1f7111992f8b2949c973267aed547d342c0cad4ea2b482e3c73d7555fe24a04fe75a285099c16f7faffb8884
7
+ data.tar.gz: 4d3202c7c22157ae50b6491d9bce97bcc5e811a657c9130ad76886d6d09e5a6af64f5c598c5f3cc70a56bde99256c1d73306d86f882808fb321cd94848fdc8d2
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /.ruby-version
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in gem-src-srv.gemspec
6
+ gemspec
@@ -0,0 +1,22 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ gem-src-srv (0.1.1)
5
+ retryable (~> 3.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ rake (10.5.0)
11
+ retryable (3.0.0)
12
+
13
+ PLATFORMS
14
+ ruby
15
+
16
+ DEPENDENCIES
17
+ bundler (~> 1.16)
18
+ gem-src-srv!
19
+ rake (~> 10.0)
20
+
21
+ BUNDLED WITH
22
+ 1.16.1
data/LICENSE ADDED
@@ -0,0 +1,51 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Masataka Pocke Kuwabara
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 all
13
+ 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 THE
21
+ SOFTWARE.
22
+
23
+
24
+ ----
25
+
26
+
27
+ This project copies some code from https://github.com/amatsuda/gem-src
28
+ https://github.com/amatsuda/gem-src/blob/94565781c9c0941a02e1230d05f4e03b7587d187/LICENSE.txt
29
+
30
+ Copyright (c) 2012 Akira Matsuda
31
+
32
+ MIT License
33
+
34
+ Permission is hereby granted, free of charge, to any person obtaining
35
+ a copy of this software and associated documentation files (the
36
+ "Software"), to deal in the Software without restriction, including
37
+ without limitation the rights to use, copy, modify, merge, publish,
38
+ distribute, sublicense, and/or sell copies of the Software, and to
39
+ permit persons to whom the Software is furnished to do so, subject to
40
+ the following conditions:
41
+
42
+ The above copyright notice and this permission notice shall be
43
+ included in all copies or substantial portions of the Software.
44
+
45
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
46
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
47
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
48
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
49
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
50
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
51
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,49 @@
1
+ # Gem::Src::Srv
2
+
3
+ Run `git clone` after `gem install` concurrently. Inspired by [gem-src](https://github.com/amatsuda/gem-src)
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ $ gem install gem-src-srv
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ It clones a git repository after you install a gem with [ghq](https://github.com/motemen/ghq).
14
+
15
+ ```bash
16
+ $ gem install rails
17
+ $ ghq list | grep rails/rails
18
+ github.com/rails/rails
19
+ ```
20
+
21
+ Note: If you want to clone repositories with plain `git clone` command, you can send a pull-request!
22
+
23
+ ### Configuration
24
+
25
+ You can set `GEM_SRC_SRV_PORT` and `GEM_SRC_SRV_CONCURRENCY` environment variables.
26
+
27
+ See [lib/gem/src/srv/configuration.rb](https://github.com/pocke/gem-src-srv/blob/master/lib/gem/src/srv/configuration.rb).
28
+
29
+ ## Design
30
+
31
+ gem-src is good, but it clones a repository synchronously. So it makes `gem install` slow.
32
+
33
+ gem-src-srv clones a repository concurrently. So it does not block `gem install`, it's faster!
34
+
35
+ ### How concurrently?
36
+
37
+ gem-src-srv works on Client-Server model.
38
+
39
+ ![img_20180225_124045652](https://user-images.githubusercontent.com/4361134/36637896-47fa1daa-1a29-11e8-828a-c37aaa36f6ac.jpg)
40
+
41
+ ## Development
42
+
43
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
44
+
45
+ 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).
46
+
47
+ ## Contributing
48
+
49
+ Bug reports and pull requests are welcome on GitHub at https://github.com/pocke/gem-src-srv.
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "gem/src/srv"
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__)
@@ -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
@@ -0,0 +1,5 @@
1
+ #!ruby
2
+
3
+ require 'gem/src/srv'
4
+
5
+ Gem::Src::Srv.start
@@ -0,0 +1,26 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "gem/src/srv/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "gem-src-srv"
7
+ spec.version = Gem::Src::Srv::VERSION
8
+ spec.authors = ["Masataka Pocke Kuwabara"]
9
+ spec.email = ["kuwabara@pocke.me"]
10
+
11
+ spec.summary = %q{Run `git clone` after `gem install` concurrently.}
12
+ spec.description = %q{Run `git clone` after `gem install` concurrently.}
13
+ spec.homepage = "https://github.com/pocke/gem-src-srv"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
+ f.match(%r{^(test|spec|features)/})
17
+ end
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.16"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+
25
+ spec.add_runtime_dependency "retryable", "~> 3.0"
26
+ end
@@ -0,0 +1,24 @@
1
+ require 'webrick'
2
+ require 'net/http'
3
+ require 'open-uri'
4
+ require 'json'
5
+ require 'etc'
6
+
7
+ module Gem
8
+ module Src
9
+ module Srv
10
+ def self.start
11
+ queue = Queue.new
12
+ Worker.start(queue)
13
+ Server.start(queue)
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ require_relative "srv/version"
20
+ require_relative "srv/configuration"
21
+ require_relative "srv/irregular_repositories"
22
+ require_relative "srv/fetcher"
23
+ require_relative "srv/server"
24
+ require_relative "srv/worker"
@@ -0,0 +1,14 @@
1
+ module Gem
2
+ module Src
3
+ module Srv
4
+ module Configuration
5
+ def self.env(key)
6
+ ENV["GEM_SRC_SRV_#{key}"]
7
+ end
8
+
9
+ PORT = env('PORT')&.to_i || 64322
10
+ CONCURRENCY = env('CONCURRENCY')&.to_i || Etc.nprocessors
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,86 @@
1
+ module Gem::Src::Srv
2
+ class Fetcher
3
+ def self.tested_repositories
4
+ @tested_repositories ||= []
5
+ end
6
+
7
+ def tested_repositories
8
+ self.class.tested_repositories
9
+ end
10
+
11
+ def initialize(spec)
12
+ @spec = spec
13
+ end
14
+
15
+ def fetch
16
+ if IRREGULAR_REPOSITORIES.key? spec.name
17
+ return git_clone IRREGULAR_REPOSITORIES[spec.name]
18
+ end
19
+
20
+ git_clone(spec.homepage) ||
21
+ git_clone(github_url(spec.homepage)) ||
22
+ git_clone(source_code_uri) ||
23
+ git_clone(homepage_uri) ||
24
+ git_clone(github_url(homepage_uri)) ||
25
+ git_clone(github_organization_uri(spec.name))
26
+ end
27
+
28
+ private
29
+
30
+ attr_reader :spec
31
+
32
+ def git_clone(repository)
33
+ return if repository.nil? || repository.empty?
34
+ return if tested_repositories.include? repository
35
+ tested_repositories << repository
36
+ return if github?(repository) && !github_page_exists?(repository)
37
+
38
+ system 'ghq', 'get', repository
39
+ end
40
+
41
+ def github?(url)
42
+ URI.parse(url).host == 'github.com'
43
+ end
44
+
45
+ def github_page_exists?(url)
46
+ Net::HTTP.new('github.com', 443).tap {|h| h.use_ssl = true }.request_head(url).code != '404'
47
+ end
48
+
49
+ def github_url(url)
50
+ if url =~ /\Ahttps?:\/\/([^.]+)\.github\.(?:com|io)\/(.+)/
51
+ if $1 == 'www'
52
+ "https://github.com/#{$2}"
53
+ elsif $1 == 'wiki'
54
+ # https://wiki.github.com/foo/bar => https://github.com/foo/bar
55
+ "https://github.com/#{$2}"
56
+ else
57
+ # https://foo.github.com/bar => https://github.com/foo/bar
58
+ "https://github.com/#{$1}/#{$2}"
59
+ end
60
+ end
61
+ end
62
+
63
+ def api
64
+ @api ||= open("https://rubygems.org/api/v1/gems/#{spec.name}.yaml", &:read)
65
+ rescue OpenURI::HTTPError
66
+ ""
67
+ end
68
+
69
+ def source_code_uri
70
+ api_uri_for('source_code')
71
+ end
72
+
73
+ def homepage_uri
74
+ api_uri_for('homepage')
75
+ end
76
+
77
+ def github_organization_uri(name)
78
+ "https://github.com/#{name}/#{name}"
79
+ end
80
+
81
+ def api_uri_for(key)
82
+ uri = api[Regexp.new("^#{key}_uri: (.*)$"), 1]
83
+ uri =~ /\A(?:https?|git):\/\// ? uri : nil
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,66 @@
1
+ # frozen-string-literal: true
2
+
3
+ module Gem::Src::Srv
4
+ IRREGULAR_REPOSITORIES = {
5
+ 'activesupport' => nil,
6
+ 'actionview' => nil,
7
+ 'actionpack' => nil,
8
+ 'activemodel' => nil,
9
+ 'activerecord' => nil,
10
+ 'activejob' => nil,
11
+ 'actionmailer' => nil,
12
+ 'actioncable' => nil,
13
+ 'railties' => nil,
14
+ 'activeresource' => 'https://github.com/rails/activeresource.git',
15
+ 'autoparse' => 'https://github.com/google/autoparse.git',
16
+ 'aws-sdk-rails' => 'https://github.com/aws/aws-sdk-rails.git',
17
+ 'bson' => 'https://github.com/mongodb/bson-ruby.git',
18
+ 'compass-core' => 'https://github.com/Compass/compass.git',
19
+ 'compass-import-once' => 'https://github.com/Compass/compass.git',
20
+ 'cool.io' => 'https://github.com/tarcieri/cool.io.git',
21
+ 'cucumber-core' => 'https://github.com/cucumber/cucumber-ruby-core.git',
22
+ 'cucumber-wire' => 'https://github.com/cucumber/cucumber-ruby-wire.git',
23
+ 'diff-lcs' => 'https://github.com/halostatue/diff-lcs.git',
24
+ 'elasticsearch-api' => 'https://github.com/elastic/elasticsearch-ruby.git',
25
+ 'elasticsearch-extensions' => 'https://github.com/elastic/elasticsearch-ruby.git',
26
+ 'elasticsearch-transport' => 'https://github.com/elastic/elasticsearch-ruby.git',
27
+ 'erubis' => 'https://github.com/kwatch/erubis.git',
28
+ 'geocoder' => 'https://github.com/alexreisner/geocoder',
29
+ 'hirb' => 'https://github.com/cldwalker/hirb',
30
+ 'html2haml' => 'https://github.com/haml/html2haml',
31
+ 'io-console' => nil,
32
+ 'kaminari-actionview' => nil,
33
+ 'kaminari-activerecord' => nil,
34
+ 'kaminari-core' => nil,
35
+ 'log4r' => 'https://github.com/colbygk/log4r',
36
+ 'meta_request' => 'https://github.com/dejan/rails_panel',
37
+ 'method_source' => 'https://github.com/banister/method_source',
38
+ 'origin' => 'https://github.com/mongoid/origin',
39
+ 'padrino' => 'https://github.com/padrino/padrino-framework',
40
+ 'padrino-admin' => nil,
41
+ 'padrino-cache' => nil,
42
+ 'padrino-core' => nil,
43
+ 'padrino-gen' => nil,
44
+ 'padrino-helpers' => nil,
45
+ 'padrino-mailer' => nil,
46
+ 'padrino-performance' => nil,
47
+ 'padrino-support' => nil,
48
+ 'paranoia' => 'https://github.com/rubysherpas/paranoia',
49
+ 'pdf-core' => 'https://github.com/prawnpdf/pdf-core',
50
+ 'pg' => nil,
51
+ 'rack-mini-profiler' => 'https://github.com/MiniProfiler/rack-mini-profiler',
52
+ 'raindrops' => 'https://github.com/tmm1/raindrops',
53
+ 'redis-actionpack' => 'https://github.com/redis-store/redis-actionpack',
54
+ 'redis-activesupport' => 'https://github.com/redis-store/redis-activesupport',
55
+ 'redis-rack' => 'https://github.com/redis-store/redis-rack',
56
+ 'redis-rails' => 'https://github.com/redis-store/redis-rails',
57
+ 'rom-mapper' => 'https://github.com/rom-rb/rom-mapper',
58
+ 'rom-repository' => 'https://github.com/rom-rb/rom-repository',
59
+ 'rom-sql' => 'https://github.com/rom-rb/rom-sql',
60
+ 'rouge' => 'https://github.com/jneen/rouge',
61
+ 'rubygems-update' => nil,
62
+ 'spreadsheet' => 'https://github.com/zdavatz/spreadsheet',
63
+ 'thin' => 'https://github.com/macournoyer/thin',
64
+ 'uniform_notifier' => 'https://github.com/flyerhzm/uniform_notifier'
65
+ }.freeze
66
+ end
@@ -0,0 +1,31 @@
1
+ module Gem::Src::Srv
2
+ Spec = Struct.new(:name, :homepage)
3
+
4
+ class Server
5
+ def self.start(queue)
6
+ self.new(queue).start
7
+ end
8
+
9
+ def initialize(queue)
10
+ @queue = queue
11
+ end
12
+
13
+ def start
14
+ srv = WEBrick::HTTPServer.new(
15
+ BindAddress: '127.0.0.1',
16
+ Port: Configuration::PORT,
17
+ )
18
+ srv.mount_proc('/gem_install') do |req, resp|
19
+ if req.request_method != 'POST'
20
+ resp.status = 404
21
+ next
22
+ end
23
+
24
+ body = JSON.parse(req.body)
25
+ @queue << Spec.new(body['name'], body['homepage'])
26
+ end
27
+ trap('INT') { srv.shutdown }
28
+ srv.start
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,7 @@
1
+ module Gem
2
+ module Src
3
+ module Srv
4
+ VERSION = "0.1.1"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,23 @@
1
+ module Gem::Src::Srv
2
+ class Worker
3
+ def self.start(queue)
4
+ Configuration::CONCURRENCY.times do
5
+ self.new(queue).start
6
+ end
7
+ end
8
+
9
+ def initialize(queue)
10
+ @queue = queue
11
+ end
12
+
13
+ def start
14
+ Thread.new do
15
+ loop do
16
+ spec = @queue.pop
17
+ fetcher = Fetcher.new(spec)
18
+ fetcher.fetch
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,25 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'retryable'
4
+ require 'json'
5
+
6
+ require 'gem/src/srv/configuration'
7
+
8
+
9
+ Gem.post_install do |installer|
10
+ next if installer.spec.name == 'gem-src-srv'
11
+
12
+ spawn('gem-src-srv', [:out, :err] => '/dev/null')
13
+
14
+ Retryable.retryable(tries: 3, sleep: 0.1, on: Errno::ECONNREFUSED) do
15
+ port = Gem::Src::Srv::Configuration::PORT
16
+ uri = URI.parse("http://localhost:#{port}/gem_install")
17
+ req = Net::HTTP::Post.new(uri)
18
+ req.body = JSON.generate({
19
+ name: installer.spec.name,
20
+ homepage: installer.spec.homepage,
21
+ })
22
+ req.content_type = 'Application/json'
23
+ Net::HTTP.new(uri.host, uri.port).start {|http| http.request(req) }
24
+ end
25
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gem-src-srv
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Masataka Pocke Kuwabara
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-02-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: retryable
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: Run `git clone` after `gem install` concurrently.
56
+ email:
57
+ - kuwabara@pocke.me
58
+ executables:
59
+ - gem-src-srv
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - Gemfile.lock
66
+ - LICENSE
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - exe/gem-src-srv
72
+ - gem-src-srv.gemspec
73
+ - lib/gem/src/srv.rb
74
+ - lib/gem/src/srv/configuration.rb
75
+ - lib/gem/src/srv/fetcher.rb
76
+ - lib/gem/src/srv/irregular_repositories.rb
77
+ - lib/gem/src/srv/server.rb
78
+ - lib/gem/src/srv/version.rb
79
+ - lib/gem/src/srv/worker.rb
80
+ - lib/rubygems_plugin.rb
81
+ homepage: https://github.com/pocke/gem-src-srv
82
+ licenses: []
83
+ metadata: {}
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 2.7.6
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: Run `git clone` after `gem install` concurrently.
104
+ test_files: []