From 0be1bd3c38eca609d18aec2b13c5113bce9ba56b Mon Sep 17 00:00:00 2001 From: DevMando Date: Wed, 2 Jul 2025 00:14:35 -0700 Subject: [PATCH 1/2] feat: add Docker support with .env configuration and runtime secret injection . Tested docker build/run. --- StarshipWebApp/.env.example | 7 + StarshipWebApp/Program.cs | 6 + .../DevMandoStarships/profile.arm.json | 120 ++++++++++++++++++ StarshipWebApp/docker-compose.yml | 11 ++ 4 files changed, 144 insertions(+) create mode 100644 StarshipWebApp/.env.example create mode 100644 StarshipWebApp/Properties/ServiceDependencies/DevMandoStarships/profile.arm.json create mode 100644 StarshipWebApp/docker-compose.yml diff --git a/StarshipWebApp/.env.example b/StarshipWebApp/.env.example new file mode 100644 index 0000000..e4a273e --- /dev/null +++ b/StarshipWebApp/.env.example @@ -0,0 +1,7 @@ +# === Database === +ConnectionStrings__DefaultConnection=Server=YOUR_SERVER;Database=StarshipDb;User Id=YOUR_USERNAME;Password=YOUR_PASSWORD; + +# === Google OAuth === +Authentication__Google__ClientId=your-google-client-id.apps.googleusercontent.com +Authentication__Google__ClientSecret=your-google-client-secret + diff --git a/StarshipWebApp/Program.cs b/StarshipWebApp/Program.cs index 3748daf..a5d9e56 100644 --- a/StarshipWebApp/Program.cs +++ b/StarshipWebApp/Program.cs @@ -12,6 +12,12 @@ var builder = WebApplication.CreateBuilder(args); +builder.Configuration + .AddJsonFile("appsettings.json", optional: false) + .AddEnvironmentVariables(); + +Console.WriteLine("GOOGLE CLIENT ID: " + builder.Configuration["Authentication:Google:ClientId"]); + // Add services to the container. builder.Services.AddRazorComponents() .AddInteractiveServerComponents(); diff --git a/StarshipWebApp/Properties/ServiceDependencies/DevMandoStarships/profile.arm.json b/StarshipWebApp/Properties/ServiceDependencies/DevMandoStarships/profile.arm.json new file mode 100644 index 0000000..42c418f --- /dev/null +++ b/StarshipWebApp/Properties/ServiceDependencies/DevMandoStarships/profile.arm.json @@ -0,0 +1,120 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "metadata": { + "_dependencyType": "compute.appService.container" + }, + "parameters": { + "resourceGroupName": { + "type": "string", + "defaultValue": "DefaultResourceGroup-CUS", + "metadata": { + "description": "Name of the resource group for the resource. It is recommended to put resources under same resource group for better tracking." + } + }, + "resourceGroupLocation": { + "type": "string", + "defaultValue": "centralus", + "metadata": { + "description": "Location of the resource group. Resource groups could have different location than resources, however by default we use API versions from latest hybrid profile which support all locations for resource types we support." + } + }, + "resourceName": { + "type": "string", + "defaultValue": "DevMandoStarships", + "metadata": { + "description": "Name of the main resource to be created by this template." + } + }, + "resourceLocation": { + "type": "string", + "defaultValue": "[parameters('resourceGroupLocation')]", + "metadata": { + "description": "Location of the resource. By default use resource group's location, unless the resource provider is not supported there." + } + } + }, + "variables": { + "appServicePlan_name": "[concat('Plan', uniqueString(concat(parameters('resourceName'), subscription().subscriptionId)))]", + "appServicePlan_ResourceId": "[concat('/subscriptions/', subscription().subscriptionId, '/resourceGroups/', parameters('resourceGroupName'), '/providers/Microsoft.Web/serverFarms/', variables('appServicePlan_name'))]", + "appServiceContainer_name": "['Container', uniqueString(concat(parameters('resourceName'), subscription().subscriptionId)))]" + }, + "resources": [ + { + "type": "Microsoft.Resources/resourceGroups", + "name": "[parameters('resourceGroupName')]", + "location": "[parameters('resourceGroupLocation')]", + "apiVersion": "2019-10-01" + }, + { + "type": "Microsoft.Resources/deployments", + "name": "[concat(parameters('resourceGroupName'), 'Deployment', uniqueString(concat(parameters('resourceName'), subscription().subscriptionId)))]", + "resourceGroup": "[parameters('resourceGroupName')]", + "apiVersion": "2019-10-01", + "dependsOn": [ + "[parameters('resourceGroupName')]" + ], + "properties": { + "mode": "Incremental", + "template": { + "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "resources": [ + { + "location": "[parameters('resourceLocation')]", + "name": "[parameters('resourceName')]", + "type": "Microsoft.Web/sites", + "apiVersion": "2015-08-01", + "tags": { + "[concat('hidden-related:', variables('appServicePlan_ResourceId'))]": "empty" + }, + "dependsOn": [ + "[variables('appServicePlan_ResourceId')]" + ], + "kind": "app", + "properties": { + "name": "[parameters('resourceName')]", + "kind": "app", + "httpsOnly": true, + "reserved": false, + "serverFarmId": "[variables('appServicePlan_ResourceId')]", + "siteConfig": { + "linuxFxVersion": "DOCKER|nginx" + } + }, + "identity": { + "type": "SystemAssigned" + } + }, + { + "location": "[parameters('resourceLocation')]", + "name": "[variables('appServicePlan_name')]", + "type": "Microsoft.Web/serverFarms", + "apiVersion": "2015-02-01", + "kind": "linux", + "properties": { + "name": "[variables('appServicePlan_name')]", + "sku": "Standard", + "workerSizeId": "0", + "reserved": true + } + }, + { + "location": "[parameters('resourceLocation')]", + "name": "[variables('appServiceContainer_name')]", + "type": "Microsoft.ContainerRegistry/registries", + "apiVersion": "2017-10-01", + "sku": { + "name": "Standard" + }, + "properties": { + "tenantId": "[subscription().tenantId]", + "adminUserEnabled": false + } + } + ] + } + } + } + ] +} \ No newline at end of file diff --git a/StarshipWebApp/docker-compose.yml b/StarshipWebApp/docker-compose.yml new file mode 100644 index 0000000..1b73e34 --- /dev/null +++ b/StarshipWebApp/docker-compose.yml @@ -0,0 +1,11 @@ +version: '3.9' + +services: + web: + build: . + ports: + - "8080:80" + environment: + Authentication__Google__ClientId: ${GOOGLE_CLIENT_ID} + Authentication__Google__ClientSecret: ${GOOGLE_CLIENT_SECRET} + ConnectionStrings__DefaultConnection: ${CONNECTIONSTRINGS__DEFAULTCONNECTION} From 3741747fa278718929b75e77e2035dedc2c5d1a7 Mon Sep 17 00:00:00 2001 From: DevMando Date: Wed, 2 Jul 2025 00:19:23 -0700 Subject: [PATCH 2/2] Removed ClientID console log output for debugging. --- StarshipWebApp/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/StarshipWebApp/Program.cs b/StarshipWebApp/Program.cs index a5d9e56..d3717ed 100644 --- a/StarshipWebApp/Program.cs +++ b/StarshipWebApp/Program.cs @@ -16,7 +16,7 @@ .AddJsonFile("appsettings.json", optional: false) .AddEnvironmentVariables(); -Console.WriteLine("GOOGLE CLIENT ID: " + builder.Configuration["Authentication:Google:ClientId"]); + // Add services to the container. builder.Services.AddRazorComponents()