简体   繁体   English

如何通过 Chef 配置 Bundler?

[英]How to configure Bundler via Chef?

We use Chef to setup and execute Bundler.我们使用 Chef 来设置和执行 Bundler。 We previously run bundle install , in an bash resource with the user and group attributes set to target_user (the bundler operation is intended to be run as this user).我们之前在bash资源中运行bundle install ,并将usergroup属性设置为target_user (捆绑操作旨在以此用户身份运行)。

Due to the deprecation of some options (ie. --deployment , --path and --without ), we now need to configure them via bundle config .由于一些选项的折旧(即--deployment--path--without ),我们现在需要配置它们通过bundle config

However, it seems that when using the same resource configuration, Bundle doesn't work as intended;但是,似乎在使用相同的资源配置时,Bundle 无法按预期工作; we get Bundler::SudoNotPermittedError: Bundler requires sudo access to install... , which I suppose is because the configuration file is not stored in the proper place, and/or read.我们得到Bundler::SudoNotPermittedError: Bundler requires sudo access to install... ,我想这是因为配置文件没有存储在正确的位置,和/或读取。

How should the execute resource be configured? execute资源应该如何配置? Currently, it's:目前,它是:

# Simplified version
bash "Install gems" do
  code <<~EOF
    bundle config --local deployment true &&
    bundle config --local path /path/to/gems_dir &&
    bundle install --gemfile=/path/to/Gemfile
  EOF

  user "target_user"
  group "target_user"
end

You have this bash resource run as target_user , that's why the error.您将此bash资源作为target_user运行,这就是错误的原因。 I think you have 2 options here:我认为你在这里有两个选择:

  1. Remove the user and group from the resource, then it will be run as root.从资源中删除用户和组,然后它将以 root 身份运行。
  2. Add sudo before the every bundle command in the code , and make sure target_user is sudoer with no password.在每次的管束命令前加sudo code ,并确保TARGET_USER是sudoer,没有密码。

It turns out that Chef doesn't export the environment (variables) when setting user / group , so if one wants to have a fully preset environment, some variables need to be set manually, via the env attribute.事实证明,在设置user / group时,Chef 不会导出环境(变量),因此如果想要拥有完全预设的环境,则需要通过env属性手动设置一些变量。

A minimum preset that accomplishes the task is the following:完成任务的最低预设如下:

bash "Bundle..." do
  code "bundle ..."
  user "user"
  group "user"
  env({
    "HOME"     => "/home/user",
    "USER"     => "user",
    "USERNAME" => "user",
    "PWD"      => "/home/user",
  })
end

There are other variables, but I suppose they aren't significant for the vast majority of the commands.还有其他变量,但我想它们对于绝大多数命令来说并不重要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM