Giter VIP home page Giter VIP logo

grack's Introduction

Dependency Status

Note: the grack gem is now being developed further at grackorg/grack. This repository will not be updated any longer.

Grack - Ruby/Rack Git Smart-HTTP Server Handler

This project aims to replace the builtin git-http-backend CGI handler distributed with C Git with a Rack application. This reason for doing this is to allow far more webservers to be able to handle Git smart http requests.

The default git-http-backend only runs as a CGI script, and specifically is only targeted for Apache 2.x usage (it requires PATH_INFO to be set and specifically formatted). So, instead of trying to get it to work with other CGI capable webservers (Lighttpd, etc), we can get it running on nearly every major and minor webserver out there by making it Rack capable. Rack applications can run with the following handlers:

  • CGI
  • FCGI
  • Mongrel (and EventedMongrel and SwiftipliedMongrel)
  • WEBrick
  • SCGI
  • LiteSpeed
  • Thin

These web servers include Rack handlers in their distributions:

  • Ebb
  • Fuzed
  • Phusion Passenger (which is mod_rack for Apache and for nginx)
  • Unicorn

With Warbler, and JRuby, we can also generate a WAR file that can be deployed in any Java web application server (Tomcat, Glassfish, Websphere, JBoss, etc).

By default, Grack uses calls to git on the system to implement Smart-Http. Since the git-http-backend is really just a simple wrapper for the upload-pack and receive-pack processes with the '--stateless-rpc' option, this does not actually re-implement very much. However, it is possible to use a different backend by specifying a different Adapter. See below for a list.

Dependencies

Quick Start

$ bundle install
$ (edit config.ru to set git project path)
$ rackup --host 127.0.0.1 -p 8080 config.ru
$ git clone http://127.0.0.1:8080/tests/example/test_repo/

Adapters

Grack makes calls to the git binary through the GitAdapter abstraction class. Grack can be made to use a different backend by specifying a different Adapter class in Grack's configuration, for example:

Grack::App.new({
      :adapter => Grack::RJGitAdapter
    })

Alternative adapters available:

  • rjgit_grack lets Grack use the RJGit gem to implement smart-http in pure jruby.

See below if you are looking to create a custom Adapter.

Contributing

If you would like to contribute to the Grack project, I prefer to get pull-requests via GitHub. You should include tests for whatever functionality you add. Just fork this project, push your changes to your fork and click the 'pull request' button.

Run 'bundle install' to install development dependencies. Then you should be able to run the tests with a 'rake' command. On ruby >= 1.9, a coverage report will be generated using simplecov. On ruby 1.8, use rcov instead: uncomment the relevant line in the Gemfile and use 'rake rcov'.

Developing Adapters

Adapters are abstraction classes that handle the actual implementation of the smart-http protocol (advertising refs, uploading and receiving packfiles). Such abstraction classes must have the following methods:

MyAdapter.receive_pack(repository_path, opts = {}, &block)
MyAdapter.upload_pack(repository_path, opts = {}, &block)
MyAdapter.update_server_info(repository_path, opts = {}, &block) # The equivalent of 'git update-server-info'. Optional, for falling back to dumb-http mode.
MyAdapter.get_config_setting(repository_path, key) # Always returns a string, e.g. "false" for key "core.bare".

Both upload_pack and receive_pack must return a ref-advertisement string if opts[:advertise_refs] is set to true; otherwise, they must yield an IO object that Grack uses to read the client's response from.

License

(The MIT License)

Copyright (c) 2009 Scott Chacon <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

grack's People

Contributors

dometto avatar mrkoopie avatar schacon avatar shugo avatar trek avatar workmad3 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

grack's Issues

hooks


$ git remote show local

  • remote local
    Fetch URL: http://localhost:3000/grack_test.git
    Push URL: http://localhost:3000/grack_test.git
    HEAD branch: master
    Remote branch:
    master tracked
    Local ref configured for 'git push':
    master pushes to master (fast-forwardable)

    $ git remote show local2
  • remote local2
    Fetch URL: /Users/rafael/projects/grack/projects/grack_test.git
    Push URL: /Users/rafael/projects/grack/projects/grack_test.git
    HEAD branch: master
    Remote branch:
    master new (next fetch will store in remotes/local2)
    Local ref configured for 'git push':
    master pushes to master (fast-forwardable)

these two remotes are the same repo, but using different protocols, as you can see. I am trying to configure update/post-receive hooks on this repo, but via http it's not working as expected.


$ git push local master
Counting objects: 5, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 337 bytes, done.

Total 3 (delta 1), reused 0 (delta 0)

