Skip to content

Commit

Permalink
Merge pull request #3785 from Microsoft/users/biprasad/fixPackerFix1
Browse files Browse the repository at this point in the history
Add task input for deploy script arguments
  • Loading branch information
bishal-pdMSFT authored Mar 14, 2017
2 parents 7de6420 + 72c7592 commit 735ebdf
Show file tree
Hide file tree
Showing 20 changed files with 124 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"location": "",
"script_path": "",
"script_name": "",
"script_arguments": "",
"package_path": "",
"package_name": "",
"capture_name_prefix": ""
Expand Down Expand Up @@ -63,7 +64,7 @@
"cd /deployTemp",
"ls",
"chmod +x /deployTemp/{{user `script_name`}}",
"/deployTemp/{{user `script_name`}}"
"/deployTemp/{{user `script_name`}} {{user `script_arguments`}}"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"location": "",
"script_path": "",
"script_name": "",
"script_arguments": "",
"package_path": "",
"package_name": "",
"capture_name_prefix": ""
Expand Down Expand Up @@ -65,7 +66,7 @@
"inline": [
"cd \"C:\\DeployTemp\"",
"ls",
"C:\\DeployTemp\\{{user `script_name`}}"
"C:\\DeployTemp\\{{user `script_name`}} {{user `script_arguments`}}"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
"loc.input.help.packagePath": "Specify the path to deployment package.",
"loc.input.label.deployScriptPath": "Deployment script",
"loc.input.help.deployScriptPath": "Specify the path to powershell or shell script which deploys application.",
"loc.input.label.deployScriptArguments": "Deployment script arguments",
"loc.input.help.deployScriptArguments": "Specify the arguments to be passed to deployment script.",
"loc.input.label.imageUri": "Image URI",
"loc.input.help.imageUri": "Provide a name for the variable for output image URI.",
"loc.input.label.imageStorageAccount": "Image storage account location",
Expand All @@ -39,5 +41,7 @@
"loc.messages.StorageAccountLocationOutputVariableNotFound": "Could not get vhd image storage account location from packer execution. Output variable will not be set.",
"loc.messages.BuiltInTemplateNotFoundErrorMessagePathName": "Built-in template for OS type: %s ",
"loc.messages.CouldNotDeleteTemporaryTemplateDirectory": "Could not delete temporary template directory %s. Please delete manually.",
"loc.messages.TaskParametersConstructorFailed": "Error happened while initializing task: %s."
"loc.messages.TaskParametersConstructorFailed": "Error happened while initializing task: %s.",
"loc.messages.PackerFixFailed": "Packer fix command failed. This could happen if task does not support packer version.",
"loc.messages.PackerValidateFailed": "Packer validate command failed. This could happen if task does not support packer version."
}
18 changes: 16 additions & 2 deletions Tasks/PackerBuild/Tests/L0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ describe('PackerBuild Suite', function() {
done();
});

it('Should write output of packer fix to updated template file', (done:MochaDone) => {
let tp = path.join(__dirname, 'L0Windows.js');
let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp);
tr.run();

assert(tr.invokedToolCount == 3, 'should have invoked tool thrice. actual: ' + tr.invokedToolCount);
assert(tr.succeeded, 'task should have succeeded');
assert(tr.stdout.indexOf("packer fix -validate=false") != -1, "packer fix command not called");
assert(tr.stdout.indexOf("writing to file F:\\somedir\\tempdir\\100\\default.windows.template-fixed.json content: { \"some-key\": \"some-value\" }") != -1, "packer validate command not called");
done();
});

