Skip to content

Commit

Permalink
Updates (#252)
Browse files Browse the repository at this point in the history
* apim updates

* App Config with issue

* chore: update container names in publish-images.azcli and create-apim.azcli

* cdn
  • Loading branch information
alexander-kastil authored Jul 18, 2024
1 parent b6d728e commit d08db39
Show file tree
Hide file tree
Showing 50 changed files with 801 additions and 361 deletions.
2 changes: 1 addition & 1 deletion demos/05-containers/demo-01/publish-images.azcli
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
env=dev
grp=az204-$env
grp=az204-m05-containers
loc=westeurope
acr=az204demos$env
imgApi=catalog-service
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/dotnet/vscode-csharp/blob/main/debugger-launchjson.md.
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/bin/Debug/net6.0/config-service-api.dll",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/net8.0/config-service-api.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
// Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"type": "process",
"args": [
"build",
"${workspaceFolder}/config-service-api.csproj",
"${workspaceFolder}/config-service-api.sln",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
"/consoleloggerparameters:NoSummary;ForceNoAlign"
],
"problemMatcher": "$msCompile"
},
Expand All @@ -19,9 +19,9 @@
"type": "process",
"args": [
"publish",
"${workspaceFolder}/config-service-api.csproj",
"${workspaceFolder}/config-service-api.sln",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
"/consoleloggerparameters:NoSummary;ForceNoAlign"
],
"problemMatcher": "$msCompile"
},
Expand All @@ -33,7 +33,7 @@
"watch",
"run",
"--project",
"${workspaceFolder}/config-service-api.csproj"
"${workspaceFolder}/config-service-api.sln"
],
"problemMatcher": "$msCompile"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ public class AppSettings
public string DBConnectionString { get; set; }
public string KeyVault { get; set; }
public string AppConfigEndpoint { get; set; }
public string AppConfigConnection { get; set; }
public string Sentinel { get; set; }
public string Environment { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
var cfg = Configuration.Get<AppConfig>();

builder.Configuration.AddAzureAppConfiguration(options =>
{
options.Connect(cfg.Settings.AppConfigConnection)
{
options.Connect(new Uri(cfg.Settings.AppConfigEndpoint), new DefaultAzureCredential())
.ConfigureKeyVault(kv =>
{
kv.SetCredential(new DefaultAzureCredential());
})
.Select("*", cfg.Settings.Environment)
.Select("*", cfg.Settings.Environment)
.ConfigureRefresh(refreshOptions =>
refreshOptions.Register("Settings:Sentinel", refreshAll: true));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
"DBConnectionString": "Data Source=./food-local.db",
"KeyVault": "foodvault-dev.vault.azure.net",
"AppConfigEndpoint": "https://foodconfig-dev.azconfig.io",
"AppConfigConnection": "Endpoint=https://foodconfig-dev.azconfig.io;Id=fVrb-l9-s0:Kn9pxn7Ueh+XZ9viVGsR;Secret=hbr+jKb0SgK+RIrud2EXWXKZkschTJt23bCzN29xWRI=",
"Sentinel": 1,
"Environment": "production"
"Environment": "dev"
},
"FeatureManagement": {
"PremiumFeature": false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>config_service_api</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.8.1" />
<PackageReference Include="Azure.Security.KeyVault.Secrets" Version="4.4.0" />
<PackageReference Include="Microsoft.Azure.AppConfiguration.AspNetCore" Version="5.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.AzureAppConfiguration" Version="5.2.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="Azure.Identity" Version="1.12.0" />
<PackageReference Include="Azure.Security.KeyVault.Secrets" Version="4.6.0" />
<PackageReference Include="Microsoft.Azure.AppConfiguration.AspNetCore" Version="7.3.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.AzureAppConfiguration" Version="7.3.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.002.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "config-service-api", "config-service-api.csproj", "{84F9C0BE-1B03-4C0D-A560-10B655B1473E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{84F9C0BE-1B03-4C0D-A560-10B655B1473E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{84F9C0BE-1B03-4C0D-A560-10B655B1473E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{84F9C0BE-1B03-4C0D-A560-10B655B1473E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{84F9C0BE-1B03-4C0D-A560-10B655B1473E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {09D0ED85-1414-4B5B-B8A1-B6D532F38909}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ plan=config-plan-$env

# create appconfig and add a value
appconfigid=$(az appconfig create -g $grp -n $cfg -l $loc --sku free --query id -o tsv)
az appconfig kv set -n $cfg --key "Settings:Title" --value "App Config Demo Dev" -y
az appconfig kv set -n $cfg --key "Settings:Title" --value "App Config Demo Dev" -y --label dev
az appconfig kv set -n $cfg --key "Settings:Title" --value "App Config Demo" -y --label production

az appconfig kv set -n $cfg --key "Settings:Sentinel" --value 1 -y
az appconfig kv set -n $cfg --key "Settings:Sentinel" --value 1 -y --label dev
az appconfig kv set -n $cfg --key "Settings:Sentinel" --value 1 -y --label production

# app config key-vault binding
cfgmi=$(az appconfig identity assign -g $grp -n $cfg --query principalId -o tsv)
az keyvault set-policy -n $vault -g $grp --object-id $cfgmi --secret-permissions get list

az appconfig kv set-keyvault -n $cfg --key "Settings:DBConnectionString" --secret-identifier "https://$vault.vault.azure.net/Secrets/conSQLite" -y
az appconfig kv set-keyvault -n $cfg --key "Settings:DBConnectionString" --secret-identifier "https://$vault.vault.azure.net/Secrets/conSQLite" -y --label dev
az appconfig kv set-keyvault -n $cfg --key "Settings:DBConnectionString" --secret-identifier "https://$vault.vault.azure.net/Secrets/conSQLServer" -y --label production

# alternative: keyvault policy assignment using service principal
Expand Down
7 changes: 7 additions & 0 deletions demos/08-apim/demo-01/catalog-service/.azure/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[defaults]
group = az204-m08-apim-dev
sku = FREE
appserviceplan = food-dev
location = westeurope
web = foodcatalogapi-dev

25 changes: 25 additions & 0 deletions demos/08-apim/demo-01/catalog-service/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/bin
**/charts
**/docker-compose*
**/compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
## files generated by popular Visual Studio add-ons.

# Database
.azure/
*.db
food.db-shm
food.db-wal

# User-specific files
*.suo
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/dotnet/vscode-csharp/blob/main/debugger-launchjson.md.
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/bin/Debug/net6.0/food-api.dll",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/net8.0/catalog-service.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
// Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"type": "process",
"args": [
"build",
"${workspaceFolder}/food-api.csproj",
"${workspaceFolder}/catalog-service.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
"/consoleloggerparameters:NoSummary;ForceNoAlign"
],
"problemMatcher": "$msCompile"
},
Expand All @@ -19,9 +19,9 @@
"type": "process",
"args": [
"publish",
"${workspaceFolder}/food-api.csproj",
"${workspaceFolder}/catalog-service.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
"/consoleloggerparameters:NoSummary;ForceNoAlign"
],
"problemMatcher": "$msCompile"
},
Expand All @@ -33,7 +33,7 @@
"watch",
"run",
"--project",
"${workspaceFolder}/food-api.csproj"
"${workspaceFolder}/catalog-service.csproj"
],
"problemMatcher": "$msCompile"
}
Expand Down
43 changes: 43 additions & 0 deletions demos/08-apim/demo-01/catalog-service/AppInsights/AILogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using Microsoft.ApplicationInsights;
using Microsoft.Extensions.Configuration;

namespace FoodApp
{
public class AILogger
{
private TelemetryClient ai;
private AppConfig config;

public AILogger(TelemetryClient tc, IConfiguration cfg)
{
ai = tc;
config = cfg.Get<AppConfig>();
}

public void LogEvent(string text, object item, bool logToConsole = false)
{
string value = Newtonsoft.Json.JsonConvert.SerializeObject(item);
ai.TrackEvent($"Dev - {text}", new Dictionary<string, string> { { text, value } });
if (logToConsole) Console.WriteLine($"Dev - {text} - {value}");
}

public void LogEvent(string text, string param)
{
var props = new Dictionary<string, string> { { text, param } };
ai.TrackEvent(text, props);
}

public void LogEvent(string text, Exception ex)
{
ai.TrackEvent(text, new Dictionary<string, string> { { "Error", ex.Message } });
}

public void LogEvent(string text, Dictionary<string, string> arr)
{
ai.TrackEvent(text, arr);
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.Extensions.Configuration;

namespace FoodApp
{
public class FoodTelemetryInitializer : ITelemetryInitializer{

AppConfig config;
public FoodTelemetryInitializer(IConfiguration iconfig)
{
config = iconfig.Get<AppConfig>();
}

public void Initialize(ITelemetry telemetry)
{
if (string.IsNullOrEmpty(telemetry.Context.Cloud.RoleName))
{
telemetry.Context.Cloud.RoleName = config.Title;
}
}
}
}
Loading

0 comments on commit d08db39

Please sign in to comment.