Migrate database when deploying to Azure App Service - azure

I'm using the ASP.NET Core & Angular startup template from ASP.NET Boilerplate with Multi-Tenancy disabled: 1 database with a single tenant(Default).
I'm also using TeamCity to build/test/publish the projects available in the startup template so I end up with 3 NuGet packages that are getting pushed to Octopus Deploy:
API (Host project, ASP.NET Core Web Application)
Migrator (Console application, capable of migrating the database(s))
UI (Angular App)
I want to deploy this setup to Azure with Octopus Deploy(self hosted, v2018.9.0) in the following way using 2 App Services(Host & UI) and 1 Azure SQL database(Host):
Take the UI and API applications offline, displaying a friendly maintenance message while updating the projects.
Migrate the database using the Migrator package
Deploy the API application package
Deploy the UI application package
Put the API application online, maybe some more tests to check that it's working correctly
Put the UI application online.
If all this was on-prem, I would have no questions. It's the Azure part that I can't figure out because I don't know how to do these things on Azure via Octopus Deploy:
Put an Azure App Service offline/online (using an app_offline.htm file)
Deploy the Migrator package to the API Azure App Service in a special folder(so that I don't overwrite the API deployment) and run the migrator: dotnet [migrator.dll] -q
I tried using the Octopus Deploy "Deploy an Azure Web App" but this step won't let me also deploy the migrator package and run it before the API package is deployed. Or does it? I don't know how.
I tried using the "Run an Azure PowerShell script" but this executes on the Octopus Deploy server and not on the Azure App Service environment right?
Maybe there are other, even better, approaches deploying this setup to Azure?

You can use App service slots to swap in/out version of your logical applications. When you swap there's a warming up that occurs and no loss of traffic.
So basically deploy to backup slot, then swap production with backup slot.
For the db I don't think your strategy is valid. There are some assumptions you are making that will not make your life easy. I would look at handling the db deployment separately with no breaking changes but that's my opinion.
I'm not familiar with Octopus or TeamCity so I won't go into details about those.

Related

Azure Zero-downtime Deployments - separate FE/BE App Services

I have an application that consists of an Angular 2+ frontend deployed on a separate App Service to my .NET Core backend (per environment).
I'm investigating zero-downtime deployments with Azure App Service staging slots, however I don't understand how I'd have this setup in my case, because:
My FE and BE are deployed via DevOps CI/CD automation, and are built + deployed in an Azure Pipeline - meaning my Angular app has its API URL set in whichever environment.ts file is chosen (depending on which environment is being deployed to).
What is the correct way to achieve having a zero-downtime deployment setup in Azure in this case?
You are correct in that you won't be able to use deployment slots with your Angular app, since the configuration is bundled with the code. You can use Azure Static Web App with CDN to achieve this.
For your backend, deployment slots with auto swap enabled should get you what you're looking for.
https://learn.microsoft.com/en-us/azure/storage/blobs/static-website-content-delivery-network
https://learn.microsoft.com/en-us/azure/app-service/deploy-staging-slots

Deploying several webjobs and a webapi to a single App Service on Azure with Devops

I am trying to deploy 4 or more webjobs and a webapi to a single app service on Azure, using Azure Devops.
I have read previously that to deploy a webjobs i needed to prp my artefact with the following tree organisation : webjobs/app_data/jobs/continuous ou webjobs/app_data/jobs/triggered
So i made it so that my build prepared the artefacts organised like this :
artefact
/WebApi
/...dlls and stuff
/webjob
/app_data
/jobs
/continuous
/webjob1
/...
/webjob2
/...
/triggered
/webjob3
/...
/Webjob4
/...
When i deploy webjobs, using the task Azure App Service Deploy, and pointing the folder webjob, i can see my webjobs being deployed all well.
But when i try to deploy the webApi as well, it doesn't work.
I first tried to deploy webjobs and webapi in two separated task (still using Azure App Service Deploy ) but one was overwritting the others.
I then tried using one task Azure App Service Deploy, by providing the top folder containing WebApi and webjob, but this doesn't seem to work.
I suppose there is a simple thing to do here, but i don't seem to be able to work it out ...
Is there any people who have managed to do this ?
Check this case: How do you deploy an Azure WebJob and App to the same App Service via VSTS?
You need to associate webjobs with web app, by right clicking your Web App project in Visual Studio and select Add > Existing Project as Azure WebJob and follow the wizard.
The webjobS are included in the web app package, then you just need to deploy web app to azure app service.
It will generate webjob’s package too during publishing (that why there are two zip files), but you just need to specify web app package in Azure App Service deploy task. (Check Publish using Web Deploy option). Make sure the "Exclude files from the App_data folder" is unchecked:

Azure function app deploy and release pipeline error

I pushed my .net core function application using visual studio and now setting up release pipeline. I can publish and execute the application just fine and it works great on the Azure portal. However when I see the builds for releases in azure-devOps that slot fails with the following error.
2019-06-19T23:21:33.3543380Z ##[error]Error: Deployment of msBuild generated package is not supported. Change package format or use Azure App Service Deploy task. D:\a\r1\a\_...AVFunctionCore.zip
I am not sure where I need to check in my setup to even start diagnosing the issue.
Here are the pipeline steps.
I create a new stage and then select a template of type (Azure app service deployment)
Under tasks
App type is Function App on Windows
Give the app name, resource group , give the slot and
package folder as
$(System.DefaultWorkingDirectory)/**/AVFunctionCore.zip
Everything else on this is left as default.
Azure function app deploy and release pipeline error
According to the error message:
Deployment of msBuild generated package is not supported. Change
package format or use Azure App Service Deploy task.
It seems you are not using the correct task to publish the generated package. Since the generated package is .zip, you can try the suggestion as error message said use Azure App Service Deploy task.
Azure App Service Deploy task:
Use this task in a build or release pipeline to deploy to a range of
App Services on Azure. The task works on cross-platform agents running
Windows, Linux, or Mac and uses several different underlying
deployment technologies.
The task works for ASP.NET, ASP.NET Core, PHP, Java, Python, Go, and
Node.js based web applications.
The task can be used to deploy to a range of Azure App Services such
as:
Web Apps on both Windows and Linux
Web Apps for Containers Function
Apps on both Windows and Linux
Function Apps for Containers
WebJobs
Apps configured under Azure App Service Environments
Check this blog Visual Studio 2017 Tools for Azure Functions and Continuous Integration with VSTS for some more details.
Hope this helps.
I get predefined pipeline from VS integration. So for those you have the same case:
In GUI/Classic mode Release page -> edit pipeline
Edit task in stage section (this is responsible for deploying)
Replace Azure Web App task with Azure App Service deploy
I have more than one project (web api + azure function) in my solution. For the web app I used the zip file, but for the azure function to work I needed to publish the whole folder.
Azure Function
Package or folder:
$(System.DefaultWorkingDirectory)/_Backend/drop
Web Api
Package or folder:
$(System.DefaultWorkingDirectory)/_Backend/drop/ClientAPI.zip

Azure App Service API Deployment requires a restart

I use the Deploy Azure App Service VSTS task to deploy an asp dotnet core API to an Azure API app using the Publish using Web Deploy option. The task runs without any errors but somehow I have to restart the API to get the new version.
Is that intended? Is there any flag that I can set to immediately get the deployment "live"? As a workaround I can add a restart task but I hope there is another way....
Are you using App Service Local Cache? https://learn.microsoft.com/en-us/azure/app-service/app-service-local-cache
If you are you will need to remove WEBSITE_LOCAL_CACHE_OPTION = Always property of your web app to have your publish show right away.
Otherwise you can always use a deployment slot to test your app before swapping in production.

Upgrading and deploying ASP.NET RC1 project to RC2 in web app

I have a web app in ASP.NET Core RC1 in production and deployed in Azure with thousand of users using day a day.
I'm now upgrading my web project to RC2, following the tutorials I have found on Google (for example: Scott Blog, Official Doc, Tutorial1, Tutorial2, Tutorial3)
I need deploy the version RC2 when I have finished the upgrade without lose service to my users.
Do I need to create a new web app for the RC2 version or can I deploy in the same web app?
What is the way to implement that?
Thanks.
You can use Azure Deployment Slots. Develop and test your web application on you local, push it into the Staging slot. If it works fine there just swap the Staging Slot with the Production Slot. If the test fails there, don't worry, your actual application will still be running in production. Swap them carefully.
If you are using a storage with your web app, create a test (if possible) database in Azure for Staging Slot. If database is not an issue, you can use the same database with Staging and Production. Make sure that it works fine on your local system first.

Resources