From 195342f0a3a02485fb0c5622c8b477da2c4aae55 Mon Sep 17 00:00:00 2001 From: Maksym Sadovnychyy Date: Wed, 13 Nov 2024 21:32:57 +0100 Subject: [PATCH] (feature): init --- .gitattributes | 63 +++++ .gitignore | 265 ++++++++++++++++++ LICENSE.md | 21 ++ README.md | 45 +++ src/.dockerignore | 30 ++ src/Core/Commands/TestCommand.cs | 12 + src/Core/Core.csproj | 9 + src/DaprNetTest.sln | 65 +++++ .../Controllers/DaprTestController.cs | 34 +++ src/Publisher/Dockerfile | 30 ++ src/Publisher/Models/PostDaprTestRequest.cs | 9 + src/Publisher/Program.cs | 23 ++ src/Publisher/Properties/launchSettings.json | 41 +++ src/Publisher/Publisher.csproj | 22 ++ src/Publisher/Publisher.http | 6 + src/Publisher/appsettings.Development.json | 8 + src/Publisher/appsettings.json | 9 + .../Controllers/DaprTestController.cs | 30 ++ src/Subscriber/Dockerfile | 30 ++ src/Subscriber/Program.cs | 24 ++ src/Subscriber/Properties/launchSettings.json | 41 +++ src/Subscriber/Subscriber.csproj | 21 ++ src/Subscriber/Subscriber.http | 6 + src/Subscriber/appsettings.Development.json | 8 + src/Subscriber/appsettings.json | 9 + src/deployment.yaml | 56 ++++ src/docker-compose.dcproj | 19 ++ src/docker-compose.override.yml | 108 +++++++ src/docker-compose.yml | 39 +++ .../dapr/components/pubsub.yaml | 21 ++ .../dapr/components/statestore.yaml | 13 + .../dapr/configuration/config.yaml | 10 + src/launchSettings.json | 12 + 33 files changed, 1139 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 LICENSE.md create mode 100644 README.md create mode 100644 src/.dockerignore create mode 100644 src/Core/Commands/TestCommand.cs create mode 100644 src/Core/Core.csproj create mode 100644 src/DaprNetTest.sln create mode 100644 src/Publisher/Controllers/DaprTestController.cs create mode 100644 src/Publisher/Dockerfile create mode 100644 src/Publisher/Models/PostDaprTestRequest.cs create mode 100644 src/Publisher/Program.cs create mode 100644 src/Publisher/Properties/launchSettings.json create mode 100644 src/Publisher/Publisher.csproj create mode 100644 src/Publisher/Publisher.http create mode 100644 src/Publisher/appsettings.Development.json create mode 100644 src/Publisher/appsettings.json create mode 100644 src/Subscriber/Controllers/DaprTestController.cs create mode 100644 src/Subscriber/Dockerfile create mode 100644 src/Subscriber/Program.cs create mode 100644 src/Subscriber/Properties/launchSettings.json create mode 100644 src/Subscriber/Subscriber.csproj create mode 100644 src/Subscriber/Subscriber.http create mode 100644 src/Subscriber/appsettings.Development.json create mode 100644 src/Subscriber/appsettings.json create mode 100644 src/deployment.yaml create mode 100644 src/docker-compose.dcproj create mode 100644 src/docker-compose.override.yml create mode 100644 src/docker-compose.yml create mode 100644 src/docker-compose/dapr/components/pubsub.yaml create mode 100644 src/docker-compose/dapr/components/statestore.yaml create mode 100644 src/docker-compose/dapr/configuration/config.yaml create mode 100644 src/launchSettings.json diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1ff0c42 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,63 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eac456d --- /dev/null +++ b/.gitignore @@ -0,0 +1,265 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# 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 +.directory + +# 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 + + +**/docker-compose/rabbitmq \ No newline at end of file diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..7ab9427 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 Maksym Sadovnychyy (MAKS-IT) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..f4398ed --- /dev/null +++ b/README.md @@ -0,0 +1,45 @@ +# Dapr with ASP.NET Core in Docker Compose and Kubernetes deployment test + +> Warning: This project is not yet complete to run in Kubernetes. It is still in development. + +## Contribution + +Contributions to this project are welcome! Please fork the repository and submit a pull request with your changes. If you encounter any issues or have feature requests, feel free to open an issue on GitHub. + +## Contact + +If you have any questions or need further assistance, feel free to reach out: + +- **Email**: [maksym.sadovnychyy@gmail.com](mailto:maksym.sadovnychyy@gmail.com) + +## License + +This project is licensed under the MIT License. See the full license text below. + +--- + +### MIT License + +``` +MIT License + +Copyright (c) 2024 Maksym Sadovnychyy (MAKS-IT) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +``` diff --git a/src/.dockerignore b/src/.dockerignore new file mode 100644 index 0000000..fe1152b --- /dev/null +++ b/src/.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/src/Core/Commands/TestCommand.cs b/src/Core/Commands/TestCommand.cs new file mode 100644 index 0000000..10566e4 --- /dev/null +++ b/src/Core/Commands/TestCommand.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Core.Commands; +public class TestCommand { + [Required] + public required string Message { get; set; } +} diff --git a/src/Core/Core.csproj b/src/Core/Core.csproj new file mode 100644 index 0000000..fa71b7a --- /dev/null +++ b/src/Core/Core.csproj @@ -0,0 +1,9 @@ + + + + net8.0 + enable + enable + + + diff --git a/src/DaprNetTest.sln b/src/DaprNetTest.sln new file mode 100644 index 0000000..cfb55eb --- /dev/null +++ b/src/DaprNetTest.sln @@ -0,0 +1,65 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.11.35327.3 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Publisher", "Publisher\Publisher.csproj", "{74D466DA-71E2-4D59-B7DD-96DDE489D7E0}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Subscriber", "Subscriber\Subscriber.csproj", "{0310090C-DB06-4437-ABA1-04B5487AC49F}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core", "Core\Core.csproj", "{B565C0F4-2642-49A6-9A6F-9CAAC66F75EE}" +EndProject +Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-compose.dcproj", "{939576C3-1BFC-4500-BDB3-0521234AC1B4}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "dapr", "dapr", "{1501327C-BD39-4430-9E39-184B66816EEC}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "components", "components", "{C7F60667-661D-4B86-9554-39F6AB571E55}" + ProjectSection(SolutionItems) = preProject + docker-compose\dapr\components\pubsub.yaml = docker-compose\dapr\components\pubsub.yaml + docker-compose\dapr\components\statestore.yaml = docker-compose\dapr\components\statestore.yaml + EndProjectSection +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "configuration", "configuration", "{6A36CFD8-4BC5-45B5-9EA8-B57D6E2F88E5}" + ProjectSection(SolutionItems) = preProject + docker-compose\dapr\configuration\config.yaml = docker-compose\dapr\configuration\config.yaml + EndProjectSection +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "deployment", "deployment", "{1874EE05-F553-41AB-A8A7-3E9AE70AE70F}" + ProjectSection(SolutionItems) = preProject + deployment.yaml = deployment.yaml + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {74D466DA-71E2-4D59-B7DD-96DDE489D7E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {74D466DA-71E2-4D59-B7DD-96DDE489D7E0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {74D466DA-71E2-4D59-B7DD-96DDE489D7E0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {74D466DA-71E2-4D59-B7DD-96DDE489D7E0}.Release|Any CPU.Build.0 = Release|Any CPU + {0310090C-DB06-4437-ABA1-04B5487AC49F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0310090C-DB06-4437-ABA1-04B5487AC49F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0310090C-DB06-4437-ABA1-04B5487AC49F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0310090C-DB06-4437-ABA1-04B5487AC49F}.Release|Any CPU.Build.0 = Release|Any CPU + {B565C0F4-2642-49A6-9A6F-9CAAC66F75EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B565C0F4-2642-49A6-9A6F-9CAAC66F75EE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B565C0F4-2642-49A6-9A6F-9CAAC66F75EE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B565C0F4-2642-49A6-9A6F-9CAAC66F75EE}.Release|Any CPU.Build.0 = Release|Any CPU + {939576C3-1BFC-4500-BDB3-0521234AC1B4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {939576C3-1BFC-4500-BDB3-0521234AC1B4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {939576C3-1BFC-4500-BDB3-0521234AC1B4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {939576C3-1BFC-4500-BDB3-0521234AC1B4}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {C7F60667-661D-4B86-9554-39F6AB571E55} = {1501327C-BD39-4430-9E39-184B66816EEC} + {6A36CFD8-4BC5-45B5-9EA8-B57D6E2F88E5} = {1501327C-BD39-4430-9E39-184B66816EEC} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {6B523C08-C7BE-471D-9058-FD873C7131D5} + EndGlobalSection +EndGlobal diff --git a/src/Publisher/Controllers/DaprTestController.cs b/src/Publisher/Controllers/DaprTestController.cs new file mode 100644 index 0000000..f0fa6b8 --- /dev/null +++ b/src/Publisher/Controllers/DaprTestController.cs @@ -0,0 +1,34 @@ +using Core.Commands; +using MaksIT.Core.Dapr; +using MaksIT.Core.Extensions; +using Microsoft.AspNetCore.Mvc; +using Publisher.Models; +using System.Text.Json; + +namespace Publisher.Controllers; +[ApiController] +[Route("[controller]")] +public class DaprTestController : ControllerBase { + + private readonly ILogger _logger; + private readonly IDaprService _daprService; + + public DaprTestController( + ILogger logger, + IDaprService daprService + ) { + _logger = logger; + _daprService = daprService; + } + + [HttpPost(Name = "DaprTestPublisher")] + public async Task Post([FromBody] PostDaprTestRequest requestData) { + var result = await _daprService.PublishEventAsync( + "pubsub", + "test", + new TestCommand { + Message = requestData.Message + }.ToJson()); + return result.ToActionResult(); + } +} diff --git a/src/Publisher/Dockerfile b/src/Publisher/Dockerfile new file mode 100644 index 0000000..fc87e77 --- /dev/null +++ b/src/Publisher/Dockerfile @@ -0,0 +1,30 @@ +# 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. + +# This stage is used when running from VS in fast mode (Default for Debug configuration) +FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base +USER app +WORKDIR /app +EXPOSE 8080 + + +# This stage is used to build the service project +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build +ARG BUILD_CONFIGURATION=Release +WORKDIR /src +COPY ["Publisher/Publisher.csproj", "Publisher/"] +COPY ["Core/Core.csproj", "Core/"] +RUN dotnet restore "./Publisher/Publisher.csproj" +COPY . . +WORKDIR "/src/Publisher" +RUN dotnet build "./Publisher.csproj" -c $BUILD_CONFIGURATION -o /app/build + +# This stage is used to publish the service project to be copied to the final stage +FROM build AS publish +ARG BUILD_CONFIGURATION=Release +RUN dotnet publish "./Publisher.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false + +# This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration) +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "Publisher.dll"] \ No newline at end of file diff --git a/src/Publisher/Models/PostDaprTestRequest.cs b/src/Publisher/Models/PostDaprTestRequest.cs new file mode 100644 index 0000000..b16846d --- /dev/null +++ b/src/Publisher/Models/PostDaprTestRequest.cs @@ -0,0 +1,9 @@ +using MaksIT.Core.Abstractions.Webapi; +using System.ComponentModel.DataAnnotations; + +namespace Publisher.Models; + +public class PostDaprTestRequest : RequestModelBase { + [Required] + public required string Message { get; set; } +} diff --git a/src/Publisher/Program.cs b/src/Publisher/Program.cs new file mode 100644 index 0000000..d7cd91c --- /dev/null +++ b/src/Publisher/Program.cs @@ -0,0 +1,23 @@ +using MaksIT.Core.Dapr.Extensions; + +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. + +builder.Services.AddControllers(); +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); + +builder.Services.RegisterPublisher(); + +var app = builder.Build(); + +app.UseSwagger(); +app.UseSwaggerUI(); + +app.UseAuthorization(); + +app.MapControllers(); + +app.Run(); diff --git a/src/Publisher/Properties/launchSettings.json b/src/Publisher/Properties/launchSettings.json new file mode 100644 index 0000000..dc1d7cd --- /dev/null +++ b/src/Publisher/Properties/launchSettings.json @@ -0,0 +1,41 @@ +{ + "profiles": { + "http": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "dotnetRunMessages": true, + "applicationUrl": "http://localhost:5115" + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "Container (Dockerfile)": { + "commandName": "Docker", + "launchBrowser": true, + "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger", + "environmentVariables": { + "ASPNETCORE_HTTP_PORTS": "8080" + }, + "publishAllPorts": true, + "useSSL": false + } + }, + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:23454", + "sslPort": 0 + } + } +} \ No newline at end of file diff --git a/src/Publisher/Publisher.csproj b/src/Publisher/Publisher.csproj new file mode 100644 index 0000000..1b7be98 --- /dev/null +++ b/src/Publisher/Publisher.csproj @@ -0,0 +1,22 @@ + + + + net8.0 + enable + enable + Linux + ..\docker-compose.dcproj + + + + + + + + + + + + + + diff --git a/src/Publisher/Publisher.http b/src/Publisher/Publisher.http new file mode 100644 index 0000000..7eba8da --- /dev/null +++ b/src/Publisher/Publisher.http @@ -0,0 +1,6 @@ +@Publisher_HostAddress = http://localhost:5115 + +GET {{Publisher_HostAddress}}/weatherforecast/ +Accept: application/json + +### diff --git a/src/Publisher/appsettings.Development.json b/src/Publisher/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/src/Publisher/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/src/Publisher/appsettings.json b/src/Publisher/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/src/Publisher/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/src/Subscriber/Controllers/DaprTestController.cs b/src/Subscriber/Controllers/DaprTestController.cs new file mode 100644 index 0000000..69710b6 --- /dev/null +++ b/src/Subscriber/Controllers/DaprTestController.cs @@ -0,0 +1,30 @@ +using Core.Commands; +using Dapr; +using MaksIT.Core.Extensions; +using Microsoft.AspNetCore.Mvc; + +namespace Subscriber.Controllers; +[ApiController] +[Route("[controller]")] +public class DaprTestController : ControllerBase { + + private readonly ILogger _logger; + + public DaprTestController( + ILogger logger + ) { + _logger = logger; + } + + [Topic("pubsub", "test")] + [HttpPost(Name = "DaprTestSubscriber")] + public IActionResult Post([FromBody] string json) { + + var requestData = json.ToObject(); + if (requestData == null) + return BadRequest(); + + _logger.LogInformation("Received message: {0}", requestData.Message); + return Ok(); + } +} diff --git a/src/Subscriber/Dockerfile b/src/Subscriber/Dockerfile new file mode 100644 index 0000000..b78e470 --- /dev/null +++ b/src/Subscriber/Dockerfile @@ -0,0 +1,30 @@ +# 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. + +# This stage is used when running from VS in fast mode (Default for Debug configuration) +FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base +USER app +WORKDIR /app +EXPOSE 8080 + + +# This stage is used to build the service project +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build +ARG BUILD_CONFIGURATION=Release +WORKDIR /src +COPY ["Subscriber/Subscriber.csproj", "Subscriber/"] +COPY ["Core/Core.csproj", "Core/"] +RUN dotnet restore "./Subscriber/Subscriber.csproj" +COPY . . +WORKDIR "/src/Subscriber" +RUN dotnet build "./Subscriber.csproj" -c $BUILD_CONFIGURATION -o /app/build + +# This stage is used to publish the service project to be copied to the final stage +FROM build AS publish +ARG BUILD_CONFIGURATION=Release +RUN dotnet publish "./Subscriber.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false + +# This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration) +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "Subscriber.dll"] \ No newline at end of file diff --git a/src/Subscriber/Program.cs b/src/Subscriber/Program.cs new file mode 100644 index 0000000..3cf4590 --- /dev/null +++ b/src/Subscriber/Program.cs @@ -0,0 +1,24 @@ +using MaksIT.Core.Dapr.Extensions; + +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. + +builder.Services.AddControllers(); +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) { + +} + +app.UseAuthorization(); + +app.RegisterSubscriber(); + +app.MapControllers(); + +app.Run(); diff --git a/src/Subscriber/Properties/launchSettings.json b/src/Subscriber/Properties/launchSettings.json new file mode 100644 index 0000000..000c480 --- /dev/null +++ b/src/Subscriber/Properties/launchSettings.json @@ -0,0 +1,41 @@ +{ + "profiles": { + "http": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "dotnetRunMessages": true, + "applicationUrl": "http://localhost:5016" + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "Container (Dockerfile)": { + "commandName": "Docker", + "launchBrowser": true, + "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger", + "environmentVariables": { + "ASPNETCORE_HTTP_PORTS": "8080" + }, + "publishAllPorts": true, + "useSSL": false + } + }, + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:25735", + "sslPort": 0 + } + } +} \ No newline at end of file diff --git a/src/Subscriber/Subscriber.csproj b/src/Subscriber/Subscriber.csproj new file mode 100644 index 0000000..fe06490 --- /dev/null +++ b/src/Subscriber/Subscriber.csproj @@ -0,0 +1,21 @@ + + + + net8.0 + enable + enable + Linux + ..\docker-compose.dcproj + + + + + + + + + + + + + diff --git a/src/Subscriber/Subscriber.http b/src/Subscriber/Subscriber.http new file mode 100644 index 0000000..e62ccae --- /dev/null +++ b/src/Subscriber/Subscriber.http @@ -0,0 +1,6 @@ +@Subscriber_HostAddress = http://localhost:5016 + +GET {{Subscriber_HostAddress}}/weatherforecast/ +Accept: application/json + +### diff --git a/src/Subscriber/appsettings.Development.json b/src/Subscriber/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/src/Subscriber/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/src/Subscriber/appsettings.json b/src/Subscriber/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/src/Subscriber/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/src/deployment.yaml b/src/deployment.yaml new file mode 100644 index 0000000..94b0d13 --- /dev/null +++ b/src/deployment.yaml @@ -0,0 +1,56 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: publisher + namespace: dapr-test +spec: + replicas: 1 + selector: + matchLabels: + app: publisher + template: + metadata: + labels: + app: publisher + annotations: + dapr.io/enabled: "true" + dapr.io/app-id: "publisher" + dapr.io/app-port: "3000" + spec: + containers: + - name: publisher + image: daprio/quickstart-pubsub-publisher + ports: + - containerPort: 3000 + +--- + +apiVersion: apps/v1 +kind: Deployment +metadata: + name: subscriber + namespace: dapr-test +spec: + replicas: 1 + selector: + matchLabels: + app: subscriber + template: + metadata: + labels: + app: subscriber + annotations: + dapr.io/enabled: "true" + dapr.io/app-id: "subscriber" + dapr.io/app-port: "3001" + spec: + containers: + - name: subscriber + image: daprio/quickstart-pubsub-subscriber + ports: + - containerPort: 3001 + env: + - name: PUBSUB_TOPIC + value: "pubsub" # The topic used by pubsub component + - name: STATE_STORE + value: "statestore" # The name of your statestore component diff --git a/src/docker-compose.dcproj b/src/docker-compose.dcproj new file mode 100644 index 0000000..a316277 --- /dev/null +++ b/src/docker-compose.dcproj @@ -0,0 +1,19 @@ + + + + 2.1 + Linux + False + 939576c3-1bfc-4500-bdb3-0521234ac1b4 + LaunchBrowser + {Scheme}://localhost:{ServicePort}/swagger + publisher + + + + docker-compose.yml + + + + + \ No newline at end of file diff --git a/src/docker-compose.override.yml b/src/docker-compose.override.yml new file mode 100644 index 0000000..11d5bda --- /dev/null +++ b/src/docker-compose.override.yml @@ -0,0 +1,108 @@ + + +networks: + hello-dapr: + driver: "bridge" + +x-daprd-common: &daprd-common + image: "daprio/daprd:edge" + volumes: + - "./docker-compose/dapr/components/:/components" # Mount our components folder for the runtime to use. The mounted location must match the --resources-path argument. + - "./docker-compose/dapr/configuration/:/configuration" # Mount our configuration folder for the runtime to use. The mounted location must match the --config", "/configuration/config.yaml. + +services: + publisher-dapr: + <<: *daprd-common + command: [ + "./daprd", + "--app-id", "publisher", + "--app-port", "5000", + # "--enable-api-logging", + # "--log-level", "debug", + "--placement-host-address", "placement:50006", # Dapr's placement service can be reach via the docker DNS entry + "--config", "/configuration/config.yaml", + "--resources-path","./components", + "--components-path", "/components" + ] + depends_on: + - placement + - publisher + network_mode: "service:publisher" # Attach the publisher-dapr service to the publisher network namespace + + publisher: + environment: + - ASPNETCORE_ENVIRONMENT=Development + - ASPNETCORE_HTTP_PORTS=5000 + ports: + - "5000:5000" + networks: + - hello-dapr + + subscriber-dapr: + <<: *daprd-common + command: [ + "./daprd", + "--app-id", "subscriber", + "--app-port", "5000", + # "--enable-api-logging", + # "--log-level", "debug", + "--placement-host-address", "placement:50006", # Dapr's placement service can be reach via the docker DNS entry + "--config", "/configuration/config.yaml", + "--resources-path","./components", + "--components-path", "/components" + ] + depends_on: + - placement + - subscriber + network_mode: "service:subscriber" # Attach the subscriber-dapr service to the subscriber network namespace + + subscriber: + environment: + - ASPNETCORE_ENVIRONMENT=Development + - ASPNETCORE_HTTP_PORTS=5000 + ports: + - "5000" + networks: + - hello-dapr + + + placement: + command: [ + "./placement", + "--port", "50006", + #"--log-level", "debug" + ] + depends_on: + - rabbitmq + - redis + - zipkin + ports: + - "50006:50006" + networks: + - hello-dapr + + zipkin: + ports: + - "9411:9411" + networks: + - hello-dapr + + rabbitmq: + environment: + RABBITMQ_DEFAULT_USER: admin + RABBITMQ_DEFAULT_PASS: password + RABBITMQ_DEFAULT_VHOST: / + ports: + - "5672:5672" + - "15672:15672" + volumes: + - ./docker-compose/rabbitmq/lib:/var/lib/rabbitmq/ + - ./docker-compose/rabbitmq/log:/var/log/rabbitmq/ + networks: + - hello-dapr + + redis: + ports: + - "6380:6379" + networks: + - hello-dapr \ No newline at end of file diff --git a/src/docker-compose.yml b/src/docker-compose.yml new file mode 100644 index 0000000..a77dfe5 --- /dev/null +++ b/src/docker-compose.yml @@ -0,0 +1,39 @@ +services: + + publisher-dapr: + container_name: publisher-dapr + image: "daprio/daprd:edge" + + publisher: + container_name: publisher + image: ${DOCKER_REGISTRY-}publisher + build: + context: . + dockerfile: Publisher/Dockerfile + + subscriber-dapr: + container_name: subscriber-dapr + image: "daprio/daprd:edge" + + subscriber: + container_name: subscriber + image: ${DOCKER_REGISTRY-}subscriber + build: + context: . + dockerfile: Subscriber/Dockerfile + + placement: + container_name: placement + image: "daprio/dapr" + + zipkin: + container_name: zipkin + image: openzipkin/zipkin + + rabbitmq: + container_name: rabbitmq + image: rabbitmq:3.12.1-management-alpine + + redis: + container_name: redis + image: redis:alpine \ No newline at end of file diff --git a/src/docker-compose/dapr/components/pubsub.yaml b/src/docker-compose/dapr/components/pubsub.yaml new file mode 100644 index 0000000..1d10583 --- /dev/null +++ b/src/docker-compose/dapr/components/pubsub.yaml @@ -0,0 +1,21 @@ +apiVersion: dapr.io/v1alpha1 +kind: Component +metadata: + name: pubsub + namespace: dapr-test +spec: + type: pubsub.rabbitmq + version: v1 + metadata: + - name: connectionString + value: "amqp://admin:password@rabbitmq:5672" + - name: durable + value: "false" + - name: deletedWhenUnused + value: "false" + - name: autoAck + value: "true" + - name: reconnectWait + value: "0" + - name: concurrency + value: parallel diff --git a/src/docker-compose/dapr/components/statestore.yaml b/src/docker-compose/dapr/components/statestore.yaml new file mode 100644 index 0000000..1a26897 --- /dev/null +++ b/src/docker-compose/dapr/components/statestore.yaml @@ -0,0 +1,13 @@ +apiVersion: dapr.io/v1alpha1 +kind: Component +metadata: + name: statestore + namespace: dapr-test +spec: + type: state.redis + version: v1 + metadata: + - name: redisHost + value: redis:6379 + - name: actorStateStore + value: "true" diff --git a/src/docker-compose/dapr/configuration/config.yaml b/src/docker-compose/dapr/configuration/config.yaml new file mode 100644 index 0000000..363fd57 --- /dev/null +++ b/src/docker-compose/dapr/configuration/config.yaml @@ -0,0 +1,10 @@ +apiVersion: dapr.io/v1alpha1 +kind: Configuration +metadata: + name: daprConfig + namespace: default +spec: + tracing: + samplingRate: "1" + zipkin: + endpointAddress: "http://zipkin:9411/api/v2/spans" \ No newline at end of file diff --git a/src/launchSettings.json b/src/launchSettings.json new file mode 100644 index 0000000..b62cf02 --- /dev/null +++ b/src/launchSettings.json @@ -0,0 +1,12 @@ +{ + "profiles": { + "Docker Compose": { + "commandName": "DockerCompose", + "commandVersion": "1.0", + "serviceActions": { + "publisher": "StartDebugging", + "subscriber": "StartDebugging" + } + } + } +} \ No newline at end of file