2016-03-07 33 views
1

我正在使用grunt-msdeploy将angularJs代码部署到服务器之一,这是工作得很好。我想将相同的代码部署到多个服务器。我如何实现它?请帮忙 !对于msdeploygrunt-msdeploy用于将AngularJS应用程序部署到多个服务器

Gruntfile.js代码:

var path = require('path'); 
    //add the config file name 
    var configFile = path.resolve('./deployconfig.json'); 
    var config = require(configFile); 
msdeploy: { 
      push: { 
       options: { 
        verb: 'sync', 
        allowUntrusted: 'true', 
        source: { 
         'contentPath': path.resolve('./dist') 
        }, 
        dest: { 
         contentPath: config.contentPath, 
         wmsvc: config.serverAddress, 
         userName: config.userName, 
         password: config.password 
        } 
       } 
      } 
     } 


grunt.loadNpmTasks('grunt-msdeploy'); 
//add task for deployment - copying the dist from local server to remote server 
grunt.registerTask('deploy', ['msdeploy:push']); 

deployconfig.json:

{ 
    "contentPath": "c:/inetpub/wwwroot/dist", 
    "serverAddress": "ec2-xx-xx-xx-x.ap-northeast-1.compute.amazonaws.com", 
    "userName": "xxxxxxxxx", 
    "password": "xxxxxxxxx" 
} 

我已经在JSON文件中的多台服务器的信息msdeploy使用多个DEST尝试过,但没没有工作。有没有办法做到这一点?

回答

0

这是工作的解决方案:

msdeploy: { 
      target1: { 
       options: { 
        verb: 'sync', 
        allowUntrusted: 'true', 
        source: { 
         'contentPath': path.resolve('./dist') 
        }, 
        dest: { 
         contentPath: "target1path", 
         wmsvc: "target1serverAddress", 
         userName:"target1userName", 
         password:"target1password" 
        } 
       } 
      }, 
      target2: { 
       options: { 
        verb: 'sync', 
        allowUntrusted: 'true', 
        source: { 
         'contentPath': path.resolve('./dist') 
        }, 
        dest: { 
         contentPath: "target2path", 
         wmsvc: "target2serverAddress", 
         userName:"target2userName", 
         password:"target2password" 
        } 
       } 
      } 
     } 

grunt.registerTask('deploy', ['msdeploy:target1', 'msdeploy:target2']); 

在情况下,如果任何人想用配置文件来做到这一点,多个条目添加到JSON配置文件是这样的:

[ 
    { 
    "contentPath": "c:/inetpub/wwwroot/dist", 
    "serverAddress": "ec2-xx-xxx-xx-xxx.ap-northeast-1.compute.amazonaws.com", 
    "userName": "xxxxxxxxxx", 
    "password": "xxxxxxxxx" 
    }, 
    { 
    "contentPath": "c:/inetpub/wwwroot/dist", 
    "serverAddress": "ec2-xx-xxx-xx-xxx.ap-northeast-1.compute.amazonaws.com", 
    "userName": "xxxxxxxxxx", 
    "password": "xxxxxxxxx" 
    } 
] 

和值可以被称为:

var path = require('path'); 
var configFile = path.resolve('./deployconfig.json'); 
var config = require(configFile); 

contentPath: config[0].contentPath, 
wmsvc: config[0].serverAddress, 
userName: config[0].userName, 
password: config[0].password 
3

我认为你正在配置的任务错误的,这就是为什么它不工作你的情况,它应该被定义为TAKS的呼噜声,这里是伪代码:

grunt.initConfig({ 
    msdeploy: { 
    options: { 
     // Task-specific options go here. 
    }, 
    your_target: { 
     // Target-specific file lists and/or options go here. 
    }, 
    }, 
}); 

更多信息和选项in the official manual

多个目的地的刚刚创建几个target描述,

grunt.initConfig({ 
    msdeploy: { 
    options: { 
     // Task-specific options go here. 
    }, 
    your_target_1: { 
     // Target-specific file lists and/or options go here. 
    }, 
    your_target_2: { 
     // Target-specific file lists and/or options go here. 
    }, 
    ... 
    }, 
}); 

您可以创建options,通用所有这些targets的,以及具体options每每target

当你运行任务,根本就没有指定的目标,你需要运行,它会通过一个执行它们一个:

// will be executed for all the targets from task `msdeploy` definition 
grunt.registerTask('deploy', ['msdeploy']); 

// or alternatively you may explicitly define the order of tasks: 
grunt.registerTask('deploy', ['msdeploy:your_target_1', 'msdeploy:your_target_2']); 
+0

好的,谢谢!我如何为多个目的地注册任务,然后假设我有mydest1和mydest2? grunt.registerTask('deploy',['msdeploy:push:mydest1']); ? – Srini

+0

@Srini,在编辑的答案中找到我的答案,我为你提供这些信息。 – Farside

+0

谢谢!我尝试了上面提到的确切方式,但不接受任何除了dest以外的其他任何名称。当我提供multile dest的部署只到第一台服务器。 – Srini

相关问题