ruby - 打包一个 Git Gem 以部署到 Ruby Lambda 运行时
问题描述
我正在构建一个 Ruby 2.7 Lambda 应用程序。
我的应用程序依赖于 github 中存在的 gem。
gem 'my-gem', git: 'https://github.com/my-org/my-gem', branch: 'main'
我想编写一个脚本来构建一个包含此依赖项的部署 zip 文件。
当我运行时bundle install
,我的 gem 安装到 vendor/bundle/ruby/2.7.0/bundler/gems/my-gem-GITHASH。
对于 Lambda 包装,我相信我需要构建以下内容
- 供应商/bundle/ruby/2.7.0/gems/my-gem-1.0.0/*(红宝石代码)
- 供应商/bundle/ruby/2.7.0/specifications/my-gem-1.0.0.gemspec
以下脚本操作可以组装此结构,但我希望我有一个更简单的方法。
cd vendor/bundle/ruby/2.7.0/bundler/gems/my-gem-*
# build the git gem (*.gem)
gem build
# copy the gem and the gemspec to the vendor/bundle/ruby/2.7.0 directories
cp *.gem ../../../gems
cp *.gemspec ../../../specifications/my-gem-1.0.0.gemspec
# upack the .gem file in the proper directory
cd ../../../gems
gem unpack *.gem
# return to the working directory
cd ../../../../..
# Zip the dependencies
zip -r deploy.zip \
vendor/bundle/ruby/2.7.0/gems \
vendor/bundle/ruby/2.7.0/specifications \
vendor/bundle/ruby/2.7.0/extensions \
lib
我很想找到一个更简单的方法来解决这个问题。
解决方案
另一种解决方案是将bundler/gems
路径添加到$LOAD_PATH
,如下所示:
load_paths = Dir['./vendor/bundle/ruby/2.7.0/bundler/gems/**/lib']
$LOAD_PATH.unshift(*load_paths)
(在最顶部lambda_function.rb
)
推荐阅读
- laravel - Laravel 不记名令牌认证
- javascript - Jquery 计数器插件 Uncaught TypeError
- r - 有没有办法根据另一列在一个列中创建和插入新行
- typescript - TypeScript - 为什么允许将字符串分配给数字
- record - Modelica 使用记录设置多个参数
- c# - 使用 .NET Core 2.2 发送电子邮件
- checkbox - 如何知道jstree的所有复选框是否都被选中
- javascript - 如何使状态和组件具有相同的值?
- vulkan - 输入附件和多重采样
- python - 在其他轮廓中填充轮廓/像素 | 使用深度图像检测框