-
Notifications
You must be signed in to change notification settings - Fork 322
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #356 from alexdrenea/feature/ef-migrations
Feature/ef migrations
- Loading branch information
Showing
20 changed files
with
6,332 additions
and
1,504 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See LICENSE file in the project root for license information. | ||
|
||
# | ||
# Powershell script to deploy the resources - Customer portal, Publisher portal and the Azure SQL Database | ||
# | ||
|
||
Param( | ||
[string][Parameter(Mandatory)]$WebAppNamePrefix, # Prefix used for creating web applications | ||
[string][Parameter(Mandatory)]$ResourceGroupForDeployment # Name of the resource group to deploy the resources | ||
) | ||
|
||
Function String-Between | ||
{ | ||
[CmdletBinding()] | ||
Param( | ||
[Parameter(Mandatory=$true)][String]$Source, | ||
[Parameter(Mandatory=$true)][String]$Start, | ||
[Parameter(Mandatory=$true)][String]$End | ||
) | ||
$sIndex = $Source.indexOf($Start) + $Start.length | ||
$eIndex = $Source.indexOf($End, $sIndex) | ||
return $Source.Substring($sIndex, $eIndex-$sIndex) | ||
} | ||
|
||
$ErrorActionPreference = "Stop" | ||
$WebAppNameAdmin=$WebAppNamePrefix+"-admin" | ||
$WebAppNamePortal=$WebAppNamePrefix+"-portal" | ||
$KeyVault=$WebAppNamePrefix+"-kv" | ||
|
||
#### THIS SECTION DEPLOYS CODE AND DATABASE CHANGES | ||
Write-host "#### Deploying new database ####" | ||
$ConnectionString = az keyvault secret show ` | ||
--vault-name $KeyVault ` | ||
--name "DefaultConnection" ` | ||
--query "{value:value}" ` | ||
--output tsv | ||
|
||
#Extract components from ConnectionString since Invoke-Sqlcmd needs them separately | ||
$Server = String-Between -source $ConnectionString -start "Data Source=" -end ";" | ||
$Database = String-Between -source $ConnectionString -start "Initial Catalog=" -end ";" | ||
$User = String-Between -source $ConnectionString -start "User Id=" -end ";" | ||
$Pass = String-Between -source $ConnectionString -start "Password=" -end ";" | ||
|
||
Write-host "## Retrieved ConnectionString from KeyVault" | ||
Set-Content -Path ../src/AdminSite/appsettings.Development.json -value "{`"ConnectionStrings`": {`"DefaultConnection`":`"$ConnectionString`"}}" | ||
|
||
dotnet-ef migrations script ` | ||
--idempotent ` | ||
--context SaaSKitContext ` | ||
--project ../src/DataAccess/DataAccess.csproj ` | ||
--startup-project ../src/AdminSite/AdminSite.csproj ` | ||
--output script.sql | ||
|
||
Write-host "## Generated migration script" | ||
|
||
Write-host "## !!!Attempting to upgrade database to migration compatibility.!!!" | ||
$compatibilityScript = " | ||
IF OBJECT_ID(N'[__EFMigrationsHistory]') IS NULL | ||
-- No __EFMigrations table means Database has not been upgraded to support EF Migrations | ||
BEGIN | ||
CREATE TABLE [__EFMigrationsHistory] ( | ||
[MigrationId] nvarchar(150) NOT NULL, | ||
[ProductVersion] nvarchar(32) NOT NULL, | ||
CONSTRAINT [PK___EFMigrationsHistory] PRIMARY KEY ([MigrationId]) | ||
); | ||
IF (SELECT TOP 1 VersionNumber FROM DatabaseVersionHistory ORDER BY CreateBy DESC) = '2.10' | ||
INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion]) | ||
VALUES (N'20221118045814_Baseline_v2', N'6.0.1'); | ||
IF (SELECT TOP 1 VersionNumber FROM DatabaseVersionHistory ORDER BY CreateBy DESC) = '5.00' | ||
INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion]) | ||
VALUES (N'20221118045814_Baseline_v2', N'6.0.1'), (N'20221118203340_Baseline_v5', N'6.0.1'); | ||
IF (SELECT TOP 1 VersionNumber FROM DatabaseVersionHistory ORDER BY CreateBy DESC) = '6.10' | ||
INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion]) | ||
VALUES (N'20221118045814_Baseline_v2', N'6.0.1'), (N'20221118203340_Baseline_v5', N'6.0.1'), (N'20221118211554_Baseline_v6', N'6.0.1'); | ||
END; | ||
GO" | ||
|
||
Invoke-Sqlcmd -query $compatibilityScript -ServerInstance $Server -database $Database -Username $User -Password $Pass | ||
Write-host "## Ran compatibility script against database" | ||
Invoke-Sqlcmd -inputFile script.sql -ServerInstance $Server -database $Database -Username $User -Password $Pass | ||
Write-host "## Ran migration against database" | ||
|
||
Remove-Item -Path ../src/AdminSite/appsettings.Development.json | ||
Remove-Item -Path script.sql | ||
Write-host "#### Database Deployment complete ####" | ||
|
||
|
||
|
||
Write-host "#### Deploying new code ####" | ||
|
||
dotnet publish ../src/AdminSite/AdminSite.csproj -v q -c debug -o ../Publish/AdminSite/ | ||
Write-host "## Admin Portal built" | ||
dotnet publish ../src/MeteredTriggerJob/MeteredTriggerJob.csproj -v q -c debug -o ../Publish/AdminSite/app_data/jobs/triggered/MeteredTriggerJob --runtime win-x64 --self-contained true | ||
Write-host "## Metered Scheduler to Admin Portal Built" | ||
dotnet publish ../src/CustomerSite/CustomerSite.csproj -v q -c debug -o ../Publish/CustomerSite | ||
Write-host "## Customer Portal Built" | ||
|
||
Compress-Archive -Path ../Publish/CustomerSite/* -DestinationPath ../Publish/CustomerSite.zip -Force | ||
Compress-Archive -Path ../Publish/AdminSite/* -DestinationPath ../Publish/AdminSite.zip -Force | ||
Write-host "## Code packages prepared." | ||
|
||
Write-host "## Deploying code to Admin Portal" | ||
az webapp deploy ` | ||
--resource-group $ResourceGroupForDeployment ` | ||
--name $WebAppNameAdmin ` | ||
--src-path "../Publish/AdminSite.zip" ` | ||
--type zip | ||
Write-host "## Deployed code to Admin Portal" | ||
|
||
Write-host "## Deploying code to Customer Portal" | ||
az webapp deploy ` | ||
--resource-group $ResourceGroupForDeployment ` | ||
--name $WebAppNamePortal ` | ||
--src-path "../Publish/CustomerSite.zip" ` | ||
--type zip | ||
Write-host "## Deployed code to Customer Portal" | ||
|
||
Remove-Item -Path ../Publish -recurse -Force | ||
Write-host "#### Code deployment complete ####" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,17 @@ | ||
## Install the Azure Marketplace SaaS Accelerator using Azure Cloud Shell | ||
|
||
You can install the SaaS Accelerator code using a __single command__ line within the Azure Portal ([video tutorial](https://youtu.be/BVZTj6fssQ8)). | ||
|
||
1. Copy the following section to an editor and update it to match your company preference. Replace `SOME-UNIQUE-STRING` with your Team name or some other random string. | ||
|
||
1. Copy the following section to an editor and update it to match your company preference. | ||
- Replace `SOME-UNIQUE-STRING` with your Team name or some other meaningful name for your depth. (Ensure that the final name does not exceed 24 characters) | ||
- Replace `[email protected]` with a valid email from your org that will use the portal for the first time. Once deployed, this account will be able to login to the administration panel and give access to more users. | ||
- [optional] Replace `MarketplaceSaasGitHub` under `ResourceGroupForDeployment` with a value that matches your comany's naming conventions for resource groups | ||
- [optional] Replace `East US` with a region closest to you. | ||
|
||
``` powershell | ||
dotnet tool install --global dotnet-ef; ` | ||
git clone https://github.com/Azure/Commercial-Marketplace-SaaS-Accelerator.git -b 6.0.1 --depth 1; ` | ||
cd ./Commercial-Marketplace-SaaS-Accelerator/deployment/Templates; ` | ||
cd ./Commercial-Marketplace-SaaS-Accelerator/deployment; ` | ||
Connect-AzureAD -Confirm; ` | ||
.\Deploy.ps1 ` | ||
-WebAppNamePrefix "marketplace-SOME-UNIQUE-STRING" ` | ||
|
@@ -15,7 +20,7 @@ Connect-AzureAD -Confirm; ` | |
-SQLAdminLoginPassword "" ` | ||
-PublisherAdminUsers "[email protected]" ` | ||
-ResourceGroupForDeployment "MarketplaceSaasGitHub" ` | ||
-Location "East US" | ||
-Location "East US"; ` | ||
``` | ||
|
||
The following lines are optional: | ||
|
@@ -28,7 +33,25 @@ Connect-AzureAD -Confirm; ` | |
-LogoURLpng "https://company_com/company_logo.png" ` | ||
-LogoURLico "https://company_com/company_logo.ico" | ||
``` | ||
|
||
The scripts above will perform these actions: | ||
- Create required App Registration for SaaS Marketplace API authentication | ||
- Create APP registration for SSO on your Landing Page | ||
- Deploy required infrastructure in Azure for | ||
|
||
## Update to a newer version of the SaaS Accelerator | ||
|
||
If you are already have deployed the SaaS Accelerator, but you want to update it so that you take advantage of new features developed, you can run the following command. | ||
|
||
*you need to ensure that you use the same parameters you used in the initial deployment | ||
|
||
``` powershell | ||
git clone https://github.com/Azure/Commercial-Marketplace-SaaS-Accelerator.git -b <branch-to-deploy> --depth 1; ` | ||
cd ./Commercial-Marketplace-SaaS-Accelerator/deployment; ` | ||
.\Upgrade.ps1 ` | ||
-WebAppNamePrefix "marketplace-SOME-UNIQUE-STRING" ` | ||
-ResourceGroupForDeployment "MarketplaceSaasGitHub" ` | ||
``` | ||
|
||
## Parameters | ||
|
||
| Parameter | Description | | ||
|
@@ -48,5 +71,6 @@ Connect-AzureAD -Confirm; ` | |
| LogoURLpng | The url of the company logo image in .png format with a size of 96x96 to be used on the website | | ||
| LogoURLico | The url of the company logo image in .ico format | | ||
| MeteredSchedulerSupport | Enable the metered scheduler. This is deployed by default. Use **true** to enable the feature. More information [here](https://github.com/Azure/Commercial-Marketplace-SaaS-Accelerator/blob/main/docs/Metered-Scheduler-Manager-Instruction.md). | ||
|
||
## Alternative Deployments | ||
There are other ways to deploy the SaaS Accelerator environment (e.g. development, maual deployment, etc). Additional instruction can be found [here](Advanced-Instructions.md). |
Oops, something went wrong.