How to execute a script on packer build failure? - packer

In my current template.json, I am executing a number of scripts with the shell provisioner. For example:
{
"type": "shell",
"scripts": [
"scriptA.sh",
"scriptB.sh"
]
},
{
"type": "shell",
"scripts": [
"scriptC.sh"
]
}
The current behavior I have observed is that, if there is a error in scriptA.sh, subsequent scripts do not get executed. However, I would like to have scriptC.sh no matter what. Is there another setting or proper location of scriptC.sh that would allow it to be executed on success or failure of packer build?
Although the 'packer build -on-error=cleanup' is present, I have not seen an option to add any additional clean up behavior on error.
Edit 1: I suppose I could combine all the scripts into one, perform a "try, catch, finally", and provide an exit code. However, for sake of readability and reusability, I would prefer to keep the scripts separate.

Related

Deploying ARM template with 2 hostnamebindings returns conflict error can't modify because another operation is in progress

I am trying to deploy an ARM template through Azure DevOps. I've tried doing a test deployment (Test-AzResourceGroupDeployment) through PowerShell without any issues.
This issue has persisted for several weeks, and i've read some posts stating it dissapeared after a few hours or after a day, however this has not been the case for me.
In Azure DevOps my build is succeeding just fine. But when i try to create a release through my release pipeline using the resource "Azure resource group deployment" it will fail stating the error:
"Code": "Conflict",
"Message": "Cannot modify this site because another operation is in progress. Details: Id: 4f18af87-8848-4df5-82f0-ec6be47fb599, OperationName: Update, CreatedTime: 9/27/2019 8:55:26 AM, RequestId: 691b5183-aa8b-4a38-8891-36906a5e2d20, EntityType: 3"
Update
I have later noticed that the error surfaces when trying to deploy my hostNameBindings for the site.
I have 2 different hostNameBindings in my template which causes the failure.
It fails apparently because it tries to deploy both of them at the same time, though i am not aware of an apparent fix for this so any help would still be appreciated!
I tried to use the copy function but as far as i know that will make an exact copy for both hostNameBindings which is not what i need. first of all they have different names and properties, anyone got a fix for this?
Make the one hostNameBindings depend on the other host name binding. Then they will be executed 1 after another and you should not get the same error message.
"dependsOn": [
"[resourceId('Microsoft.Web/sites/', variables('websitename'))]",
"[resourceId('Microsoft.Web/sites/hostNameBindings/',variables('websitename'), variables('firstbindingame-aftertheslash-sowithoutthewebsitename'))]"
],
Look like people already notice this issue and trying to fix it.
https://status.azure.com/
I had the same issue when using the Copy function in order to add multiple Custom Domains. Thanks to David Gnanasekaran's blog I was able to fix this issue.
By default the copy function will execute in parallel. By setting the mode to serial and setting the batchSize to 1 I did not receive any operation is in progress errors.
Here is my piece of ARM template to set the custom domains.
"copy": {
"name": "hostNameBindingsCopy",
"count": "[length(parameters('customDomainNames'))]",
"mode": "Serial",
"batchSize": 1
},
"apiVersion": "[variables('webApiVersion')]",
"name": "[concat(variables('webAppName'), '/', parameters('customDomainNames')[copyIndex()])]",
"type": "Microsoft.Web/sites/hostNameBindings",
"kind": "string",
"location": "[resourceGroup().location]",
"condition": "[greater(length(parameters('customDomainNames')), 0)]",
"dependsOn": [
"[resourceId('Microsoft.Web/sites', variables('webAppName'))]"
],
"properties": {
"customHostNameDnsRecordType": "CName",
"hostNameType": "Verified",
"siteName": "parameters('webAppName')"
}

VS code API documentation isn't clear on how to read json customizable values

