u=10=u sizzle-deploy as sudo on remote azure vm

Running shipit-deploy as sudo on remote Azure VM

我需要将几个 NodeJS 应用程序部署到 Microsoft Azure 上的 Ubuntu 14.04.4 虚拟机 运行ning。
我正在使用 shipit with shipit-deploy 完成任务。

我的 shipitfile.js 到目前为止如下所示:

module.exports = function (shipit) {
  require('shipit-deploy')(shipit);

  var stagingConfig = require('./config.staging').deploy;
  var productionConfig = require('./config.prod').deploy;

  shipit.initConfig({
    default: {
      workspace: '/tmp/my-api',
      deployTo: '/var/www/my-api',
      repositoryUrl: 'https://githubrepoaddresshere.git',
      ignores: ['.git', 'node_modules', 'migrations', 'dumpDB', 'logs', 'bin'],
      rsync: ['--del'],
      keepReleases: 2,
      key: '~/.ssh/id_rsa.pem',
      shallowClone: true
    },
    staging: stagingConfig,
    production: productionConfig
  });

  shipit.on('init', function() {
    console.log('Starting deployment...');
  });

  shipit.on('deployed', function () {
    // npm install etc etc
  });
};

stagingConfig 变量是一个包含环境特定信息的对象:

{
  "branch": "develop",
  "servers": "username@my-api-staging.northeurope.cloudapp.azure.com"
}

当我 运行 shipit staging deploy 命令时,我得到

'deploy:update' errored after 3.41 s
Error: Command failed: ssh -i ~/.ssh/id_rsa.pem "username@my-api-staging.northeurope.cloudapp.azure.com" "mkdir -p /var/www/my-api/releases/20160429125114"
mkdir: cannot create directory ‘/var/www/my-api/releases’: Permission denied

我知道我可以:

1) 尝试在 /home/username
上部署 2) Use this workaroundroot.

启动 ssh 会话

第一个还是要试试,第二个我肯定不愿意用

所以我的问题是:是否有一个干净且非 hacky 的解决方案,可以在使用 sudo 部署期间为每个命令添加 shipit-deploy 前缀 运行s?

您可以尝试将变量shipit.releasesPath修改为您的主路径,命令中不需要sudo前缀。

所以你的部署任务不需要管理员权限,这样也会避免一些意外的权限操作问题。

例如

shipit.initConfig({
    default: {
      ...
    },
    staging: {
      servers: '<user>@<your_vm_name>.cloudapp.net'
    }
  });
  shipit.releasesPath = '/home/www/releases';