简体   繁体   中英

Migrate database when deploying to Azure App Service

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:

  1. API (Host project, ASP.NET Core Web Application)
  2. Migrator (Console application, capable of migrating the database(s))
  3. 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):

  1. Take the UI and API applications offline, displaying a friendly maintenance message while updating the projects.
  2. Migrate the database using the Migrator package
  3. Deploy the API application package
  4. Deploy the UI application package
  5. Put the API application online, maybe some more tests to check that it's working correctly
  6. 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:

  1. Put an Azure App Service offline/online (using an app_offline.htm file)
  2. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM