From 29d60f5a52ba5acbf89797d9451c89322775bce4 Mon Sep 17 00:00:00 2001 From: babaktaremi Date: Tue, 8 Aug 2023 00:29:17 +0330 Subject: [PATCH] DockerFile And Docker-compose added --- CleanArcTemplate.nuspec | 4 +-- Dockerfile | 34 +++++++++++++++++++ docker-compose.yml | 22 ++++++++++++ .../CleanArc.Web.Api/CleanArc.Web.Api.csproj | 6 ++++ .../appsettings.Development.json | 3 ++ src/API/CleanArc.Web.Api/appsettings.json | 2 +- 6 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/CleanArcTemplate.nuspec b/CleanArcTemplate.nuspec index e2c697d..48f0302 100644 --- a/CleanArcTemplate.nuspec +++ b/CleanArcTemplate.nuspec @@ -3,7 +3,7 @@ Bobby.CleanArcTemplate - 4.0.6 + 4.1.0 Clean Architecture Solution Template BabakTaremi Clean Architecture Solution Template for and .NET 7. With many features available out of the box @@ -11,7 +11,7 @@ Ready to develop template based on clean architecture principles. Supports ASP NET Core Identity integrated with JWE tokens, OTP authentication, stand alone plugin development, CQRS pattern using MediatR library and dynamic permission management system out of the box - Unit Test Setups added. Also database is now easy to test with Sqlite in memory feature. + Docker file and docker-compose file added. know you can build image and run the project on docker container diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..52d0805 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,34 @@ +#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. + +FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base +WORKDIR /app +EXPOSE 80 +EXPOSE 443 + +FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build +WORKDIR /src +COPY ["src/API/CleanArc.Web.Api/CleanArc.Web.Api.csproj", "src/API/CleanArc.Web.Api/"] +COPY ["src/API/CleanArc.WebFramework/CleanArc.WebFramework.csproj", "src/API/CleanArc.WebFramework/"] +COPY ["src/API/Plugins/CleanArc.Web.Plugins.Grpc/CleanArc.Web.Plugins.Grpc.csproj", "src/API/Plugins/CleanArc.Web.Plugins.Grpc/"] +COPY ["src/Core/CleanArc.Application/CleanArc.Application.csproj", "src/Core/CleanArc.Application/"] +COPY ["src/Core/CleanArc.Domain/CleanArc.Domain.csproj", "src/Core/CleanArc.Domain/"] +COPY ["src/Infrastructure/CleanArc.Infrastructure.CrossCutting/CleanArc.Infrastructure.CrossCutting.csproj", "src/Infrastructure/CleanArc.Infrastructure.CrossCutting/"] +COPY ["src/Infrastructure/CleanArc.Infrastructure.Identity/CleanArc.Infrastructure.Identity.csproj", "src/Infrastructure/CleanArc.Infrastructure.Identity/"] +COPY ["src/Infrastructure/CleanArc.Infrastructure.Persistence/CleanArc.Infrastructure.Persistence.csproj", "src/Infrastructure/CleanArc.Infrastructure.Persistence/"] +COPY ["src/Shared/CleanArc.SharedKernel/CleanArc.SharedKernel.csproj", "src/Shared/CleanArc.SharedKernel/"] +COPY ["src/Tests/CleanArc.Test.Infrastructure.Identity/CleanArc.Test.Infrastructure.Identity/CleanArc.Test.Infrastructure.Identity.csproj", "src/Tests/CleanArc.Test.Infrastructure.Identity/CleanArc.Test.Infrastructure.Identity/"] +COPY ["src/Tests/CleanArc.Tests.Setup/CleanArc.Tests.Setup.csproj", "src/Tests/CleanArc.Tests.Setup/"] + + +RUN dotnet restore "src/API/CleanArc.Web.Api/CleanArc.Web.Api.csproj" +COPY . . +WORKDIR "src/API/CleanArc.Web.Api" +RUN dotnet build "CleanArc.Web.Api.csproj" -c Release -o /app/build + +FROM build AS publish +RUN dotnet publish "CleanArc.Web.Api.csproj" -c Release -o /app/publish /p:UseAppHost=false --no-restore + +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "CleanArc.Web.Api.dll"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..133fa4a --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,22 @@ +version: "3.9" # optional since v1.27.0 +services: + web_api: + image: bobby-cleanarc + container_name: bobby-cleanarc-app + environment: + "ASPNETCORE_URLS": "https://+;http://+" + "ASPNETCORE_Kestrel__Certificates__Default__Password": "Strong@Password" + "ASPNETCORE_Kestrel__Certificates__Default__Path": "/https/cleanarc.pfx" + ports: + - "5000:80" + - "5001:443" + volumes: + - ~/.aspnet/https:/https + sql: + image: "mcr.microsoft.com/mssql/server:2022-latest" + container_name: sql_server2022 + ports: # not actually needed, because the two services are on the same network + - "1435:1433" + environment: + - ACCEPT_EULA=y + - SA_PASSWORD=A&VeryComplex123Password diff --git a/src/API/CleanArc.Web.Api/CleanArc.Web.Api.csproj b/src/API/CleanArc.Web.Api/CleanArc.Web.Api.csproj index 87d863c..ce98b3f 100644 --- a/src/API/CleanArc.Web.Api/CleanArc.Web.Api.csproj +++ b/src/API/CleanArc.Web.Api/CleanArc.Web.Api.csproj @@ -27,4 +27,10 @@ + + + Always + + + diff --git a/src/API/CleanArc.Web.Api/appsettings.Development.json b/src/API/CleanArc.Web.Api/appsettings.Development.json index 8983e0f..c6b09fb 100644 --- a/src/API/CleanArc.Web.Api/appsettings.Development.json +++ b/src/API/CleanArc.Web.Api/appsettings.Development.json @@ -1,4 +1,7 @@ { + "ConnectionStrings": { + "SqlServer": "Data Source=localhost;Initial Catalog=CleanArc_DB_7_3;Integrated Security=true;Encrypt=False" + }, "Logging": { "LogLevel": { "Default": "Information", diff --git a/src/API/CleanArc.Web.Api/appsettings.json b/src/API/CleanArc.Web.Api/appsettings.json index 79c124e..60653ce 100644 --- a/src/API/CleanArc.Web.Api/appsettings.json +++ b/src/API/CleanArc.Web.Api/appsettings.json @@ -1,6 +1,6 @@ { "ConnectionStrings": { - "SqlServer": "Data Source=localhost;Initial Catalog=CleanArc_DB_7_3;Integrated Security=true;Encrypt=False" + "SqlServer": "Server=sql_server2022;Database=CleanArc_DB_Docker;User Id=SA;Password=A&VeryComplex123Password;MultipleActiveResultSets=true;encrypt=false" }, "IdentitySettings": { "SecretKey": "LongerThan-16Char-SecretKey",