Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added advanced input field Packer version, used to build the image. #10413

Merged
merged 12 commits into from
Jun 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
"loc.input.help.additionalBuilderParameters": "In auto generated Packer template mode the task creates a Packer template with an Azure builder. This builder is used to generate a machine image. You can add keys to the Azure builder to customize the generated Packer template. For example setting ssh_tty=true in case you are using a CentOS base image and you need to have a tty to run sudo.<br/>To view/edit the additional parameters in a grid, click on “…” next to text box.",
"loc.input.label.skipTempFileCleanupDuringVMDeprovision": "Skip temporary file cleanup during deprovision",
"loc.input.help.skipTempFileCleanupDuringVMDeprovision": "During deprovisioning of VM, skip clean-up of temporary files uploaded to VM. Refer [here](https://www.packer.io/docs/builders/azure.html#skip_clean)",
"loc.input.label.packerVersion": "Packer Version",
"loc.input.help.packerVersion": "Specify the version of Packer to install. This will work only with custom templates.",
"loc.input.label.imageUri": "Image URL or Name",
"loc.input.help.imageUri": "Provide a name for the output variable which will store generated machine image VHD url for un-managed VM image or image name for managed VM image.",
"loc.input.label.imageId": "Azure Resource Id",
Expand Down Expand Up @@ -74,6 +76,7 @@
"loc.messages.ResolvedDeployPackgePath": "Resolved deploy package path: %s.",
"loc.messages.ResolvedDeployScriptPath": "Resolved deploy script path: %s.",
"loc.messages.OSNotSupportedForRunningPacker": "OS is not supported for running packer.",
"loc.messages.InstallExplicitPackerVersion": "Packer version %s will be downloaded and installed for running task.",
"loc.messages.DownloadingPackerRequired": "Either packer is not installed or its version is less than %s. Version %s will be downloaded and installed for running task.",
"loc.messages.DownloadingPackerCompleted": "Packer installer downloaded successfully at path: %s.",
"loc.messages.ExtractingPackerCompleted": "Packer extracted successfully at path: %s.",
Expand Down
1 change: 1 addition & 0 deletions Tasks/PackerBuildV1/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export var DeployScriptArgumentsInputName = "deployScriptArguments";
export var ConnectedServiceInputName = "ConnectedServiceName";
export var TemplateTypeInputName = "templateType";
export var CustomTemplateLocationInputType = "customTemplateLocation";
export var PackerVersionInputName = "packerVersion"

