aws / opsworks-cookbooks

Chef Cookbooks for the AWS OpsWorks Service
Other
1.05k stars 1.23k forks source link

Run command in `before_migrate.rb` as user with sudo privileges not working #394

Open mattymess opened 8 years ago

mattymess commented 8 years ago

In my Rails app, I'm trying to run a gulp task during deployment, which adds a css file to a directory inside the public directory. In the deployment log, I see that the task runs successfully, but when I SSH into the server, I don't see the file.

[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

While I'm connected to the server via SSH and change my user to the deploy user with sudo su deploy and then run the gulp task, the file gets create.

What am I doing wrong?

The line in before_migrate looks like this...

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

The task in my gulpfile looks like this...

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
    });
  });
});

Thanks