can bundler be used in rsync deployments?

后端 未结 3 1479
忘掉有多难
忘掉有多难 2021-01-15 03:55

Can you deploy a Rails3 app using Bundler\'s Gemfile WITHOUT running bundle install... i.e. just by copying a rails project directory to the appropriate

相关标签:
3条回答
  • 2021-01-15 04:41

    Some other rails devs and I were discussing how to effectively freeze gems in Rails 3 and we worked out this solution. This is along the lines of what @asymmetric proposed, but different in some key ways. As I later discovered from the gemfile man page, this approach also suffers from the same limitation that @indirect warned of with bundle install --deployment, in that your gems must either be pure ruby (no native compilation), or these steps must be done on an identical architecture to your stage and prod servers.

    Ok, now that we have the preliminaries out of the way, let's see about "freezing" some gems into Rails 3...

    First, start with a clean environment:

    $ rvm gemset use fresh
    $ rvm gemset empty fresh
    $ gem install rails
    $ rails new strawman
    $ cd strawman/
    

    Next, install the gem you want to use:

    $ gem install condi
    

    Next, create a vendor/gems directory and unpack the gem within it:

    $ mkdir vendor/gems
    $ cd vendor/gems
    $ gem unpack condi
    Unpacked gem: '/tmp/strawman/vendor/gems/condi-0.0.6'
    

    OPTIONAL:

    If your gem doesn't have a .gemspec file with it (i.e. the spec is part of the contained Rakefile build), Bundler may not be able to load it correctly with the :path statement. In this case, you have to output the gemspec from the gem file using:

    $ gem specification /tmp/condi-0.0.6.gem > condi-0.0.6/condi.gemspec
    

    Or if you already have the gem installed locally, you can:

    $ gem specification condi -v=0.0.6 > condi-0.0.6/condi.gemspec
    

    Now, update the Gemfile with the line:

    gem 'condi', '0.0.6', :path => 'vendor/gems/condi-0.0.6'
    

    NOTE: "Unlike :git, bundler does not compile C extensions for gems specified as paths." [man gemfile] So this only works for pure ruby gems without native extensions! Be warned!

    Next, uninstall the gem from your gemset:

    $ gem uninstall condi
    Successfully uninstalled condi-0.0.6
    

    And returning to the rails root environment, try to run the rails console:

    $ cd ../..
    $ rails c
    Loading development environment (Rails 3.1.3)
    1.9.3-p0 :001 > 
    

    Success!! Your pure ruby gem is now effectively frozen in a Rails 3 app.

    0 讨论(0)
  • 2021-01-15 04:48

    Not a direct answer to your question, but you don't need admin privileges to install gems – you can install them locally to your app's location:

    bundle install --path vendor/bundle
    

    This would also isolate this app's environment from the other's, in regards to gems (i.e. the "system" gems are left in peace).

    Just remember to prepend every call to a gem with bundle exec.

    You might also want to look into rvm and its gemsets

    0 讨论(0)
  • 2021-01-15 04:57

    Yes, you can. You have to find a machine with the exact same OS/architecture combination as your production servers, and then run bundle install --deployment on it. Once you've done that, you can copy the entire app directory (including ./vendor/bundle, which contains all the installed gems). Since the gems are all already installed and compiled, your app will just boot.

    That said, this is officially unsupported. If you have issues with the approach, while the Bundler team will try to help you, there are no guarantees it will work (or keep working into the future). Here thar be dragons, etc., etc.

    0 讨论(0)
提交回复
热议问题