【问题标题】:Run command in `before_migrate.rb` as user with sudo privileges with AWS OpsWorks使用 AWS OpsWorks 以具有 sudo 权限的用户身份在“before_migrate.rb”中运行命令
【发布时间】:2017-02-04 11:22:54
【问题描述】:

在我的 Rails 应用程序中,我尝试在部署期间运行 gulp 任务,该任务将 css 文件添加到 public 目录内的目录中。在部署日志中,我看到任务运行成功,但是当我 SSH 进入服务器时,我没有看到该文件。

[2016-09-24T01:35:02+00:00] INFO: Processing execute[create critical css] action run   (/srv/www/toaster/releases/20160924013146/deploy/before_migrate.rb line 43)
[2016-09-24T01:35:03+00:00] INFO: execute[create critical css] ran successfully

当我通过 SSH 连接到服务器并将我的用户更改为使用 sudo su deploy 的部署用户,然后运行 ​​gulp 任务时,文件被创建。

我做错了什么?

before_migrate 中的行看起来像这样...

execute 'create critical css' do
  user 'deploy'
  cwd release_path
  command 'gulp criticalCss'
end

我的 gulpfile 中的任务如下所示...

gulp.task('criticalCss', function() {
  glob('./public/assets/theme_templates/v3/application-*.css', function(err, matches) {
    var full_css = matches[0]

    penthouse({
      url : 'http://performance-site.s2.fanbread.com/blogs/performance-benchmark',
      css : full_css,
      width: 375,
      height: 667
    }, function(err, criticalCss) {
      console.log(err)
      fs.writeFile('./public/assets/theme_templates/v3/posts_show.css', criticalCss); // Write the contents to a jekyll include
    });
  });
});

谢谢

【问题讨论】:

    标签: javascript ruby-on-rails gulp chef-infra aws-opsworks


    【解决方案1】:

    对于 Chef,通常的解决方案是将日志级别提高到 DEBUG 以查看命令输出。不知道您如何使用当前的 Opsworks 做到这一点。大多数情况下,这些问题要么与未设置 $HOME 等环境变量有关,要么与未正确找到 gulp 有关。

    附带说明,我不建议再使用deploy 资源。一般而言,普通的git 资源可能会更好。有关使用 Chef 进行更现代 Rails 部署的示例,请参阅我的 application_examples 食谱。

    【讨论】:

    • 感谢您的回复。默认情况下,OpsWorks 在调试模式下运行 chef。该命令的输出是我问题中的第一个代码块,它并没有真正显示任何有用的东西。我的猜测是,如果没有找到 gulp,它会出错,并显示一条更有用的消息来暗示这一点。毕竟,我可以通过 ssh 进入实例并以部署用户的身份成功运行 gulp criticalCSS。您能否详细说明为什么不建议使用部署说明书?
    • deploy 资源是为匹配 Capistrano 的结构而构建的。它比所需的复杂性和移动部件要多得多,而且非常脆弱。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多