$ git push local2 master
Counting objects: 5, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 337 bytes, done.
Total 3 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.

some message from hook

error: hook declined to update refs/heads/master
To /Users/rafael/projects/grack/projects/grack_test.git
! [remote rejected] master -> master (hook declined)

error: failed to push some refs to '/Users/rafael/projects/grack/projects/grack_test.git'

in the first git push the command simply exits without show any message from update hook, that have this content


!/bin/sh

echo
echo "some message from hook"
echo

exit 1

is it a problem with the protocol or only with grack implementation?

thanks and keep the good work! :)

Apache2: Subfolder

hi,

grack works fine with Apache2 if DocumentRoot is "grackpublic/" and location is set to "/". But I don't want to use a second VirtualHost (because of SSL) but I don't get grack running. If I try to clone a Git, Apache/Grack has a wrong path:

my repos are in /var/scm/st/git

but Apache looks into: /var/scm/fg/tk/htdocs/git/denny-git-test.git .

It seems, that the configuration file from grack wasn't read.

any suggestions?

Memory Consumption

I'm currently using Grack in production, and it works great. It's running on a 6GB slice, and I'm hosting some rather large repos. When I try to clone one of those repos, the slice runs out of memory. I'm not exactly sure whether it's because of the amount of HTTP calls, the pack-process swallowing up the CPU, or something else, but it's definitely stalling.

Is there anything specific to Grack that can be done about this? Is it generally a no go for huge repos (+1GB)?

Exception ArgumentError in Rack body object #each method

This is the set up:
Ruby 1.9
Rails 3.2
Redmine 2.6.1
jbox's redmine_git_hosting plugin

Trying to use git repo through HTTPS. Clone works fine. Push fails because, this is what apache says the issue is:

App 1013 stderr: [ 2015-02-03 16:33:59.3105 1036/0x0000000782d9b0(Worker 1) utils.rb:68 ]: *** Exception ArgumentError in Rack body object #each method (wrong number of arguments (3 for 1..2)) (process 1036, thread 0x0000000782d9b0(Worker 1)):
App 1013 stderr: from /home/r2d2/.bundler/ruby/1.9.1/grack-971b468103ac/lib/grack/server.rb:78:in popen' App 1013 stderr: from /home/r2d2/.bundler/ruby/1.9.1/grack-971b468103ac/lib/grack/server.rb:78:inblock in service_rpc'
App 1013 stderr: from /usr/lib/ruby/vendor_ruby/rack/response.rb:89:in call' App 1013 stderr: from /usr/lib/ruby/vendor_ruby/rack/response.rb:89:ineach'
App 1013 stderr: from /usr/lib/ruby/vendor_ruby/rack/body_proxy.rb:31:in each' App 1013 stderr: from /var/lib/gems/1.9.1/gems/activerecord-3.2.21/lib/active_record/query_cache.rb:46:ineach'
App 1013 stderr: from /var/lib/gems/1.9.1/gems/activerecord-3.2.21/lib/active_record/connection_adapters/abstract/connection_pool.rb:460:in each' App 1013 stderr: from /usr/lib/ruby/vendor_ruby/rack/body_proxy.rb:31:ineach'
App 1013 stderr: from /usr/lib/ruby/vendor_ruby/phusion_passenger/rack/thread_handler_extension.rb:140:in process_request' App 1013 stderr: from /usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:142:inaccept_and_process_next_request'
App 1013 stderr: from /usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:110:in main_loop' App 1013 stderr: from /usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler.rb:448:inblock (3 levels) in start_threads'

Support for Ruby 1.9. Switch from rcov to simplecov

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

    /usr/bin/ruby1.9.1 extconf.rb 

**** Ruby 1.9 is not supported. Please switch to simplecov ****

Gem files will remain installed in /var/lib/gems/1.9.1/gems/rcov-1.0.0 for inspection.
Results logged to /var/lib/gems/1.9.1/gems/rcov-1.0.0/ext/rcovrt/gem_make.out

An error occurred while installing rcov (1.0.0), and Bundler cannot continue.
Make sure that gem install rcov -v '1.0.0' succeeds before bundling.

uninitialized constant GitHttp (NameError)

I trying to setup web server for publish git repositories on successfully installed and worked redmine server.

Passenger occurs error: Web application could not be started.

uninitialized constant GitHttp (NameError)
config.ru:16:in block in

