From 24034a547bb06f5dbd384f335ebc349e6f661959 Mon Sep 17 00:00:00 2001 From: Joe Whiteaker <47674962+josephaw1022@users.noreply.github.com> Date: Sat, 6 Jan 2024 19:08:21 -0500 Subject: [PATCH 1/2] create a sample with two simple projects --- .../AspireWithAzureFunctions/.dockerignore | 30 ++ .../AspireWithAzureFunctions.AppHost.csproj | 20 ++ .../Program.cs | 9 + .../Properties/launchSettings.json | 16 ++ .../appsettings.Development.json | 8 + .../appsettings.json | 9 + ...eWithAzureFunctions.ServiceDefaults.csproj | 24 ++ .../Extensions.cs | 119 ++++++++ .../AspireWithAzureFunctions.sln | 42 +++ .../HttpFunctionApp/.gitignore | 264 ++++++++++++++++++ .../HttpFunctionApp/Dockerfile | 24 ++ .../HttpFunctionApp/Function1.cs | 30 ++ .../HttpFunctionApp/HttpFunctionApp.csproj | 31 ++ .../HttpFunctionApp/Program.cs | 14 + .../Properties/launchSettings.json | 14 + .../Properties/serviceDependencies.json | 7 + .../Properties/serviceDependencies.local.json | 7 + .../HttpFunctionApp/host.json | 12 + .../TimerTriggerFunction/.gitignore | 264 ++++++++++++++++++ .../TimerTriggerFunction/Dockerfile | 24 ++ .../TimerTriggerFunction/Function1.cs | 27 ++ .../TimerTriggerFunction/Program.cs | 14 + .../Properties/launchSettings.json | 14 + .../Properties/serviceDependencies.json | 7 + .../Properties/serviceDependencies.local.json | 7 + .../TimerTriggerFunctionApp.csproj | 34 +++ .../TimerTriggerFunction/host.json | 12 + 27 files changed, 1083 insertions(+) create mode 100644 samples/AspireWithAzureFunctions/.dockerignore create mode 100644 samples/AspireWithAzureFunctions/AspireWithAzureFunctions.AppHost/AspireWithAzureFunctions.AppHost.csproj create mode 100644 samples/AspireWithAzureFunctions/AspireWithAzureFunctions.AppHost/Program.cs create mode 100644 samples/AspireWithAzureFunctions/AspireWithAzureFunctions.AppHost/Properties/launchSettings.json create mode 100644 samples/AspireWithAzureFunctions/AspireWithAzureFunctions.AppHost/appsettings.Development.json create mode 100644 samples/AspireWithAzureFunctions/AspireWithAzureFunctions.AppHost/appsettings.json create mode 100644 samples/AspireWithAzureFunctions/AspireWithAzureFunctions.ServiceDefaults/AspireWithAzureFunctions.ServiceDefaults.csproj create mode 100644 samples/AspireWithAzureFunctions/AspireWithAzureFunctions.ServiceDefaults/Extensions.cs create mode 100644 samples/AspireWithAzureFunctions/AspireWithAzureFunctions.sln create mode 100644 samples/AspireWithAzureFunctions/HttpFunctionApp/.gitignore create mode 100644 samples/AspireWithAzureFunctions/HttpFunctionApp/Dockerfile create mode 100644 samples/AspireWithAzureFunctions/HttpFunctionApp/Function1.cs create mode 100644 samples/AspireWithAzureFunctions/HttpFunctionApp/HttpFunctionApp.csproj create mode 100644 samples/AspireWithAzureFunctions/HttpFunctionApp/Program.cs create mode 100644 samples/AspireWithAzureFunctions/HttpFunctionApp/Properties/launchSettings.json create mode 100644 samples/AspireWithAzureFunctions/HttpFunctionApp/Properties/serviceDependencies.json create mode 100644 samples/AspireWithAzureFunctions/HttpFunctionApp/Properties/serviceDependencies.local.json create mode 100644 samples/AspireWithAzureFunctions/HttpFunctionApp/host.json create mode 100644 samples/AspireWithAzureFunctions/TimerTriggerFunction/.gitignore create mode 100644 samples/AspireWithAzureFunctions/TimerTriggerFunction/Dockerfile create mode 100644 samples/AspireWithAzureFunctions/TimerTriggerFunction/Function1.cs create mode 100644 samples/AspireWithAzureFunctions/TimerTriggerFunction/Program.cs create mode 100644 samples/AspireWithAzureFunctions/TimerTriggerFunction/Properties/launchSettings.json create mode 100644 samples/AspireWithAzureFunctions/TimerTriggerFunction/Properties/serviceDependencies.json create mode 100644 samples/AspireWithAzureFunctions/TimerTriggerFunction/Properties/serviceDependencies.local.json create mode 100644 samples/AspireWithAzureFunctions/TimerTriggerFunction/TimerTriggerFunctionApp.csproj create mode 100644 samples/AspireWithAzureFunctions/TimerTriggerFunction/host.json diff --git a/samples/AspireWithAzureFunctions/.dockerignore b/samples/AspireWithAzureFunctions/.dockerignore new file mode 100644 index 00000000..fe1152bd --- /dev/null +++ b/samples/AspireWithAzureFunctions/.dockerignore @@ -0,0 +1,30 @@ +**/.classpath +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/azds.yaml +**/bin +**/charts +**/docker-compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +LICENSE +README.md +!**/.gitignore +!.git/HEAD +!.git/config +!.git/packed-refs +!.git/refs/heads/** \ No newline at end of file diff --git a/samples/AspireWithAzureFunctions/AspireWithAzureFunctions.AppHost/AspireWithAzureFunctions.AppHost.csproj b/samples/AspireWithAzureFunctions/AspireWithAzureFunctions.AppHost/AspireWithAzureFunctions.AppHost.csproj new file mode 100644 index 00000000..b5a34a1d --- /dev/null +++ b/samples/AspireWithAzureFunctions/AspireWithAzureFunctions.AppHost/AspireWithAzureFunctions.AppHost.csproj @@ -0,0 +1,20 @@ + + + + Exe + net8.0 + enable + enable + true + + + + + + + + + + + + diff --git a/samples/AspireWithAzureFunctions/AspireWithAzureFunctions.AppHost/Program.cs b/samples/AspireWithAzureFunctions/AspireWithAzureFunctions.AppHost/Program.cs new file mode 100644 index 00000000..39b07446 --- /dev/null +++ b/samples/AspireWithAzureFunctions/AspireWithAzureFunctions.AppHost/Program.cs @@ -0,0 +1,9 @@ +var builder = DistributedApplication.CreateBuilder(args); + +// Http based azure function +builder.AddProject("http-based-azure-function"); + +// Timer based azure function +builder.AddProject("timer-based-azure-function"); + +builder.Build().Run(); diff --git a/samples/AspireWithAzureFunctions/AspireWithAzureFunctions.AppHost/Properties/launchSettings.json b/samples/AspireWithAzureFunctions/AspireWithAzureFunctions.AppHost/Properties/launchSettings.json new file mode 100644 index 00000000..90f2e911 --- /dev/null +++ b/samples/AspireWithAzureFunctions/AspireWithAzureFunctions.AppHost/Properties/launchSettings.json @@ -0,0 +1,16 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "http://localhost:15259", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development", + "DOTNET_ENVIRONMENT": "Development", + "DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16103" + } + } + } +} diff --git a/samples/AspireWithAzureFunctions/AspireWithAzureFunctions.AppHost/appsettings.Development.json b/samples/AspireWithAzureFunctions/AspireWithAzureFunctions.AppHost/appsettings.Development.json new file mode 100644 index 00000000..0c208ae9 --- /dev/null +++ b/samples/AspireWithAzureFunctions/AspireWithAzureFunctions.AppHost/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/samples/AspireWithAzureFunctions/AspireWithAzureFunctions.AppHost/appsettings.json b/samples/AspireWithAzureFunctions/AspireWithAzureFunctions.AppHost/appsettings.json new file mode 100644 index 00000000..31c092aa --- /dev/null +++ b/samples/AspireWithAzureFunctions/AspireWithAzureFunctions.AppHost/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning", + "Aspire.Hosting.Dcp": "Warning" + } + } +} diff --git a/samples/AspireWithAzureFunctions/AspireWithAzureFunctions.ServiceDefaults/AspireWithAzureFunctions.ServiceDefaults.csproj b/samples/AspireWithAzureFunctions/AspireWithAzureFunctions.ServiceDefaults/AspireWithAzureFunctions.ServiceDefaults.csproj new file mode 100644 index 00000000..ef9c7cc8 --- /dev/null +++ b/samples/AspireWithAzureFunctions/AspireWithAzureFunctions.ServiceDefaults/AspireWithAzureFunctions.ServiceDefaults.csproj @@ -0,0 +1,24 @@ + + + + Library + net8.0 + enable + enable + true + + + + + + + + + + + + + + + + diff --git a/samples/AspireWithAzureFunctions/AspireWithAzureFunctions.ServiceDefaults/Extensions.cs b/samples/AspireWithAzureFunctions/AspireWithAzureFunctions.ServiceDefaults/Extensions.cs new file mode 100644 index 00000000..c59308d5 --- /dev/null +++ b/samples/AspireWithAzureFunctions/AspireWithAzureFunctions.ServiceDefaults/Extensions.cs @@ -0,0 +1,119 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Diagnostics.HealthChecks; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Diagnostics.HealthChecks; +using Microsoft.Extensions.Logging; +using OpenTelemetry.Logs; +using OpenTelemetry.Metrics; +using OpenTelemetry.Trace; + +namespace Microsoft.Extensions.Hosting; + +public static class Extensions +{ + public static IHostApplicationBuilder AddServiceDefaults(this IHostApplicationBuilder builder) + { + builder.ConfigureOpenTelemetry(); + + builder.AddDefaultHealthChecks(); + + builder.Services.AddServiceDiscovery(); + + builder.Services.ConfigureHttpClientDefaults(http => + { + // Turn on resilience by default + http.AddStandardResilienceHandler(); + + // Turn on service discovery by default + http.UseServiceDiscovery(); + }); + + return builder; + } + + public static IHostApplicationBuilder ConfigureOpenTelemetry(this IHostApplicationBuilder builder) + { + builder.Logging.AddOpenTelemetry(logging => + { + logging.IncludeFormattedMessage = true; + logging.IncludeScopes = true; + }); + + builder.Services.AddOpenTelemetry() + .WithMetrics(metrics => + { + metrics.AddRuntimeInstrumentation() + .AddBuiltInMeters(); + }) + .WithTracing(tracing => + { + if (builder.Environment.IsDevelopment()) + { + // We want to view all traces in development + tracing.SetSampler(new AlwaysOnSampler()); + } + + tracing.AddAspNetCoreInstrumentation() + .AddGrpcClientInstrumentation() + .AddHttpClientInstrumentation(); + }); + + builder.AddOpenTelemetryExporters(); + + return builder; + } + + private static IHostApplicationBuilder AddOpenTelemetryExporters(this IHostApplicationBuilder builder) + { + var useOtlpExporter = !string.IsNullOrWhiteSpace(builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]); + + if (useOtlpExporter) + { + builder.Services.Configure(logging => logging.AddOtlpExporter()); + builder.Services.ConfigureOpenTelemetryMeterProvider(metrics => metrics.AddOtlpExporter()); + builder.Services.ConfigureOpenTelemetryTracerProvider(tracing => tracing.AddOtlpExporter()); + } + + // Uncomment the following lines to enable the Prometheus exporter (requires the OpenTelemetry.Exporter.Prometheus.AspNetCore package) + // builder.Services.AddOpenTelemetry() + // .WithMetrics(metrics => metrics.AddPrometheusExporter()); + + // Uncomment the following lines to enable the Azure Monitor exporter (requires the Azure.Monitor.OpenTelemetry.Exporter package) + // builder.Services.AddOpenTelemetry() + // .UseAzureMonitor(); + + return builder; + } + + public static IHostApplicationBuilder AddDefaultHealthChecks(this IHostApplicationBuilder builder) + { + builder.Services.AddHealthChecks() + // Add a default liveness check to ensure app is responsive + .AddCheck("self", () => HealthCheckResult.Healthy(), ["live"]); + + return builder; + } + + public static WebApplication MapDefaultEndpoints(this WebApplication app) + { + // Uncomment the following line to enable the Prometheus endpoint (requires the OpenTelemetry.Exporter.Prometheus.AspNetCore package) + // app.MapPrometheusScrapingEndpoint(); + + // All health checks must pass for app to be considered ready to accept traffic after starting + app.MapHealthChecks("/health"); + + // Only health checks tagged with the "live" tag must pass for app to be considered alive + app.MapHealthChecks("/alive", new HealthCheckOptions + { + Predicate = r => r.Tags.Contains("live") + }); + + return app; + } + + private static MeterProviderBuilder AddBuiltInMeters(this MeterProviderBuilder meterProviderBuilder) => + meterProviderBuilder.AddMeter( + "Microsoft.AspNetCore.Hosting", + "Microsoft.AspNetCore.Server.Kestrel", + "System.Net.Http"); +} diff --git a/samples/AspireWithAzureFunctions/AspireWithAzureFunctions.sln b/samples/AspireWithAzureFunctions/AspireWithAzureFunctions.sln new file mode 100644 index 00000000..e8ab4eb0 --- /dev/null +++ b/samples/AspireWithAzureFunctions/AspireWithAzureFunctions.sln @@ -0,0 +1,42 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34407.89 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspireWithAzureFunctions.AppHost", "AspireWithAzureFunctions.AppHost\AspireWithAzureFunctions.AppHost.csproj", "{0783072C-4C84-46A4-85E6-287C514079E5}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspireWithAzureFunctions.ServiceDefaults", "AspireWithAzureFunctions.ServiceDefaults\AspireWithAzureFunctions.ServiceDefaults.csproj", "{43489F15-748C-4B92-9C8F-7C9455E4867A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HttpFunctionApp", "HttpFunctionApp\HttpFunctionApp.csproj", "{74B1219D-48B8-4F63-9651-A187843B0C0D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TimerTriggerFunctionApp", "TimerTriggerFunction\TimerTriggerFunctionApp.csproj", "{0B94967D-6877-471C-B284-4185025CB114}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {0783072C-4C84-46A4-85E6-287C514079E5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0783072C-4C84-46A4-85E6-287C514079E5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0783072C-4C84-46A4-85E6-287C514079E5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0783072C-4C84-46A4-85E6-287C514079E5}.Release|Any CPU.Build.0 = Release|Any CPU + {43489F15-748C-4B92-9C8F-7C9455E4867A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {43489F15-748C-4B92-9C8F-7C9455E4867A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {43489F15-748C-4B92-9C8F-7C9455E4867A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {43489F15-748C-4B92-9C8F-7C9455E4867A}.Release|Any CPU.Build.0 = Release|Any CPU + {74B1219D-48B8-4F63-9651-A187843B0C0D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {74B1219D-48B8-4F63-9651-A187843B0C0D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {74B1219D-48B8-4F63-9651-A187843B0C0D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {74B1219D-48B8-4F63-9651-A187843B0C0D}.Release|Any CPU.Build.0 = Release|Any CPU + {0B94967D-6877-471C-B284-4185025CB114}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0B94967D-6877-471C-B284-4185025CB114}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0B94967D-6877-471C-B284-4185025CB114}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0B94967D-6877-471C-B284-4185025CB114}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {D13567BC-B25E-44A3-B383-D2C5E6C804D2} + EndGlobalSection +EndGlobal diff --git a/samples/AspireWithAzureFunctions/HttpFunctionApp/.gitignore b/samples/AspireWithAzureFunctions/HttpFunctionApp/.gitignore new file mode 100644 index 00000000..ff5b00c5 --- /dev/null +++ b/samples/AspireWithAzureFunctions/HttpFunctionApp/.gitignore @@ -0,0 +1,264 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# Azure Functions localsettings file +local.settings.json + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +project.fragment.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +#*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush +.cr/ + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc \ No newline at end of file diff --git a/samples/AspireWithAzureFunctions/HttpFunctionApp/Dockerfile b/samples/AspireWithAzureFunctions/HttpFunctionApp/Dockerfile new file mode 100644 index 00000000..b586022e --- /dev/null +++ b/samples/AspireWithAzureFunctions/HttpFunctionApp/Dockerfile @@ -0,0 +1,24 @@ +#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging. + +FROM mcr.microsoft.com/azure-functions/dotnet-isolated:4-dotnet-isolated8.0 AS base +WORKDIR /home/site/wwwroot +EXPOSE 8080 + +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build +ARG BUILD_CONFIGURATION=Release +WORKDIR /src +COPY ["HttpFunctionApp/HttpFunctionApp.csproj", "HttpFunctionApp/"] +RUN dotnet restore "./HttpFunctionApp/HttpFunctionApp.csproj" +COPY . . +WORKDIR "/src/HttpFunctionApp" +RUN dotnet build "./HttpFunctionApp.csproj" -c $BUILD_CONFIGURATION -o /app/build + +FROM build AS publish +ARG BUILD_CONFIGURATION=Release +RUN dotnet publish "./HttpFunctionApp.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false + +FROM base AS final +WORKDIR /home/site/wwwroot +COPY --from=publish /app/publish . +ENV AzureWebJobsScriptRoot=/home/site/wwwroot \ + AzureFunctionsJobHost__Logging__Console__IsEnabled=true \ No newline at end of file diff --git a/samples/AspireWithAzureFunctions/HttpFunctionApp/Function1.cs b/samples/AspireWithAzureFunctions/HttpFunctionApp/Function1.cs new file mode 100644 index 00000000..6f8a0830 --- /dev/null +++ b/samples/AspireWithAzureFunctions/HttpFunctionApp/Function1.cs @@ -0,0 +1,30 @@ +using System.Net; +using Microsoft.Azure.Functions.Worker; +using Microsoft.Azure.Functions.Worker.Http; +using Microsoft.Extensions.Logging; + +namespace HttpFunctionApp +{ + public class Function1 + { + private readonly ILogger _logger; + + public Function1(ILoggerFactory loggerFactory) + { + _logger = loggerFactory.CreateLogger(); + } + + [Function("Function1")] + public HttpResponseData Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req) + { + _logger.LogInformation("C# HTTP trigger function processed a request."); + + var response = req.CreateResponse(HttpStatusCode.OK); + response.Headers.Add("Content-Type", "text/plain; charset=utf-8"); + + response.WriteString("Welcome to Azure Functions In Apsire!"); + + return response; + } + } +} diff --git a/samples/AspireWithAzureFunctions/HttpFunctionApp/HttpFunctionApp.csproj b/samples/AspireWithAzureFunctions/HttpFunctionApp/HttpFunctionApp.csproj new file mode 100644 index 00000000..9f22bc44 --- /dev/null +++ b/samples/AspireWithAzureFunctions/HttpFunctionApp/HttpFunctionApp.csproj @@ -0,0 +1,31 @@ + + + net8.0 + v4 + Exe + enable + enable + /home/site/wwwroot + Linux + + + + + + + + + + + + PreserveNewest + + + PreserveNewest + Never + + + + + + \ No newline at end of file diff --git a/samples/AspireWithAzureFunctions/HttpFunctionApp/Program.cs b/samples/AspireWithAzureFunctions/HttpFunctionApp/Program.cs new file mode 100644 index 00000000..9de3b3ed --- /dev/null +++ b/samples/AspireWithAzureFunctions/HttpFunctionApp/Program.cs @@ -0,0 +1,14 @@ +using Microsoft.Azure.Functions.Worker; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; + +var host = new HostBuilder() + .ConfigureFunctionsWorkerDefaults() + .ConfigureServices(services => + { + services.AddApplicationInsightsTelemetryWorkerService(); + services.ConfigureFunctionsApplicationInsights(); + }) + .Build(); + +host.Run(); diff --git a/samples/AspireWithAzureFunctions/HttpFunctionApp/Properties/launchSettings.json b/samples/AspireWithAzureFunctions/HttpFunctionApp/Properties/launchSettings.json new file mode 100644 index 00000000..77486c5a --- /dev/null +++ b/samples/AspireWithAzureFunctions/HttpFunctionApp/Properties/launchSettings.json @@ -0,0 +1,14 @@ +{ + "profiles": { + "HttpFunctionApp": { + "commandName": "Project", + "commandLineArgs": "--port 7050" + }, + "Container (Dockerfile)": { + "commandName": "Docker", + "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}", + "httpPort": 31911, + "useSSL": false + } + } +} \ No newline at end of file diff --git a/samples/AspireWithAzureFunctions/HttpFunctionApp/Properties/serviceDependencies.json b/samples/AspireWithAzureFunctions/HttpFunctionApp/Properties/serviceDependencies.json new file mode 100644 index 00000000..c264e8ca --- /dev/null +++ b/samples/AspireWithAzureFunctions/HttpFunctionApp/Properties/serviceDependencies.json @@ -0,0 +1,7 @@ +{ + "dependencies": { + "appInsights1": { + "type": "appInsights" + } + } +} \ No newline at end of file diff --git a/samples/AspireWithAzureFunctions/HttpFunctionApp/Properties/serviceDependencies.local.json b/samples/AspireWithAzureFunctions/HttpFunctionApp/Properties/serviceDependencies.local.json new file mode 100644 index 00000000..5a956e85 --- /dev/null +++ b/samples/AspireWithAzureFunctions/HttpFunctionApp/Properties/serviceDependencies.local.json @@ -0,0 +1,7 @@ +{ + "dependencies": { + "appInsights1": { + "type": "appInsights.sdk" + } + } +} \ No newline at end of file diff --git a/samples/AspireWithAzureFunctions/HttpFunctionApp/host.json b/samples/AspireWithAzureFunctions/HttpFunctionApp/host.json new file mode 100644 index 00000000..ee5cf5f8 --- /dev/null +++ b/samples/AspireWithAzureFunctions/HttpFunctionApp/host.json @@ -0,0 +1,12 @@ +{ + "version": "2.0", + "logging": { + "applicationInsights": { + "samplingSettings": { + "isEnabled": true, + "excludedTypes": "Request" + }, + "enableLiveMetricsFilters": true + } + } +} \ No newline at end of file diff --git a/samples/AspireWithAzureFunctions/TimerTriggerFunction/.gitignore b/samples/AspireWithAzureFunctions/TimerTriggerFunction/.gitignore new file mode 100644 index 00000000..ff5b00c5 --- /dev/null +++ b/samples/AspireWithAzureFunctions/TimerTriggerFunction/.gitignore @@ -0,0 +1,264 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# Azure Functions localsettings file +local.settings.json + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +project.fragment.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +#*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush +.cr/ + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc \ No newline at end of file diff --git a/samples/AspireWithAzureFunctions/TimerTriggerFunction/Dockerfile b/samples/AspireWithAzureFunctions/TimerTriggerFunction/Dockerfile new file mode 100644 index 00000000..1b38f864 --- /dev/null +++ b/samples/AspireWithAzureFunctions/TimerTriggerFunction/Dockerfile @@ -0,0 +1,24 @@ +#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging. + +FROM mcr.microsoft.com/azure-functions/dotnet-isolated:4-dotnet-isolated8.0 AS base +WORKDIR /home/site/wwwroot +EXPOSE 8080 + +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build +ARG BUILD_CONFIGURATION=Release +WORKDIR /src +COPY ["TimerTriggerFunction/TimerTriggerFunctionApp.csproj", "TimerTriggerFunction/"] +RUN dotnet restore "./TimerTriggerFunction/TimerTriggerFunctionApp.csproj" +COPY . . +WORKDIR "/src/TimerTriggerFunction" +RUN dotnet build "./TimerTriggerFunctionApp.csproj" -c $BUILD_CONFIGURATION -o /app/build + +FROM build AS publish +ARG BUILD_CONFIGURATION=Release +RUN dotnet publish "./TimerTriggerFunctionApp.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false + +FROM base AS final +WORKDIR /home/site/wwwroot +COPY --from=publish /app/publish . +ENV AzureWebJobsScriptRoot=/home/site/wwwroot \ + AzureFunctionsJobHost__Logging__Console__IsEnabled=true \ No newline at end of file diff --git a/samples/AspireWithAzureFunctions/TimerTriggerFunction/Function1.cs b/samples/AspireWithAzureFunctions/TimerTriggerFunction/Function1.cs new file mode 100644 index 00000000..cb8e5be5 --- /dev/null +++ b/samples/AspireWithAzureFunctions/TimerTriggerFunction/Function1.cs @@ -0,0 +1,27 @@ +using System; +using Microsoft.Azure.Functions.Worker; +using Microsoft.Extensions.Logging; + +namespace TimerTriggerFunction +{ + public class Function1 + { + private readonly ILogger _logger; + + public Function1(ILoggerFactory loggerFactory) + { + _logger = loggerFactory.CreateLogger(); + } + + [Function("Function1")] + public void Run([TimerTrigger("*/30 * * * * *")] TimerInfo myTimer) + { + _logger.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}"); + + if (myTimer.ScheduleStatus is not null) + { + _logger.LogInformation($"Next timer schedule at: {myTimer.ScheduleStatus.Next}"); + } + } + } +} diff --git a/samples/AspireWithAzureFunctions/TimerTriggerFunction/Program.cs b/samples/AspireWithAzureFunctions/TimerTriggerFunction/Program.cs new file mode 100644 index 00000000..9de3b3ed --- /dev/null +++ b/samples/AspireWithAzureFunctions/TimerTriggerFunction/Program.cs @@ -0,0 +1,14 @@ +using Microsoft.Azure.Functions.Worker; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; + +var host = new HostBuilder() + .ConfigureFunctionsWorkerDefaults() + .ConfigureServices(services => + { + services.AddApplicationInsightsTelemetryWorkerService(); + services.ConfigureFunctionsApplicationInsights(); + }) + .Build(); + +host.Run(); diff --git a/samples/AspireWithAzureFunctions/TimerTriggerFunction/Properties/launchSettings.json b/samples/AspireWithAzureFunctions/TimerTriggerFunction/Properties/launchSettings.json new file mode 100644 index 00000000..911d48b3 --- /dev/null +++ b/samples/AspireWithAzureFunctions/TimerTriggerFunction/Properties/launchSettings.json @@ -0,0 +1,14 @@ +{ + "profiles": { + "TimerTriggerFunction": { + "commandName": "Project", + "commandLineArgs": "--port 7036" + }, + "Container (Dockerfile)": { + "commandName": "Docker", + "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}", + "httpPort": 33941, + "useSSL": false + } + } +} \ No newline at end of file diff --git a/samples/AspireWithAzureFunctions/TimerTriggerFunction/Properties/serviceDependencies.json b/samples/AspireWithAzureFunctions/TimerTriggerFunction/Properties/serviceDependencies.json new file mode 100644 index 00000000..c264e8ca --- /dev/null +++ b/samples/AspireWithAzureFunctions/TimerTriggerFunction/Properties/serviceDependencies.json @@ -0,0 +1,7 @@ +{ + "dependencies": { + "appInsights1": { + "type": "appInsights" + } + } +} \ No newline at end of file diff --git a/samples/AspireWithAzureFunctions/TimerTriggerFunction/Properties/serviceDependencies.local.json b/samples/AspireWithAzureFunctions/TimerTriggerFunction/Properties/serviceDependencies.local.json new file mode 100644 index 00000000..5a956e85 --- /dev/null +++ b/samples/AspireWithAzureFunctions/TimerTriggerFunction/Properties/serviceDependencies.local.json @@ -0,0 +1,7 @@ +{ + "dependencies": { + "appInsights1": { + "type": "appInsights.sdk" + } + } +} \ No newline at end of file diff --git a/samples/AspireWithAzureFunctions/TimerTriggerFunction/TimerTriggerFunctionApp.csproj b/samples/AspireWithAzureFunctions/TimerTriggerFunction/TimerTriggerFunctionApp.csproj new file mode 100644 index 00000000..0801ee14 --- /dev/null +++ b/samples/AspireWithAzureFunctions/TimerTriggerFunction/TimerTriggerFunctionApp.csproj @@ -0,0 +1,34 @@ + + + net8.0 + v4 + Exe + enable + enable + /home/site/wwwroot + Linux + + + + + + + + + + + + + + + PreserveNewest + + + PreserveNewest + Never + + + + + + \ No newline at end of file diff --git a/samples/AspireWithAzureFunctions/TimerTriggerFunction/host.json b/samples/AspireWithAzureFunctions/TimerTriggerFunction/host.json new file mode 100644 index 00000000..ee5cf5f8 --- /dev/null +++ b/samples/AspireWithAzureFunctions/TimerTriggerFunction/host.json @@ -0,0 +1,12 @@ +{ + "version": "2.0", + "logging": { + "applicationInsights": { + "samplingSettings": { + "isEnabled": true, + "excludedTypes": "Request" + }, + "enableLiveMetricsFilters": true + } + } +} \ No newline at end of file From 87066fd08a9a7a2f57f23d3d4ce754565b4ca9b6 Mon Sep 17 00:00:00 2001 From: Joe Whiteaker <47674962+josephaw1022@users.noreply.github.com> Date: Sat, 6 Jan 2024 19:16:59 -0500 Subject: [PATCH 2/2] add azure function package versions to the centralized package versioning --- Directory.Packages.props | 10 ++++++++++ .../HttpFunctionApp/HttpFunctionApp.csproj | 14 +++++++------- .../TimerTriggerFunctionApp.csproj | 14 +++++++------- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 738301bf..f9702e5e 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -67,5 +67,15 @@ + + + + + + + + + + \ No newline at end of file diff --git a/samples/AspireWithAzureFunctions/HttpFunctionApp/HttpFunctionApp.csproj b/samples/AspireWithAzureFunctions/HttpFunctionApp/HttpFunctionApp.csproj index 9f22bc44..ef65cb4f 100644 --- a/samples/AspireWithAzureFunctions/HttpFunctionApp/HttpFunctionApp.csproj +++ b/samples/AspireWithAzureFunctions/HttpFunctionApp/HttpFunctionApp.csproj @@ -8,13 +8,13 @@ /home/site/wwwroot Linux - - - - - - - + + + + + + + diff --git a/samples/AspireWithAzureFunctions/TimerTriggerFunction/TimerTriggerFunctionApp.csproj b/samples/AspireWithAzureFunctions/TimerTriggerFunction/TimerTriggerFunctionApp.csproj index 0801ee14..fdabe337 100644 --- a/samples/AspireWithAzureFunctions/TimerTriggerFunction/TimerTriggerFunctionApp.csproj +++ b/samples/AspireWithAzureFunctions/TimerTriggerFunction/TimerTriggerFunctionApp.csproj @@ -8,13 +8,13 @@ /home/site/wwwroot Linux - - - - - - - + + + + + + +