it('Should cleanup temp template folder', (done:MochaDone) => {
let tp = path.join(__dirname, 'L0Windows.js');
let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp);
Expand Down Expand Up @@ -173,7 +185,8 @@ describe('PackerBuild Suite', function() {

assert(tr.failed, 'task should have failed');
assert(tr.invokedToolCount == 1, 'should not invoke packer validate and build commands. actual: ' + tr.invokedToolCount);
assert(tr.stdout.indexOf("packer fix failed\r\nsome error") != -1, "error message should be right");
assert(tr.stdout.indexOf("packer fix failed\r\nsome error") != -1, "error message should be right");
assert(tr.stdout.indexOf("loc_mock_PackerFixFailed") != -1, "error message should be right");
done();
});

Expand All @@ -186,7 +199,8 @@ describe('PackerBuild Suite', function() {

assert(tr.failed, 'task should have failed');
assert(tr.invokedToolCount == 2, 'should not invoke packer build command. actual: ' + tr.invokedToolCount);
assert(tr.stdout.indexOf("packer validate failed\r\nsome error") != -1, "error message should be right");
assert(tr.stdout.indexOf("packer validate failed\r\nsome error") != -1, "error message should be right");
assert(tr.stdout.indexOf("loc_mock_PackerValidateFailed") != -1, "error message should be right");
done();
});

Expand Down
14 changes: 9 additions & 5 deletions Tasks/PackerBuild/Tests/L0Linux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ tr.setInput('baseImage', 'Canonical:UbuntuServer:14.04.4-LTS:linux');
tr.setInput('location', 'South India');
tr.setInput('packagePath', '/packer-user-scripts/dummy.tar.gz');
tr.setInput('deployScriptPath', '/packer-user-scripts/deploy.sh');
tr.setInput('deployScriptArguments', "\"subdir 1\" false");
tr.setInput('ConnectedServiceName', 'AzureRMSpn');
tr.setInput('imageUri', 'imageUri');
tr.setInput('imageStorageAccount', 'imageStorageAccount');
Expand All @@ -33,25 +34,25 @@ let a: any = <any>{
"exec": {
"packer fix -validate=false /tmp/tempdir/100/default.linux.template.json": {
"code": 0,
"stdout": "Executed Successfully"
"stdout": "{ \"some-key\": \"some-value\" }"
},
"packer validate -var resource_group=testrg -var storage_account=teststorage -var image_publisher=Canonical -var image_offer=UbuntuServer -var image_sku=14.04.4-LTS -var location=South India -var capture_name_prefix=Release-1 -var script_path=/packer-user-scripts/deploy.sh -var script_name=deploy.sh -var package_path=/packer-user-scripts/dummy.tar.gz -var package_name=dummy.tar.gz -var subscription_id=sId -var client_id=spId -var client_secret=spKey -var tenant_id=tenant -var object_id=oId /tmp/tempdir/100/default.linux.template.json": {
"packer validate -var resource_group=testrg -var storage_account=teststorage -var image_publisher=Canonical -var image_offer=UbuntuServer -var image_sku=14.04.4-LTS -var location=South India -var capture_name_prefix=Release-1 -var script_path=/packer-user-scripts/deploy.sh -var script_name=deploy.sh -var package_path=/packer-user-scripts/dummy.tar.gz -var package_name=dummy.tar.gz -var script_arguments=\"subdir 1\" false -var subscription_id=sId -var client_id=spId -var client_secret=spKey -var tenant_id=tenant -var object_id=oId /tmp/tempdir/100/default.linux.template-fixed.json": {
"code": 0,
"stdout": "Executed Successfully"
},
"packer build -force -var resource_group=testrg -var storage_account=teststorage -var image_publisher=Canonical -var image_offer=UbuntuServer -var image_sku=14.04.4-LTS -var location=South India -var capture_name_prefix=Release-1 -var script_path=/packer-user-scripts/deploy.sh -var script_name=deploy.sh -var package_path=/packer-user-scripts/dummy.tar.gz -var package_name=dummy.tar.gz -var subscription_id=sId -var client_id=spId -var client_secret=spKey -var tenant_id=tenant -var object_id=oId /tmp/tempdir/100/default.linux.template.json": {
"packer build -force -var resource_group=testrg -var storage_account=teststorage -var image_publisher=Canonical -var image_offer=UbuntuServer -var image_sku=14.04.4-LTS -var location=South India -var capture_name_prefix=Release-1 -var script_path=/packer-user-scripts/deploy.sh -var script_name=deploy.sh -var package_path=/packer-user-scripts/dummy.tar.gz -var package_name=dummy.tar.gz -var script_arguments=\"subdir 1\" false -var subscription_id=sId -var client_id=spId -var client_secret=spKey -var tenant_id=tenant -var object_id=oId /tmp/tempdir/100/default.linux.template-fixed.json": {
"code": 0,
"stdout": "Executed Successfully\nOSDiskUri: https://bishalpackerimages.blob.core.windows.net/system/Microsoft.Compute/Images/packer/packer-osDisk.e2e08a75-2d73-49ad-97c2-77f8070b65f5.vhd\nStorageAccountLocation: SouthIndia"
},
"packer fix -validate=false \\tmp\\tempdir\\100\\default.linux.template.json": {
"code": 0,
"stdout": "Executed Successfully"
},
"packer validate -var resource_group=testrg -var storage_account=teststorage -var image_publisher=Canonical -var image_offer=UbuntuServer -var image_sku=14.04.4-LTS -var location=South India -var capture_name_prefix=Release-1 -var script_path=/packer-user-scripts/deploy.sh -var script_name=deploy.sh -var package_path=/packer-user-scripts/dummy.tar.gz -var package_name=dummy.tar.gz -var subscription_id=sId -var client_id=spId -var client_secret=spKey -var tenant_id=tenant -var object_id=oId \\tmp\\tempdir\\100\\default.linux.template.json": {
"packer validate -var resource_group=testrg -var storage_account=teststorage -var image_publisher=Canonical -var image_offer=UbuntuServer -var image_sku=14.04.4-LTS -var location=South India -var capture_name_prefix=Release-1 -var script_path=/packer-user-scripts/deploy.sh -var script_name=deploy.sh -var package_path=/packer-user-scripts/dummy.tar.gz -var package_name=dummy.tar.gz -var script_arguments=\"subdir 1\" false -var subscription_id=sId -var client_id=spId -var client_secret=spKey -var tenant_id=tenant -var object_id=oId \\tmp\\tempdir\\100\\default.linux.template-fixed.json": {
"code": 0,
"stdout": "Executed Successfully"
},
"packer build -force -var resource_group=testrg -var storage_account=teststorage -var image_publisher=Canonical -var image_offer=UbuntuServer -var image_sku=14.04.4-LTS -var location=South India -var capture_name_prefix=Release-1 -var script_path=/packer-user-scripts/deploy.sh -var script_name=deploy.sh -var package_path=/packer-user-scripts/dummy.tar.gz -var package_name=dummy.tar.gz -var subscription_id=sId -var client_id=spId -var client_secret=spKey -var tenant_id=tenant -var object_id=oId \\tmp\\tempdir\\100\\default.linux.template.json": {
"packer build -force -var resource_group=testrg -var storage_account=teststorage -var image_publisher=Canonical -var image_offer=UbuntuServer -var image_sku=14.04.4-LTS -var location=South India -var capture_name_prefix=Release-1 -var script_path=/packer-user-scripts/deploy.sh -var script_name=deploy.sh -var package_path=/packer-user-scripts/dummy.tar.gz -var package_name=dummy.tar.gz -var script_arguments=\"subdir 1\" false -var subscription_id=sId -var client_id=spId -var client_secret=spKey -var tenant_id=tenant -var object_id=oId \\tmp\\tempdir\\100\\default.linux.template-fixed.json": {
"code": 0,
"stdout": "Executed Successfully\nOSDiskUri: https://bishalpackerimages.blob.core.windows.net/system/Microsoft.Compute/Images/packer/packer-osDisk.e2e08a75-2d73-49ad-97c2-77f8070b65f5.vhd\nStorageAccountLocation: SouthIndia"
}
Expand All @@ -76,6 +77,9 @@ tr.registerMock('./utilities', {
copyFile: function(source: string, destination: string) {
console.log('copying ' + source + ' to ' + destination);
},
writeFile: function(filePath: string, content: string) {
console.log("writing to file " + filePath + " content: " + content);
},
getCurrentTime: function() {
return 100;
},
Expand Down
9 changes: 6 additions & 3 deletions Tasks/PackerBuild/Tests/L0Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ let a: any = <any>{
"exec": {
"packer fix -validate=false F:\\somedir\\tempdir\\100\\default.windows.template.json": {
"code": 0,
"stdout": "Executed Successfully"
"stdout": "{ \"some-key\": \"some-value\" }"
},
"packer validate -var resource_group=testrg -var storage_account=teststorage -var image_publisher=MicrosoftWindowsServer -var image_offer=WindowsServer -var image_sku=2012-R2-Datacenter -var location=South India -var capture_name_prefix=Release-1 -var script_path=C:\\deploy.ps1 -var script_name=deploy.ps1 -var package_path=C:\\dummy.zip -var package_name=dummy.zip -var subscription_id=sId -var client_id=spId -var client_secret=spKey -var tenant_id=tenant -var object_id=oId F:\\somedir\\tempdir\\100\\default.windows.template.json": {
"packer validate -var resource_group=testrg -var storage_account=teststorage -var image_publisher=MicrosoftWindowsServer -var image_offer=WindowsServer -var image_sku=2012-R2-Datacenter -var location=South India -var capture_name_prefix=Release-1 -var script_path=C:\\deploy.ps1 -var script_name=deploy.ps1 -var package_path=C:\\dummy.zip -var package_name=dummy.zip -var subscription_id=sId -var client_id=spId -var client_secret=spKey -var tenant_id=tenant -var object_id=oId F:\\somedir\\tempdir\\100\\default.windows.template-fixed.json": {
"code": 0,
"stdout": "Executed Successfully"
},
"packer build -force -var resource_group=testrg -var storage_account=teststorage -var image_publisher=MicrosoftWindowsServer -var image_offer=WindowsServer -var image_sku=2012-R2-Datacenter -var location=South India -var capture_name_prefix=Release-1 -var script_path=C:\\deploy.ps1 -var script_name=deploy.ps1 -var package_path=C:\\dummy.zip -var package_name=dummy.zip -var subscription_id=sId -var client_id=spId -var client_secret=spKey -var tenant_id=tenant -var object_id=oId F:\\somedir\\tempdir\\100\\default.windows.template.json": {
"packer build -force -var resource_group=testrg -var storage_account=teststorage -var image_publisher=MicrosoftWindowsServer -var image_offer=WindowsServer -var image_sku=2012-R2-Datacenter -var location=South India -var capture_name_prefix=Release-1 -var script_path=C:\\deploy.ps1 -var script_name=deploy.ps1 -var package_path=C:\\dummy.zip -var package_name=dummy.zip -var subscription_id=sId -var client_id=spId -var client_secret=spKey -var tenant_id=tenant -var object_id=oId F:\\somedir\\tempdir\\100\\default.windows.template-fixed.json": {
"code": 0,
"stdout": process.env["__build_output__"]
}
Expand All @@ -57,6 +57,9 @@ tr.registerMock('./utilities', {
copyFile: function(source: string, destination: string) {
console.log('copying ' + source + ' to ' + destination);
},
writeFile: function(filePath: string, content: string) {
console.log("writing to file " + filePath + " content: " + content);
},
getCurrentTime: function() {
return 100;
},
Expand Down
10 changes: 7 additions & 3 deletions Tasks/PackerBuild/Tests/L0Windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ tr.setInput('baseImage', 'MicrosoftWindowsServer:WindowsServer:2012-R2-Datacente
tr.setInput('location', 'South India');
tr.setInput('packagePath', 'C:\\dummy.zip');
tr.setInput('deployScriptPath', 'C:\\deploy.ps1');
tr.setInput('deployScriptArguments', "-target \"subdir 1\" -shouldFail false");
tr.setInput('ConnectedServiceName', 'AzureRMSpn');
tr.setInput('imageUri', 'imageUri');
tr.setInput('imageStorageAccount', 'imageStorageAccount');
Expand All @@ -33,13 +34,13 @@ let a: any = <any>{
"exec": {
"packer fix -validate=false F:\\somedir\\tempdir\\100\\default.windows.template.json": {
"code": 0,
"stdout": "Executed Successfully"
"stdout": "{ \"some-key\": \"some-value\" }"
},
"packer validate -var resource_group=testrg -var storage_account=teststorage -var image_publisher=MicrosoftWindowsServer -var image_offer=WindowsServer -var image_sku=2012-R2-Datacenter -var location=South India -var capture_name_prefix=Release-1 -var script_path=C:\\deploy.ps1 -var script_name=deploy.ps1 -var package_path=C:\\dummy.zip -var package_name=dummy.zip -var subscription_id=sId -var client_id=spId -var client_secret=spKey -var tenant_id=tenant -var object_id=oId F:\\somedir\\tempdir\\100\\default.windows.template.json": {
"packer validate -var resource_group=testrg -var storage_account=teststorage -var image_publisher=MicrosoftWindowsServer -var image_offer=WindowsServer -var image_sku=2012-R2-Datacenter -var location=South India -var capture_name_prefix=Release-1 -var script_path=C:\\deploy.ps1 -var script_name=deploy.ps1 -var package_path=C:\\dummy.zip -var package_name=dummy.zip -var script_arguments=-target \"subdir 1\" -shouldFail false -var subscription_id=sId -var client_id=spId -var client_secret=spKey -var tenant_id=tenant -var object_id=oId F:\\somedir\\tempdir\\100\\default.windows.template-fixed.json": {
"code": 0,
"stdout": "Executed Successfully"
},
"packer build -force -var resource_group=testrg -var storage_account=teststorage -var image_publisher=MicrosoftWindowsServer -var image_offer=WindowsServer -var image_sku=2012-R2-Datacenter -var location=South India -var capture_name_prefix=Release-1 -var script_path=C:\\deploy.ps1 -var script_name=deploy.ps1 -var package_path=C:\\dummy.zip -var package_name=dummy.zip -var subscription_id=sId -var client_id=spId -var client_secret=spKey -var tenant_id=tenant -var object_id=oId F:\\somedir\\tempdir\\100\\default.windows.template.json": {
"packer build -force -var resource_group=testrg -var storage_account=teststorage -var image_publisher=MicrosoftWindowsServer -var image_offer=WindowsServer -var image_sku=2012-R2-Datacenter -var location=South India -var capture_name_prefix=Release-1 -var script_path=C:\\deploy.ps1 -var script_name=deploy.ps1 -var package_path=C:\\dummy.zip -var package_name=dummy.zip -var script_arguments=-target \"subdir 1\" -shouldFail false -var subscription_id=sId -var client_id=spId -var client_secret=spKey -var tenant_id=tenant -var object_id=oId F:\\somedir\\tempdir\\100\\default.windows.template-fixed.json": {
"code": 0,
"stdout": "Executed Successfully\nOSDiskUri: https://bishalpackerimages.blob.core.windows.net/system/Microsoft.Compute/Images/packer/packer-osDisk.e2e08a75-2d73-49ad-97c2-77f8070b65f5.vhd\nStorageAccountLocation: SouthIndia"
}
Expand All @@ -61,6 +62,9 @@ tr.registerMock('./utilities', {
copyFile: function(source: string, destination: string) {
console.log('copying ' + source + ' to ' + destination);
},
writeFile: function(filePath: string, content: string) {
console.log("writing to file " + filePath + " content: " + content);
},
getCurrentTime: function() {
return 100;
},
Expand Down
Loading

0 comments on commit 735ebdf

Please sign in to comment.