From 26d569f78293b4fd592e52b8e6e7f488d290ba50 Mon Sep 17 00:00:00 2001 From: PramodMahajan14 Date: Fri, 28 Mar 2025 17:39:01 +0530 Subject: [PATCH] added Docker file --- .dockerignore | 30 +++++++++++++++++ .../Controllers/AuthController.cs | 8 +++-- Marco.Pms.Services/Dockerfile | 33 +++++++++++++++++++ Marco.Pms.Services/Marco.Pms.Services.csproj | 1 + Marco.Pms.Services/Program.cs | 5 +-- Marco.Pms.Services/appsettings.json | 24 +++++++------- 6 files changed, 84 insertions(+), 17 deletions(-) create mode 100644 .dockerignore create mode 100644 Marco.Pms.Services/Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..fe1152b --- /dev/null +++ b/.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/Marco.Pms.Services/Controllers/AuthController.cs b/Marco.Pms.Services/Controllers/AuthController.cs index 2259142..3d341ca 100644 --- a/Marco.Pms.Services/Controllers/AuthController.cs +++ b/Marco.Pms.Services/Controllers/AuthController.cs @@ -159,15 +159,17 @@ namespace MarcoBMS.Services.Controllers var isTokenValid = await _userManager.VerifyUserTokenAsync( user, TokenOptions.DefaultProvider, // This is the token provider - UserManager.ResetPasswordTokenPurpose, - WebUtility.UrlDecode( model.Token) + // UserManager.ResetPasswordTokenPurpose, + //WebUtility.UrlDecode( model.Token) + UserManager.ResetPasswordTokenPurpose, model.Token + //WebUtility.UrlDecode( model.Token) ); if (!isTokenValid) return BadRequest("Invalid or expired token."); - var result = await _userManager.ResetPasswordAsync(user, WebUtility.UrlDecode(model.Token), model.NewPassword); + var result = await _userManager.ResetPasswordAsync(user, model.Token, model.NewPassword); if (!result.Succeeded) return BadRequest(result.Errors); diff --git a/Marco.Pms.Services/Dockerfile b/Marco.Pms.Services/Dockerfile new file mode 100644 index 0000000..6ee3148 --- /dev/null +++ b/Marco.Pms.Services/Dockerfile @@ -0,0 +1,33 @@ +# 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_UID +WORKDIR /app +EXPOSE 8080 +EXPOSE 8081 + + +# 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 ["Marco.Pms.Services/Marco.Pms.Services.csproj", "Marco.Pms.Services/"] +COPY ["Marco.Pms.DataAccess/Marco.Pms.DataAccess.csproj", "Marco.Pms.DataAccess/"] +COPY ["Marco.Pms.Model/Marco.Pms.Model.csproj", "Marco.Pms.Model/"] +COPY ["Marco.Pms.Utility/Marco.Pms.Utility.csproj", "Marco.Pms.Utility/"] +RUN dotnet restore "./Marco.Pms.Services/Marco.Pms.Services.csproj" +COPY . . +WORKDIR "/src/Marco.Pms.Services" +RUN dotnet build "./Marco.Pms.Services.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 "./Marco.Pms.Services.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", "Marco.Pms.Services.dll"] \ No newline at end of file diff --git a/Marco.Pms.Services/Marco.Pms.Services.csproj b/Marco.Pms.Services/Marco.Pms.Services.csproj index 4e70e23..c565785 100644 --- a/Marco.Pms.Services/Marco.Pms.Services.csproj +++ b/Marco.Pms.Services/Marco.Pms.Services.csproj @@ -27,6 +27,7 @@ + diff --git a/Marco.Pms.Services/Program.cs b/Marco.Pms.Services/Program.cs index a01ea0e..2c343f8 100644 --- a/Marco.Pms.Services/Program.cs +++ b/Marco.Pms.Services/Program.cs @@ -12,7 +12,7 @@ using Microsoft.OpenApi.Models; using Serilog; using System.Text; - +Serilog.Debugging.SelfLog.Enable(Console.Error); var builder = WebApplication.CreateBuilder(args); @@ -146,8 +146,9 @@ if (app.Environment.IsDevelopment()) app.UseSwagger(); app.UseSwaggerUI(); // Use CORS in the pipeline - app.UseCors("DevCorsPolicy"); + } +app.UseCors("DevCorsPolicy"); app.UseStaticFiles(); // Enables serving static files diff --git a/Marco.Pms.Services/appsettings.json b/Marco.Pms.Services/appsettings.json index 868c367..f0e008a 100644 --- a/Marco.Pms.Services/appsettings.json +++ b/Marco.Pms.Services/appsettings.json @@ -21,16 +21,16 @@ "configure": [ { "Name": "MongoDB", - "Args": { - "databaseUrl": "mongodb://localhost:27017/DotNetLogs", - //"databaseUrl": "mongodb://devuser:xxxxx@147.93.98.152:27017/MarcoPMS?authSource=admin", - "collectionName": "application_logs", - "batchPostingLimit": 50, - "cappedMaxSizeMb": "1024", - "cappedMaxDocuments": "1000", - "rollingInterval": "Day" - //"outputTemplate": "[{Timestamp:yyyy/MM/dd HH:mm} {Level:u3}] {SourceContext}:{NewLine} {Message:lj}{Exception}{NewLine}" - } + "Args": { + //"databaseUrl": "mongodb://localhost:27017/DotNetLogs", + "databaseUrl": "mongodb+srv://rootuser:marco123@marcocluster.xi93iig.mongodb.net/marcoCluster?retryWrites=true&w=majority", + "collectionName": "application_logs", + "batchPostingLimit": 50, + "cappedMaxSizeMb": "1024", + "cappedMaxDocuments": "1000", + "rollingInterval": "Day" + //"outputTemplate": "[{Timestamp:yyyy/MM/dd HH:mm} {Level:u3}] {SourceContext}:{NewLine} {Message:lj}{Exception}{NewLine}" + } }, { "Name": "File", @@ -64,8 +64,8 @@ "ConnectionStrings": { // "DefaultConnectionString": "Server=103.50.160.45;User ID=marcowvh_admin;Password=Marcoemp@123;Database=marcowvh_empattendanceci", - "DefaultConnectionString": "Server=localhost;port=3333;User ID=root;Password=root;Database=MarcoBMS1", - // "DefaultConnectionString": "Server=147.93.98.152;User ID=devuser;Password=AppUser@123$;Database=MarcoBMS1" + //"DefaultConnectionString": "Server=localhost;port=3306;User ID=root;Password=root;Database=MarcoBMS1", + "DefaultConnectionString": "Server=147.93.98.152;User ID=devuser;Password=AppUser@123$;Database=MarcoBMS1" }, "AppSettings": { "WebFrontendUrl": "http://localhost:5173",