【问题标题】:Running shipit-deploy as sudo on remote Azure VM在远程 Azure VM 上以 sudo 身份运行 shipit-deploy
【发布时间】:2016-04-29 13:17:47
【问题描述】:

我需要将几个 NodeJS 应用程序部署到在 Microsoft Azure 上运行的 Ubuntu 14.04.4 虚拟机。
我正在使用 shipitshipit-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 的解决方案让 shipit-deploy 在部署期间使用 sudo 为它运行的每个命令添加前缀?

【问题讨论】:

    标签: node.js azure deployment web-deployment


    【解决方案1】:

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

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

    例如

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-24
      • 2019-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多