2016-03-07 61 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

相關問題