2016-04-29 101 views
0

我需要将多个NodeJS应用程序部署到在Microsoft Azure上运行的Ubuntu 14.04.4虚拟机。
我正在使用shipitshipit-deploy来执行此任务。在远程Azure虚拟机上将sudo部署为sudo

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": "[email protected]" 
} 

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

'deploy:update' errored after 3.41 s 
Error: Command failed: ssh -i ~/.ssh/id_rsa.pem "[email protected]" "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 workaround启动SSH会话为root

我还是要尝试第一个,并且不肯愿意使用第二个。

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

回答

0

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

因此您的部署任务不需要管理员权限,这也将避免一些意外的权限操作问题。

E.G.

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