This article describes how to set up a local Gridwich development environment in either Visual Studio 2022, or Visual Studio Code.
- Up-to-date Visual Studio Code or Visual Studio 2022.
- Azure CLI
- .NET 6.0
- PowerShell
- Git installed, and your organization's Azure DevOps Gridwich repository cloned to your local machine. If you're using Windows GitHub Desktop, avoid cloning into user directories.
Optional:
- curl
- A REST testing tool
-
In Visual Studio Code, when prompted which version of Terraform language server to install, select the latest stable version:
-
After installation, run the following command:
dotnet restore ./src --interactive
-
At the prompt, sign in to Azure so your build can access the artifact feed for installing the necessary NuGet packages.
-
Follow the instructions to create local.settings.json.
-
Press F5.
You can now make requests to the two Function endpoints shown in the build output, for example:
EventGrid: [POST] http://localhost:7071/api/EventGrid
MediaInfo: [GET] http://localhost:7071/api/MediaInfo
-
In Visual Studio, open the src\Gridwich.Host.FunctionApp.sln file in the directory where you cloned the Gridwich repository.
-
In Solution Explorer, right-click the Gridwich.Host.FunctionApp library and select Set as Startup Project.
-
Follow the instructions to create local.settings.json.
-
Press F5.
You can now make requests to the two Function endpoints shown in the build output, for example:
EventGrid: [POST] http://localhost:7071/api/EventGrid
MediaInfo: [GET] http://localhost:7071/api/MediaInfo
The following procedure creates the settings on your local machine to run the Gridwich Azure Function.
For an example local.settings.json file, see sample.local.settings.json.
If you need an Azure PowerShell CLI environment, you can use Azure Cloud Shell and select PowerShell instead of Bash.
-
To create the file, use the following PowerShell script and edit the results. In the script, use your Azure tenant and subscription values, and replace
mygridwichapp
with your application name.# Change the $targetEnv if you're not using the 'sb' environment $targetEnv = "sb" $targetTenant = "00000000-0000-0000-0000-000000000000" $targetSub = "00000000-0000-0000-0000-000000000000" $appname = "mygridwichapp" az account set --subscription $targetSub $appSettings = az webapp config appsettings list --subscription $targetSub --name $appname-grw-fxn-$targetEnv -g $appname-application-rg-$targetEnv | ConvertFrom-Json $settingsList = New-Object System.Collections.ArrayList($null) $settingsList.AddRange($appSettings) echo "{""IsEncrypted"": false,""Values"": {" > local.settings.$targetEnv.json $settingsList.ForEach({echo """$($_.name)"":""$($_.value)"","}) >> local.settings.$targetEnv.json echo """AzureWebJobsStorage"": ""UseDevelopmentStorage=true"",""FUNCTIONS_WORKER_RUNTIME"": ""dotnet"",""AZURE_TENANT_ID"": ""$targetTenant"",""AZURE_SUBSCRIPTION_ID"": ""$targetSub""}}" >> local.settings.$targetEnv.json type local.settings.$targetEnv.json
-
Edit the resulting local.settings.sb.json file to remove the following lines:
AzureWebJobsDashboard
- The
AzureWebJobsStorage
pointing to a connection string WEBSITE_CONTENTAZUREFILECONNECTIONSTRING
WEBSITE_CONTENTSHARE
WEBSITE_ENABLE_SYNC_UPDATE_SITE
WEBSITE_RUN_FROM_PACKAGE
To view Azure Key Vault keys and secrets, run the following script:
$keyVaultName = 'gridwich-kv-sb'
$targetUserPrincipalName = (az ad signed-in-user show | ConvertFrom-Json).userPrincipalName
az keyvault set-policy --name $keyVaultName --secret-permissions list get --upn $targetUserPrincipalName
Or, you can use the following Azure CLI commands:
-
Run the following command:
az ad signed-in-user show
-
In the output, find and copy
userPrincipalName
, which may look like:<your username_yourdomain>.com#EXT#@<a Microsoft Entra ID>.onmicrosoft.com
. -
Run the following command, using the
userPrincipalName
value you copied:az keyvault set-policy --name gridwich-kv-sb --secret-permissions list get --upn "<your username_yourdomain>.com#EXT#@<a Microsoft Entra ID>.onmicrosoft.com"
To replace the @Microsoft.KeyVault
secrets in local.settings.sb.json with actual values, run:
$keyVaultName="$appname-kv-$targetEnv"
$targetUserPrincipalName = (az ad signed-in-user show | ConvertFrom-Json).userPrincipalName
az keyvault set-policy --name $keyVaultName --secret-permissions list get --upn $targetUserPrincipalName
$APPINSIGHTS_INSTRUMENTATIONKEY=$((az keyvault secret show --vault-name $keyVaultName --name appinsights-instrumentationkey | ConvertFrom-Json).value)
$TELESTREAMCLOUD_API_KEY=$((az keyvault secret show --vault-name $keyVaultName --name telestream-cloud-api-key | ConvertFrom-Json).value)
$GRW_TOPIC_END_POINT=$((az keyvault secret show --vault-name $keyVaultName --name grw-topic-end-point | ConvertFrom-Json).value)
$GRW_TOPIC_KEY=$((az keyvault secret show --vault-name $keyVaultName --name grw-topic-key | ConvertFrom-Json).value)
echo $('"APPINSIGHTS_INSTRUMENTATIONKEY":"'+$APPINSIGHTS_INSTRUMENTATIONKEY+'",') $('"TELESTREAMCLOUD_API_KEY":"'+$TELESTREAMCLOUD_API_KEY+'",') $('"GRW_TOPIC_END_POINT":"'+$GRW_TOPIC_END_POINT+'",') $('"GRW_TOPIC_KEY":"'+$GRW_TOPIC_KEY+'",')
Rename local.settings.sb.json to local.settings.json and copy it to Gridwich.Host.FunctionApp/src. Or edit local.settings.json in place, using the console output from the preceding scripts.
- Create or delete a cloud sandbox or test environment.