I ahve read both the online docuemntation and the source code for the VS code API and it is still not clear to me how to read the JSON user settings and workpsace settings. I ahve tried to look for examples but I can't find something that just displays how to do this.
In essence I want a value in the settings called "maximum". I want then to read the value of maximum from the TS scrypt.
The documentation has led me to write the following two lines in the activate function:
const config = vscode.workspace.getConfiguration('extension', vscode.window.activeTextEditor.document.uri);
vscode.window.showInformationMessage(config.has('configuration').toString());
In the package.json file I have added, under contributes:
"configuration": {
"maximum":
{
"type": ["integer"],
"default": 40,
"description": "The level of alignment, how far the titles will extend horizontally"
}
}
However I get false as an output.
I have tried multiple different outputs and the only time I got true was when the parameter of the first function was 'launch' and the second parameters was 'configurations'.
I do nmot understand from the documentation alone what the parameters need to be. Nor where should the value be specified.
You get False as output because the configuration keyword in the package.json indicates only the configuration contribution point of your extension.
I would suggest you to adopt the vscode example to your needs:
"contributes": {
"configuration": {
"type": "object",
"title": "This is my config",
"properties": {
"myExtensionName.maximum": {
"type": "integer",
"default": 40,
"description": "The level of alignment, how far the titles will extend horizontally."
}
}
}
}
Now if you run the following you should get returned true:
const config = vscode.workspace.getConfiguration('myExtensionName');
vscode.window.showInformationMessage(config.has('maximum').toString());
I think you can not separately get the workspace and user settings, because vscode's pattern is that the workspace settings override the user settings.
From the docs:
VS Code provides two different scopes for settings:
User Settings - Settings that apply globally to any instance of VS Code you open.
Workspace Settings - Settings stored inside your workspace and only apply when the workspace is opened.
Workspace settings override user settings.

Azure Functions: How do I control development/production/staging app settings?

I've just started experimenting with Azure functions and I'm trying to understand how to control the app settings depending on environment.
In dotnet core you could have appsettings.json, appsettings.development.json etc. And as you moved between different environments the config would change.
However from looking at Azure function documentation all I can find is that you can set up config in the azure portal but I can't see anything about setting up config in the solution?
So what is the best way to manage build environment?
Thanks in advance :-)
The best way, in my opinion, is using a proper build and release system, like VSTS.
What I've done in one of my solutions is creating an ARM template of my Function App and deploy this using a release pipeline with VSTS RM.
This way you can just add a value to the template.json, like the one from below.
"appSettings": [
// other entries
{
"name": "MyValue",
"value": "[parameters('myValue')]"
}
You will need another file, called parameters.json which will hold the values. This file looks like so (at the moment).
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"name": {},
"storageName": {},
"location": {},
"subscriptionId": {}
}
}
Back in VSTS you can just change/override the values of these parameters in the portal.
By using such a workflow you will get a professional CI/CD implementation where no one has to bother themselves with the actual secrets. They are only known to the system administrators.

Composer fails update on a require from git repository where branch name starts with digit and has a period

I've forked the repository at https://github.com/laravel-doctrine/orm and I'm trying to add it as a require in a composer.json script.
My json (the relevant bits) is as follows:
"repositories": [
{
"type": "git",
"url": "https://github.com/MyGHAccount/laravel-doctrine.git"
},
.
.
.
"require": {
.
.
.
"laravel-doctrine/orm": "dev-1.2"
Composer generates the following error:
Your requirements could not be resolved to an installable set of packages.
Problem 1
- The requested package laravel-doctrine/orm could not be found in any version, there may be a typo in the package name.
Potential causes:
- A typo in the package name
- The package is not available in a stable-enough version according to your minimum-stability setting see
https://getcomposer.org/doc/04-schema.md#minimum-stability for more
details.
Read https://getcomposer.org/doc/articles/troubleshooting.md for
further common problems.
The actual branch name from https://github.com/laravel-doctrine/orm is 1.2.
This SO question leads me to believe that Composer has no problem with periods in the branch name, but can't deal with branches starting with a digit.
I have found a workaround to this in that I simply renamed my branch on GitHub to master; I just want to know if there's a proper way to do this with Composer without the workaround.
Issue 1
This doesn't make sense: https://github.com/MyGHAccount/laravel-doctrine/orm.git.
In case you forked the original repository, the fork has another URL and not the one you posted here.
There are only two levels: github.com/vendor/repo.
It's possibly https://github.com/MyGHAccount/orm.git.
Issue 2
You're not using Composers verbose mode. Please use Composer's verbose mode (-vvv) and let Composer tell you the package resolution story and it's problems. You might be able to figure the issue out yourself.
Issue 3
Before - using packagist package:
composer.json:
{
"require": {
"laravel-doctrine/orm": "1.2"
}
}
After - overriding with your own fork:
composer.json:
{
"repositories": [
{
"type": "git",
"url": "https://github.com/your-account/orm"
}
],
"require": {
"laravel-doctrine/orm": "1.2"
}
}

Grunt doesn't run json_server task from grunt-json-server

I am using the configuration the npm page gives an example for, yet when I try to run the task using either grunt.run.task (['json_server']) or in concurrent: { server: { tasks [ 'json_server'] } }, grunt doesn't even print out the task name in the console. It doesn't even give me an error if I remove the db file it tries to point to.
See: https://github.com/tfiwm/grunt-json-server/issues/4
The library uses registerMultiTask; when changed to registerTask, it worked fine for me.