Post Deployment Script in Azure Web App for Containers - azure

Is it possible to run a post-deploy script inside a container in Azure Web App for Containers(not the "regular" Web App with Kudu).
I have an ARM template that creates some resources, including a Web App for Containers where I use a Dockerhub image. I want to run a post-deployment script inside the container(a database migration script if that matters("bundle exec rake db:migrate" specifically)).
I can put the command into the Startup File in the Container Settings in the Azure Portal. That runs the command successfully, but it doesn't start up the container normally. So, I have to remove the Startup File migration command after it completes and then restart the Web App for it to start up normally. This is not optimal, neither is running the migration command on every startup/restart and then starting up the webserver.
This type of post-deploy script option is available in Heroku's template deployments, using the scripts object and the postdeploy key in it. See https://devcenter.heroku.com/articles/app-json-schema#scripts.
Does such a post-deploy script option exist for Azure Web App for Containers?
If not, is there a simpler/better way to run the migrate command than what I'm currently doing?

Related

Trying to get Azure Devops pipeline to run the app dll

I have azure devops publishing a dotnet core web app to an AWS server, but the app serilog logs are not kicking in because even though the DLLS etc are updated the myapp.dll is not re-started, so the logging setup code in program.cs is not executed.
If I run the app in powershell using "dotnet myapp.dll" then the logging file appears but that starts a seperate process on a different port... so it doesnt help.
The app runs under IIS on the server and Im not sure if this is a devops issue or something i need to do in IIS..
I added this as the last step to the pipeline but I get an error
You misspelled a built-in dotnet command.
You intended to execute a .NET Core program, but dotnet-.\myWork.dll does not exist.
You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.
The pipeline doesn't start your application. Even if it worked, you would have an app running on the Agent that's executing the pipeline, not on your server.
If you want the app hosted on your server, I'd start with Publish an ASP.NET Core app to IIS tutorial.
Get it deployed on your server manually and ensure it's running correctly. But don't do right-click publish - use commandline all the way.
Once you know what are the necessary steps (and what might go wrong), you can start automating it.

wwwroot not always updating on Azure Webapp

I have accessed my site via Kudu # my-site.scm.azurewebsites.net/wwwroot/
I've noticed that the files in webroot are not the most up-to-date.
I am updating the site via github and Azure CLI.
My repo is hosting the correct files.
When I SSH on the Linux server, and cat <updated file>, it is up-to-date and reflective of the files in my repo.
How do I update the wwwroot?
Try explicitly stopping and then re-starting the webapp if "Restart" from the management portal did not solve the issue.
Possible cause: Azure App Service Deploy task version
Make sure you have the latest. linux azure app service is different from windows azure app service. Linux app service don't have default so you need to set. So follow the steps below:
Use WebDeploy/MSDeploy to deploy my web app. You need to set an app setting called WEBSITE_WEBDEPLOY_USE_SCM to false.
OR
When the Select deployment method option is not checked, the task appears to prefer the Run From Package option. The solution for us now isto select the option and choose Web Deploy as our deployment method.
If Git deployment fails to your Linux web app, choose one of the following options to deploy your application code:
Use the Continuous Delivery (Preview) feature: You can store your
app's source code in an Azure DevOps Git repo or GitHub repo to use
Azure Continuous Delivery. For more information, see How to configure
Continuous Delivery for Linux web app.
Use the ZIP deploy API (refer): To use this API, SSH into your web app and go
to the folder where you want to deploy your code. Run the following
code:
curl -X POST -u --data-binary #
https://{your-sitename}.scm.azurewebsites.net/api/zipdeploy
If you get an error that the curl command is not found, make sure you install curl by using apt-get install curl before you run the previous curl command.
You'll need to specify a startup script for the type of app you are
running.
Download Azure Storage Explorer, free tool to conveniently manage your Azure cloud storage resources from your desktop. (also to virtual web app directories)

Is necessary to restart node in every deploy to Azure Web App?

I build and deployed a Vue/nuxt web app to Azure Web App by configuring Azure DevOps build and release pipelines.
The app runs on top of node and Express configuration. I start the app on the server by typing: npm run start on Kudu's CMD. Then the start script is set in the package.json file to launch the command: node server/index.js.
On the other hand, the build pipeline is configured to trigger a new build of the app (npm run build) when a new commit occurs and then the release pipeline catches the output and deploys it to Azure by Zip Deploy mechanism ("Azure App Service deploy" task).
So far I found not in the need to restart neither the Azure Web App nor the node process to update the app. In some ocassion I did found some strange error behaviour I solved by killing the process and restarting all over again.
In an official and proper way manner should I do this every time a new build is released? And how can I do it? I can gues on how to restart node via post deployment actions but what about killing the process? I must kill otherwise the new process port number will collide with the running one.
As I know there exists some circumstances under which an application deployment might result in a restart.
See Deployment vs. runtime issues, App Service deploys files to the wwwroot folder. It never directly restarts your app.
So i think it's necessary when your changes in code do not start to work in your application, but if it works well when sometimes the restart occurs, you don't need to do the restart manually. Also, if you want to restart the app service, you can try Azure App Service Manage Task or restart it in Azure web portal.

Azure Devops - How to run a powershell script on an App Service post-deploy?

I'm struggling to understand how to run a powershell script (it just runs an exe) on the App Service after deployment using Azure Devops.
FYI - the exe just reads some config info in the web.config and does some database updates. So it needs access to the transformed web.config and the SQL Server database that the App Service has.
I've tried adding a Powershell step using a Release Pipeline deployment task, but it seems to only run on the Agent, which does not have the context that the exe needs.
I can run the script manually using the Kudu command line window tool, but I need to automate this thing.
I've seen a few SO articles like this: How to add a custom post deployment script to azure websites? or Kudu post-deployment commands not running but I think that only works when you use the inbuilt deployment mechanism for App Services. ie - I couldn't get it to trigger the script in post-deploy from Azure Devops.
This is in the comments above, but if people find it useful, the answer to this is
Using the Azure App Service Deploy task, expand Post Deployment Action, there's an option to run a script (or inline write one).
This will be executed as part of the app service deployment and should allow you to do what you want. It's run at the wwwroot folder so the files need to be present in your actual deployment (zip/folder).

Azure App Service ARM Templates - Run Command in the Console

I am currently building an ARM Template that deploys the following.
App Service Plan
App Service
MS Deploy .NET Core Application on the App Service
The problem is that after the .NET Core Application is deployed I want to execute a command in the console. I have tried a couple of different ways to do it via the CustomScriptExtension, but I keep getting :
"No route registered for '/CustomScriptExtension?api-version=2015-06-15'"
Which makes me think that the Custom Script Extensions are supported for VMs only and not for App Services (I am a bit new to ARM Templating and there is nothing useful I could find in the Azure Quickstart Templates).
Any suggestions on how I can execute a simple command in the App Service command promt via an ARM Template ?
I use the runcommand option of msdeploy to run a command after deployment.
In my case I added a manifest.xml to the root of the zip file that will be deployed:
<MSDeploy.iisApp>
<runcommand path="move D:\home\site\wwwroot\applicationHost.xdt D:\home\site\" dontUseCommandExe="true" MSDeploy.MSDeployKeyAttributeName="path" />
</MSDeploy.iisApp>
The "MSDeploy.MSDeployKeyAttributeName="path"" is important. More details here.
The content of the path attribute will be executed on the remote mashine.
I hope this helps,
KirK

Resources