export var TemplateVariableResourceGroupName = "resource_group";
export var TemplateVariableStorageAccountName = "storage_account";
Expand Down
18 changes: 14 additions & 4 deletions Tasks/PackerBuildV1/src/packerHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,22 @@ export default class PackerHost implements definitions.IPackerHost {
var installedPackerPath = tl.which("packer", false);
var installedPackerVersion = this._getPackerVersion(installedPackerPath);
console.log(tl.loc("InstalledPackerVersion", installedPackerVersion));
if(!installedPackerVersion ||
utils.isGreaterVersion(utils.PackerVersion.convertFromString(constants.CurrentSupportedPackerVersionString), utils.PackerVersion.convertFromString(installedPackerVersion))) {
var packerVersionString = constants.CurrentSupportedPackerVersionString;
var explicitPackerVersion : boolean= false ;

console.log(tl.loc("DownloadingPackerRequired", constants.CurrentSupportedPackerVersionString, constants.CurrentSupportedPackerVersionString));
if(this._taskParameters.templateType == constants.TemplateTypeCustom && this._taskParameters.packerVersionString && installedPackerVersion != this._taskParameters.packerVersionString) {
packerVersionString = this._taskParameters.packerVersionString;
explicitPackerVersion = true;
anuragc617 marked this conversation as resolved.
Show resolved Hide resolved
}

if(explicitPackerVersion || !installedPackerVersion || utils.isGreaterVersion(utils.PackerVersion.convertFromString(packerVersionString), utils.PackerVersion.convertFromString(installedPackerVersion))) {
if(explicitPackerVersion){
console.log(tl.loc("InstallExplicitPackerVersion", packerVersionString))
} else {
console.log(tl.loc("DownloadingPackerRequired", packerVersionString, packerVersionString));
}
var downloadPath = path.join(this.getStagingDirectory(), "packer.zip");
var packerDownloadUrl = util.format(constants.PackerDownloadUrlFormat, constants.CurrentSupportedPackerVersionString, constants.CurrentSupportedPackerVersionString, this._getPackerZipNamePrefix());
var packerDownloadUrl = util.format(constants.PackerDownloadUrlFormat, packerVersionString, packerVersionString, this._getPackerZipNamePrefix());
tl.debug("Downloading packer from url: " + packerDownloadUrl);
await utils.download(packerDownloadUrl, downloadPath);
console.log(tl.loc("DownloadingPackerCompleted", downloadPath));
Expand Down
3 changes: 2 additions & 1 deletion Tasks/PackerBuildV1/src/taskParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default class TaskParameters {
public packagePath: string;
public deployScriptPath: string;
public deployScriptArguments: string;
public packerVersionString: string;

public additionalBuilderParameters: {};
public customTemplateParameters: {};
Expand All @@ -47,6 +48,7 @@ export default class TaskParameters {
this.customTemplateLocation = tl.getPathInput(constants.CustomTemplateLocationInputType, true, true);
console.log(tl.loc("ParsingCustomTemplateParameters"));
this.customTemplateParameters = JSON.parse(tl.getInput("customTemplateParameters"));
this.packerVersionString = tl.getInput(constants.PackerVersionInputName);
anuragc617 marked this conversation as resolved.
Show resolved Hide resolved
} else {
this.serviceEndpoint = tl.getInput(constants.ConnectedServiceInputName, true);
this.resourceGroup = tl.getInput(constants.ResourceGroupInputName, true);
Expand Down Expand Up @@ -83,7 +85,6 @@ export default class TaskParameters {

this.graphCredentials = this._getAzureADGraphCredentials(this.serviceEndpoint);
}

console.log(tl.loc("ParsingAdditionalBuilderParameters"));
this.additionalBuilderParameters = JSON.parse(tl.getInput("additionalBuilderParameters"));
this.skipTempFileCleanupDuringVMDeprovision = tl.getBoolInput("skipTempFileCleanupDuringVMDeprovision", false);
Expand Down
16 changes: 14 additions & 2 deletions Tasks/PackerBuildV1/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@
{
"name": "Advanced",
"displayName": "Advanced",
"isExpanded": false,
"visibleRule": "templateType = builtin"
"isExpanded": false
},
{
"name": "Output",
Expand Down Expand Up @@ -224,6 +223,7 @@
"required": false,
"defaultValue": "{\"vm_size\":\"Standard_D3_v2\"}",
"groupName": "Advanced",
"visibleRule": "templateType = builtin",
"helpMarkDown": "In auto generated Packer template mode the task creates a Packer template with an Azure builder. This builder is used to generate a machine image. You can add keys to the Azure builder to customize the generated Packer template. For example setting ssh_tty=true in case you are using a CentOS base image and you need to have a tty to run sudo.<br/>To view/edit the additional parameters in a grid, click on “…” next to text box.",
"properties": {
"editorExtension": "ms.vss-services-azure.azure-servicebus-message-grid"
Expand All @@ -235,8 +235,19 @@
"label": "Skip temporary file cleanup during deprovision",
"defaultValue": true,
"groupName": "Advanced",
"visibleRule": "templateType = builtin",
"helpMarkDown": "During deprovisioning of VM, skip clean-up of temporary files uploaded to VM. Refer [here](https://www.packer.io/docs/builders/azure.html#skip_clean)"
},
{
"name": "packerVersion",
"type": "string",
"label": "Packer Version",
"required": false,
"defaultValue": "",
"groupName": "Advanced",
"visibleRule": "templateType = custom",
"helpMarkDown": "Specify the version of Packer to install. This will work only with custom templates."
},
{
"name": "imageUri",
"type": "string",
Expand Down Expand Up @@ -316,6 +327,7 @@
"ResolvedDeployPackgePath": "Resolved deploy package path: %s.",
"ResolvedDeployScriptPath": "Resolved deploy script path: %s.",
"OSNotSupportedForRunningPacker": "OS is not supported for running packer.",
"InstallExplicitPackerVersion": "Packer version %s will be downloaded and installed for running task.",
"DownloadingPackerRequired": "Either packer is not installed or its version is less than %s. Version %s will be downloaded and installed for running task.",
"DownloadingPackerCompleted": "Packer installer downloaded successfully at path: %s.",
"ExtractingPackerCompleted": "Packer extracted successfully at path: %s.",
Expand Down
16 changes: 14 additions & 2 deletions Tasks/PackerBuildV1/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@
{
"name": "Advanced",
"displayName": "ms-resource:loc.group.displayName.Advanced",
"isExpanded": false,
"visibleRule": "templateType = builtin"
"isExpanded": false
},
{
"name": "Output",
Expand Down Expand Up @@ -224,6 +223,7 @@
"required": false,
"defaultValue": "{\"vm_size\":\"Standard_D3_v2\"}",
"groupName": "Advanced",
"visibleRule": "templateType = builtin",
"helpMarkDown": "ms-resource:loc.input.help.additionalBuilderParameters",
"properties": {
"editorExtension": "ms.vss-services-azure.azure-servicebus-message-grid"
Expand All @@ -235,8 +235,19 @@
"label": "ms-resource:loc.input.label.skipTempFileCleanupDuringVMDeprovision",
"defaultValue": true,
"groupName": "Advanced",
"visibleRule": "templateType = builtin",
"helpMarkDown": "ms-resource:loc.input.help.skipTempFileCleanupDuringVMDeprovision"
},
{
"name": "packerVersion",
"type": "string",
"label": "ms-resource:loc.input.label.packerVersion",
"required": false,
"defaultValue": "",
"groupName": "Advanced",
"visibleRule": "templateType = custom",
"helpMarkDown": "ms-resource:loc.input.help.packerVersion"
},
{
"name": "imageUri",
"type": "string",
Expand Down Expand Up @@ -316,6 +327,7 @@
"ResolvedDeployPackgePath": "ms-resource:loc.messages.ResolvedDeployPackgePath",
"ResolvedDeployScriptPath": "ms-resource:loc.messages.ResolvedDeployScriptPath",
"OSNotSupportedForRunningPacker": "ms-resource:loc.messages.OSNotSupportedForRunningPacker",
"InstallExplicitPackerVersion": "ms-resource:loc.messages.InstallExplicitPackerVersion",
"DownloadingPackerRequired": "ms-resource:loc.messages.DownloadingPackerRequired",
"DownloadingPackerCompleted": "ms-resource:loc.messages.DownloadingPackerCompleted",
"ExtractingPackerCompleted": "ms-resource:loc.messages.ExtractingPackerCompleted",
Expand Down