I am moving an application to Azure and I am not sure where I can run my entity framework migrations. We are deploying from github, but I can't run the migrations from the runner due to security policies outside of my control. I need the migrations to run in Azure.
I already have a command line program that runs the migrations, but I am not opposed to running them with the dotnet command (dotnet ef database update).
This is something I only need to run once on each deployment.
I got it to work with a container instance, but that doesn't support using KeyVault references for environment variables. My deployment can't have any secrets and I need to use a KeyVault reference for the connection string.
I thought about a timer-triggered function, but the deployment needs to know that it completed successfully.
What is a good cloud native solution for something that only needs on deployment?
Thanks # Albert Starreveld for the doc.
There are different approaches on EF migrations running in Azure
Code first is one approach
For this approach a Data Model need to be created
*For the below address class a table is created in database and for the person as well with a unique identifier *
Need to use the below NuGet packages to the project
Microsoft.EntityFrameworkCore
Microsoft.EntityFrameworkCore.SqlServer
Microsoft.EntityFrameworkCore.Design
To communicate with the dtabase and model classes
we use the DbContext class, which is a base class provided by EntityFrameworkCore
To run the below command
you need to install the dotnet-ef tool, and run the below command based on your .net framework version
.NET Core 3: dotnet tool install --global dotnet-ef --version 3.1
And database updates can be done by using teh below command
dotnet ef database update
Updating the database in an Azure DevOps pipeline
for Azure DevOps, there is deployment task for SQL databases. And this task is compatible with the EntityFrameworkCore migrations.
By executing the ‘ef migrations script’ command, a SQL file will be generated that can be used by the SqlAzureDacpacDeployment#1 task in Azure pipelines.
for more information, please check the link1 and link2
Related
I'm looking for an automated way for adding & deploying SPFX solution package (*.sppkg) into the SharePoint 2019 (NOT online) app catalog. This is cause and doing the deploying using azure devops (CI/CD) release pipeline.
I found those two below tasks for adding this package:
The first one worked fine in just adding the file to the app catalog but not deploying it, so I had to do it manually.
The second task has the option to write PnP script against SharePoint, but the problem with me is that most of the scripts i found are for SharePoint Online not on premise.
Appreciate your support if you had such situation and got it solved using PnP or something else.
Microsoft's official documentation describes an approach to continuous deployment using Azure DevOps. You can click Implement Continuous Integration and Continuous deployment using Azure DevOps for detailed information. There is no need to write PNP scripts using this method.
Setting up Azure DevOps for Continuous Deployments with a SharePoint
Framework solution requires the following steps:
Creating the Release Definition
Linking the Build Artifact
Creating the Environment
Installing NodeJS
Installing the CLI for Microsoft 365
Connecting to the App Catalog
Adding the Solution Package to the App Catalog
Deploying the Application
Setting the Variables for the Environment
If you just want to use Azure DevOps CD and don't want to use CI, you can skip the second step and upload your build artifacts directly to the repository, and then use them in the release pipeline.
There are some basic scenarion for using pipelines:
You use cloud pipeline (azure, github, etc) with their abilities and their purpuse.
You create own environment with self-hosted pipelines
You add own runner (pipeline agent) to your cloud (azure) environment
So, azure allows you to add own pipeline agent to environment. For example, self-hosting windows agent.
So, I think solution in your case will be:
Install self-hosted agent
Configure agent environment - installing SharePointPnPPowerShell2019
Add agent to your azure environment
Add step to deploy your solution into pipline with using self-hosted agent
This scenario allows you to deploy sppkg solutions without publish your app catalog to internet, because your self-hosted agent will be in the save network as your sharepoint farm.
Azure pipeline deploy steps allow to run powershell on target machines
Prerequisites This task uses Windows Remote Management (WinRM) to
access on-premises physical computers or virtual computers that are
domain-joined or workgroup-joined.
What are the industrial standards for developing a CI/CD pipelines for Azure SQL database?
I have an existing Azure SQL database (DEV instance, includes Schemas, Tables, Functions, Stored Procedures, etc. ) the code for these are hardcoded (meaning, not generated using SSDT compare nor generating script from existing table/SP/Function nor DACPAC/BACPAC file, it's just the code which developers wrote) and maintained in Git repo,
Now, my users want to create another Database using the scripts which were uploaded into Git by developers (Use the code which was uploaded by developers in Git (bitbucket), meaning identifying all the dependencies of DB objects and executing them in order to create new Database, Is this the correct approach? consider this as approach 1),
upon investing lots of time on deployments, I am confused/convinced that it is advised to follow below approach, let's call it as approach 2,
create a solution and clone your existing Git repo in Visual Studio
Import the DB objects from solution explorer and push the solution to Git.
Create a pipeline includes steps as build solution/copy/publish artifact
Create a new release pipeline and use "Azure SQL Data Warehouse deployment" task and link DACPAC file (which is generated from above step dynamically)
Now, for incremental changes, my assumption is, Change the code-> upload in git->generate solution-> build release (the DACPAC file generated from build pipeline will be compared with current QA db and only new changes will be applied, behind the scenes, sqlpackage will be used to compare at release "Azure SQL Data Warehouse deployment task" )
Links I have gone thru:
Configure CD of Azure SQL database using Azure DevOps and Visual Studio
Please correct me if my understanding is wrong,
Thanks a ton,
A DevOps newbie here.
Azure DevOps services provide the Azure SQL database deployment task to deploy an Azure SQL database.
So the approach 2 is the common way. With the task we can deploy an Azure SQL Database using DACPAC or run scripts using SQLCMD.
You can also reference the following links:
Tutorial: Deploy your ASP.NET app and Azure SQL Database code by using Azure DevOps Starter
DevOps for Azure SQL
Azure SQL Database CI/CD with Azure DevOps
I am trying to implement source control for database stored procedures. I am using Azure DevOps and I have added all the stored procedures to an Azure Repo.
I am connecting to the Azure Repo through the team explorer in SSMS. I am working on a branch and once the stored procedure changes are added to the master branch I want the changes to be automatically deployed to the production database.
Is this possible using an Azure pipeline?
Yes you can do it with DACPAC
You can follow the following links,
Use tools that help you integrate and deploy your database along your code. Build better apps on any client OS (Windows, Linux, and macOS) using our graphical user interface and command line tools.
DevOps using SQL Server
Continuous Deployment of SQL
The following link has step by step instructions as to how we can set up Azure pipeline to execute the changes from one database to another:
https://microsoft.github.io/PartsUnlimited/iac/200.2x-IaC-CDAzureSQLdbwithVSTSandVS.html
I have TFS 2015 and i was able to automated the build process from the branch and get the files from the drop folder as shown below:
It has release for multiple projects like Web API and Windows Service
I want Azure VM on which i want to automate the deployment process - continuous delivery.
Deploy the Web API on IIS on Azure VM
Deploy the Windows Services On Azure VM.
Run Scripts SQL.
I have credentials of Azure VM. How i can perform the three above steps.
I have worked on a similar problem in the past so can probably help you out (MSFT, if it helps).
Web Api on IIS on Azure VM
This is almost completely automated in the form of WinRM - IIS Web App Deployment task that you can find and add in your release definition. The link provides complete instructions on what parameters to provide and tweaks to be done for Azure VM compared to on-premise ones. There are a few prerequisites to running this task, like installing and configuring IIS on the VM which the documentation discusses in detail. As a necessary input to this task, you need to provide the web deploy package which I am assuming was generated as your build output. If not, you can refer to this SO post to get the required output. If you have parameters like connection strings that you wish to modify at deploy time, using a parameters.xml file in the above task.
Windows Service on Azure VM
There is no completely automated task for this requirement, but it is pretty straight-forward. It can be achieved by using the PowerShell on Target Machines task along with Azure File Copy task. For the first task, all that is required as input is the .exe of the windows service that you wish to deploy, which should be generated as the output of your build process (build artifacts). Much of the remote machine inputs for this task is similar to the previous one so you should not have any problem there. You will need to check-in the Powershell script that does the actual windows service installation, in your source code as part of the same windows service project (copy local = True). This will ensure that as the build output, you will have access to the powershell script which you can use in the second task. Azure File Copy is required to copy your powershell script to the Azure VM so that the Powershell task can execute it. Let's assume you copied the powershell script to a folder C:\Data\ on the Azure VM.
$serviceName = "MyWindowsService"
$exeFullName = "path\\to\\your\\service.exe"
$serviceDisplayName = "MyWindowsService"
$pss = New-Service $serviceName $exeFullName -DisplayName $serviceDisplayName
-StartupType Automatic
Add this content to the checked in powershell file and name it installWindowsService.ps1. Then in the powershell task provide the path of the powershell file to execute as C:\Data\installWindowsService.ps1.
Run SQL Scripts on Azure VM
I haven't personally worked on this so the best I can do is point you in the right direction. If you are using DACPAC for your SQL deployment, you can use the WinRM - SQL Server Database Deployment task. If you just intend to execute scripts, use the remote powershell task from above and refer this post that will help you with running SQL commands through powershell script
Seems you want the CD release process picks up the artifacts published by your CI build and then deploys them to your IIS servers/Windows Services on Azure VM.
If you've just completed a CI build, then you should create a new release definition that's automatically linked to the build definition.
Open the Releases tab of the Build & Release hub, open the + drop-down in the list of release definitions, and choose Create release definition.
For 2, write a powershell script to handle this, ensure build outputs
were available to copy from the ‘Drop’ folder on the build and that
they are copied to C:\xxx\ on the target VM(s). More detail steps
please refer this blog.
For 3, you could use Azure SQL Database Deployment task. Either
select the SQL Script file on the automation agent or on a UNC path
that is accessible to the automation agent. Or directly enter the
InLine SQL Script to run against the Azure SQL Server Database. Also take a look at the tutorial.
Maybe not all the task is fully Compatible with TFS2015 version, you could upgrade your TFS version to get more new features or customize your own build/release task to handle it.
I want to run tests using real SQL databases. The SQL server and the databases would be on Azure. I'm trying to configure a build definition on VSTS where the tasks would set up an Azure resource group with the databases, set the connection strings on my solution and run the Entity Framework Core migrations to the databases. After the tests a task should delete the resource group.
I created an Azure resource group with the databases I need and downloaded the PowerShell deployment files, the script, template.json and so on.
The PowerShell script task can have an inline script or a path to the script. Should I add the Powershell scripts to the solution so that the VSTS could access them? The inline script option seems to be for small few line scripts and the Azure deployment is quite big with multiple files.
Setting up the connection strings shouldn't be too difficult. Several people suggest using the Replace Tokens task from the market place.
I'm not sure how to run the database migrations after that. Can I run the migrations on PowerShell script task? How can I ensure that the needed cmdlets work?
Since the script is quite big, you can’t use Inline script, you can add it to the project or other path of server (Add additional mapping for different path).
Regarding database migration, if you enabled EF migration in a web app, you can create a publish profile (web deploy package) with database migration enabled, then publish/deploy with /p:DeployOnBuild=true /p:PublishProfile=[profile name];DesktopBuildPackageLocation="$(build.artifactstagingdirectory)\webEF.zip" MSBuild arguments, then deploy package to Azure Web APP through Azure Web Deploy task.