在不使用git或互联网访问的情况下部署Ruby gem local [英] Deploy a Ruby gem local without using git or internet access

查看:167
本文介绍了在不使用git或互联网访问的情况下部署Ruby gem local的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在没有互联网的情况下发布一个Ruby gem,只捆绑安装在开发者电脑上的gem?

这是用于部署内部我们的组织,上网受到严格限制。所有的PC运行Windows7与Ruby1.9.3和Bundler 1.11.2



我几乎没有使用git或bundler的经验。
没有使用Rails,但是其他一些宝石,如activerecord和logger。



我尝试过:
我用rb创建了一个文件夹。脚本和.gemspec文件与所需的gem's,然后我执行 bundle gem name_of_the_gem_i_want_to_make 但出现错误 Errno :: ENOENT:没有这样的文件或目录 - git config user.name
在过去,我创建了一个git帐户并做了一些试验性的工作,我不想使用它。



在过去,我尝试了jRuby和Warble以生成JAR,但在这种情况下,我想坚持使用MRI Ruby。



我在我的开发电脑上连接了互联网,但是我想要一些电脑或服务器部署脚本 - 更重要的是他们依赖的宝石 - 不要。
Ruby已经安装到位了。



我想要一个简单的方法从我的dev电脑中收集所有需要的文件并将它们传输到目标电脑上。
我可以压缩我的Ruby文件夹并将它解压到其他地方,但是我有很多我不需要的文件。



你可以给我命令I需要使用或给我一个网站,解释如何做到这一点?我在网上阅读了很多关于捆绑商的信息,但却找不到这种工作方式。
无法想象其他开发者会遇到同样的问题,并且有一个常见的解决方案。



编辑:



我通过执行 gem build mygem.gemspec 创建了一个gem,但它只有我自己的脚本,没有必需的gem's。



编辑:按照Mihai的建议,删除了以前的尝试。



创建子文件夹供应商/宝石并将2个gemfiles复制到那里。

现在我可以做一个 bundle package 和一个 bundle install --no-部署与以下Gemfile。

  gem'active_record','4.1.1',:path => 'vendor / gems'
gem'logger','1.2.8',:path => 'vendor / gems'

现在的问题:如何将其部署到另一台pc上?复制文件夹中和目标PC上的所有内容,执行 bundle install --local ?或者是否有办法将所有东西都捆绑在一块宝石中,这样在目标PC上我可以执行 gem install mygem --local ?一个gem build mygem不包括bundle中的任何东西。

解决方案

您可以通过两种方式来实现。



a)缓存(套餐 )项目的供应商/缓存文件夹中的宝石

  bundle package 

这会生成/更新 Gemfile.lock 并将所有gem本地复制到您的项目的供应商/缓存文件夹中。然后,您可以将您的项目文件复制到您的服务器并运行

  bundle install --local#翻译为从供应商/缓存



使用自定义路径,通常位于项目之外



bundle install 支持本地路径

  gem install --local path_to_my_gem / my_gem.gem 

- 本地标志是可选的,但在这种情况下它很有用,因为它会跳过常规远程存储库中的查找。



随后,您可以指定Gemfile中的路径以及

  gemmy_gem,路径:path_to_my_gem / my_gem.gem


Is there a way to distribute a Ruby gem without access to the internet, just bundling the gem's that are installed on the dev's pc ?

This is for deploying inside our organisation, access to internet is heavily restricted. All the pc's run Windows7 with Ruby1.9.3 and Bundler 1.11.2

I have little experience with git or bundler. Rails is not used but some other gems like activerecord and logger are.

What I tried: I created a folder with my rb. scripts and a .gemspec file with the required gem's, then I executed bundle gem name_of_the_gem_i_want_to_make but got an error Errno::ENOENT: No such file or directory - git config user.name. In the past I created a git account and did some experimenting bu I'd prefer not to use it.

In the past I experimented with jRuby and Warble to produce JAR's but in this case I'd like to stick with MRI Ruby.

I have internet connection on my dev pc but some of the pc's or servers I want to deploy the scripts - and more important the gem's they depend on - don't. Ruby is allready installed everywhere though.

I'd like a simple way to gather all the needed files from my dev pc and transfer these to the target pc's. I could zip my Ruby folder and extract it elsewhere but then I have a lot of files I don't need.

Can you give me the commands I need to use or give me a site that explains how to do this ? I read a lot about bundler online but have nowhere found this way of working. Can't imagine other devs haven't the same issues and a common solution is present.

EDIT:

I managed to create a gem by executing gem build mygem.gemspec but it has only my own scripts in it, no required gem's.

EDIT: followed the suggestion of Mihai, removed the previous attempts.

Made a subfolder vendor/gems and copied the 2 gemfiles there.

Now I can do a bundle package and a bundle install --no-deployment with the following Gemfile.

gem 'active_record', '4.1.1', :path => 'vendor/gems'
gem 'logger', '1.2.8', :path => 'vendor/gems'

Question now: how to deploy this onto another pc ? Copy everything in the folder and on the target pc do a bundle install --local ? Or is there a way to bundle everything in a gem so that on the target pc I can do gem install mygem --local ? A gem build mygem doesn't include anything from the bundle.

解决方案

You can do this in two ways.

a) Cache (package) the gems in your project's vendor/cache folder

bundle package

This will generate/update Gemfile.lock and copy all the gems locally inside your project's vendor/cache folder. Then you can copy your project files to your server and run

bundle install --local # translates to pick my gems from vendor/cache

b) Use a custom path, usually located outside your project

bundle install supports local paths

gem install --local path_to_my_gem/my_gem.gem

The --local flag is optional but it's useful in this case as it skips the lookup in the usual remote repositories.

Subsequently you can specify the path in the Gemfile as well

gem "my_gem", path: "path_to_my_gem/my_gem.gem"

这篇关于在不使用git或互联网访问的情况下部署Ruby gem local的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