'
/usr/local/rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/builder.rb:55:ininstance_eval'
/usr/local/rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/builder.rb:55:in initialize'
config.ru:1:innew'
config.ru:1:in '
/usr/local/rvm/gems/ruby-2.0.0-p247/gems/passenger-4.0.18/helper-scripts/rack-preloader.rb:105:ineval'
/usr/local/rvm/gems/ruby-2.0.0-p247/gems/passenger-4.0.18/helper-scripts/rack-preloader.rb:105:in preload_app'
/usr/local/rvm/gems/ruby-2.0.0-p247/gems/passenger-4.0.18/helper-scripts/rack-preloader.rb:150:in'
/usr/local/rvm/gems/ruby-2.0.0-p247/gems/passenger-4.0.18/helper-scripts/rack-preloader.rb:29:in module:PhusionPassenger'
/usr/local/rvm/gems/ruby-2.0.0-p247/gems/passenger-4.0.18/helper-scripts/rack-preloader.rb:28:in'

I use interpreter version - /usr/local/rvm/wrappers/ruby-2.0.0-p247/ruby

Test failures

I see the tests use schacon/simplegit.git (through .gitmodules) for testing the Rack app. However, the tests seem to assume a v1.4 tag exists in this repo (test_info_refs_dumb), which it doesn't seem to have. Could it be this is not the example repository the tests are written against?

Enforcement: More details @ not found

Hello,

I have installed today grack and tried for 2 hours to get it working til I have read the sourcecode and understand, that I will get the message "not found", when the directory miss, request not supported, etc.
It would be nice, when there is a verbose option, which give me more informations about what is missing.

Thanks.

Windows

was giving me "invalid length sets" or "bad length character" errors when running grack on Windows.
Turns out that the pipe under service_rpc() needs to be opened with binary mode, otherwise Windows writes \r\n instead of just \n.
It works if I change it to IO.popen(command, "r+b")

X-Sendfile and X-Accel-Redirect support

While Ruby/Rack is fine to be an intermediary to handle permission/authentication, it's not the best tool at reading/sending files. A better solution can be to delegate it to the webserver (Apache2/Nginx), with X-Sendfile and X-Accel-Redirect HTTP responses.

You can read more about then here:

http://wiki.nginx.org/XSendfile
https://tn123.org/mod_xsendfile/

All you have to do is craft a HTTP response code with one of the two (configurable) and append the path for the file resource and let the webserver handle the file transmission.

fatal: protocol error: bad line length character

Hello,
The GET requests (such as git ls-remote) work well but All the POST requests (such as git clone) fail with the following error message:

fatal: protocol error: bad line length character:

My System:

Windows XP
Thin v1.2.11
git v1.7.4

Some logs:

>> Using rack adapter
>> Thin web server (v1.2.11 codename Bat-Shit Crazy)
>> Tracing ON
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:8080, CTRL+C to stop
GET /tpstory/info/refs?service=git-upload-pack HTTP/1.1
User-Agent: git/1.7.4.3282.g844cb
Host: localhost:8080
Accept: */*
Pragma: no-cache

HTTP/1.1 200 OK
Content-Type: application/x-git-upload-pack-advertisement
Expires: Fri, 01 Jan 1980 00:00:00 GMT
Pragma: no-cache
Cache-Control: no-cache, max-age=0, must-revalidate
Content-Length: 256
Connection: keep-alive
Server: thin 1.2.11 codename Bat-Shit Crazy

001e# service=git-upload-pack
0000
009b86e527191b32b489ed1e75afa930b1915a72b731 HEAD multi_ack thin-pack side-band side-band-64k ofs-delta shallow no-progress include-tag multi_ack_detailed
003f86e527191b32b489ed1e75afa930b1915a72b731 refs/heads/master
0000
POST /tpstory/git-upload-pack HTTP/1.1
User-Agent: git/1.7.4.3282.g844cb
Host: localhost:8080
Accept-Encoding: deflate, gzip
Content-Type: application/x-git-upload-pack-request
Accept: application/x-git-upload-pack-result
Content-Length: 116

0067want 86e527191b32b489ed1e75afa930b1915a72b731 multi_ack_detailed side-band-64k thin-pack ofs-delta
00000009done
HTTP/1.1 200 OK
Content-Type: application/x-git-upload-pack-result
Connection: close
Server: thin 1.2.11 codename Bat-Shit Crazy

fatal: protocol error: bad line length character:
000

Thank you for your help.

Security hole

It seems when Rack::File code was copied over, the protection against directory traversal above the root directory was left out. This means that a user can clone any repo on the system, including the application hosting grack itself. I imagine adding any level of authentication via middleware or otherwise would take care of this in a real application, but if one is using grack standalone the security hole is present.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.