add Dockerfile

This commit is contained in:
2026-01-27 14:55:15 +03:30
parent 9bca1b81d6
commit a745dfff86
5 changed files with 165 additions and 1 deletions

18
.gitignore vendored
View File

@@ -1,3 +1,21 @@
.env*
.env
certs/*.pfx
certs/*.pem
certs/*.key
certs/*.crt
Storage/
Logs/
*.user
*.suo
bin/
obj/
certs/*.pfx
certs/*.pem
certs/*.key
certs/*.crt
Storage/
Logs/
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##

78
ServiceHost/Dockerfile Normal file
View File

@@ -0,0 +1,78 @@
# Multi-stage build for ASP.NET Core 10
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
WORKDIR /src.
# Copy solution and project files
COPY ["DadmehrGostar.sln", "DadmehrGostar.sln"]
COPY ["ServiceHost/ServiceHost.csproj", "ServiceHost/"]
COPY ["0_Framework/0_Framework.csproj", "0_Framework/"]
COPY ["_0_Framework/_0_Framework_b.csproj", "_0_Framework/"]
COPY ["AccountManagement.Application/AccountManagement.Application.csproj", "AccountManagement.Application/"]
COPY ["AccountManagement.Application.Contracts/AccountManagement.Application.Contracts.csproj", "AccountManagement.Application.Contracts/"]
COPY ["AccountManagement.Configuration/AccountManagement.Configuration.csproj", "AccountManagement.Configuration/"]
COPY ["AccountManagement.Domain/AccountManagement.Domain.csproj", "AccountManagement.Domain/"]
COPY ["AccountMangement.Infrastructure.EFCore/AccountMangement.Infrastructure.EFCore.csproj", "AccountMangement.Infrastructure.EFCore/"]
COPY ["BackgroundInstitutionContract/BackgroundInstitutionContract.Task/BackgroundInstitutionContract.Task.csproj", "BackgroundInstitutionContract/BackgroundInstitutionContract.Task/"]
COPY ["BackgroundJobs/BackgroundJobs.Task/BackgroundJobs.Task.csproj", "BackgroundJobs/BackgroundJobs.Task/"]
COPY ["backService/backService.csproj", "backService/"]
COPY ["Company.Domain/Company.Domain.csproj", "Company.Domain/"]
COPY ["CompanyManagement.Infrastructure.Excel/CompanyManagement.Infrastructure.Excel.csproj", "CompanyManagement.Infrastructure.Excel/"]
COPY ["CompanyManagement.Infrastructure.Mongo/CompanyManagement.Infrastructure.Mongo.csproj", "CompanyManagement.Infrastructure.Mongo/"]
COPY ["CompanyManagment.App.Contracts/CompanyManagment.App.Contracts.csproj", "CompanyManagment.App.Contracts/"]
COPY ["CompanyManagment.Application/CompanyManagment.Application.csproj", "CompanyManagment.Application/"]
COPY ["CompanyManagment.EFCore/CompanyManagment.EFCore.csproj", "CompanyManagment.EFCore/"]
COPY ["PersonalContractingParty.Config/PersonalContractingParty.Config.csproj", "PersonalContractingParty.Config/"]
COPY ["ProgramManager/src/Application/GozareshgirProgramManager.Application/GozareshgirProgramManager.Application.csproj", "ProgramManager/src/Application/GozareshgirProgramManager.Application/"]
COPY ["ProgramManager/src/Domain/GozareshgirProgramManager.Domain/GozareshgirProgramManager.Domain.csproj", "ProgramManager/src/Domain/GozareshgirProgramManager.Domain/"]
COPY ["ProgramManager/src/Infrastructure/GozareshgirProgramManager.Infrastructure/GozareshgirProgramManager.Infrastructure.csproj", "ProgramManager/src/Infrastructure/GozareshgirProgramManager.Infrastructure/"]
COPY ["Query/Query.csproj", "Query/"]
COPY ["Query.Bootstrapper/Query.Bootstrapper.csproj", "Query.Bootstrapper/"]
COPY ["Shared.Contracts/Shared.Contracts.csproj", "Shared.Contracts/"]
COPY ["WorkFlow/Application/WorkFlow.Application/WorkFlow.Application.csproj", "WorkFlow/Application/WorkFlow.Application/"]
COPY ["WorkFlow/Application/WorkFlow.Application.Contracts/WorkFlow.Application.Contracts.csproj", "WorkFlow/Application/WorkFlow.Application.Contracts/"]
COPY ["WorkFlow/Domain/WorkFlow.Domain/WorkFlow.Domain.csproj", "WorkFlow/Domain/WorkFlow.Domain/"]
COPY ["WorkFlow/Infrastructure/WorkFlow.Infrastructure.ACL/WorkFlow.Infrastructure.ACL.csproj", "WorkFlow/Infrastructure/WorkFlow.Infrastructure.ACL/"]
COPY ["WorkFlow/Infrastructure/WorkFlow.Infrastructure.Config/WorkFlow.Infrastructure.Config.csproj", "WorkFlow/Infrastructure/WorkFlow.Infrastructure.Config/"]
COPY ["WorkFlow/Infrastructure/WorkFlow.Infrastructure.EfCore/WorkFlow.Infrastructure.EfCore.csproj", "WorkFlow/Infrastructure/WorkFlow.Infrastructure.EfCore/"]
# Restore all projects
RUN dotnet restore "DadmehrGostar.sln"
# Copy source code
COPY . .
# Build the ServiceHost project
WORKDIR /src/ServiceHost
RUN dotnet build "ServiceHost.csproj" -c Release -o /app/build
# Publish stage
FROM build AS publish
RUN dotnet publish "ServiceHost.csproj" -c Release -o /app/publish /p:UseAppHost=false
# Runtime stage
FROM mcr.microsoft.com/dotnet/aspnetcore:10.0 AS final
WORKDIR /app
# Install curl for health checks
RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
# Copy published app
COPY --from=publish /app/publish .
# Create directories for certificates, storage, and logs
RUN mkdir -p /app/certs /app/Storage /app/Logs && \
chmod 755 /app/certs /app/Storage /app/Logs
# Expose ports
EXPOSE 80 443
# Health check - check both HTTP and HTTPS
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD curl -f http://localhost:80/health || curl -f -k https://localhost:443/health || exit 1
# Set entry point
ENTRYPOINT ["dotnet", "ServiceHost.dll"]

View File

@@ -56,7 +56,10 @@ var connectionString = builder.Configuration.GetConnectionString("MesbahDb");
var connectionStringTestDb = builder.Configuration.GetConnectionString("TestDb");
#region Serilog
var logDirectory = @"C:\Logs\Gozareshgir\";
// Use Docker-compatible log path
var logDirectory = builder.Environment.IsDevelopment()
? @"C:\Logs\Gozareshgir\"
: "/app/Logs";
if (!Directory.Exists(logDirectory))
{
@@ -541,6 +544,9 @@ app.MapHub<ProjectBoardHub>("api/pm/board");
app.MapRazorPages();
app.MapControllers();
// Health check endpoint for Docker
app.MapGet("/health", () => Results.Ok(new { status = "Healthy", timestamp = DateTime.UtcNow }));
#endregion
app.Run();

View File

@@ -47,6 +47,17 @@
"applicationUrl": "https://localhost:5004;http://localhost:5003;",
"jsWebView2Debugging": false,
"hotReloadEnabled": true
},
"Docker": {
"commandName": "DockerCompose",
"commandLineArgs": "up",
"dockerComposeProjectPath": "..\\docker-compose.yml",
"launchBrowser": true,
"launchUrl": "https://localhost:5004",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"useSSL": true
}
},
"iisSettings": {

51
docker-compose.yml Normal file
View File

@@ -0,0 +1,51 @@
version: '3.8'
services:
# ASP.NET Core Application with HTTPS Support
servicehost:
build:
context: .
dockerfile: ServiceHost/Dockerfile
container_name: gozareshgir-servicehost
env_file:
- .env
environment:
- ASPNETCORE_ENVIRONMENT=${ASPNETCORE_ENVIRONMENT:-Development}
- ASPNETCORE_URLS=${ASPNETCORE_URLS:-https://+:443;http://+:80}
- ASPNETCORE_Kestrel__Certificates__Default__Password=${CERT_PASSWORD}
- ASPNETCORE_Kestrel__Certificates__Default__Path=/app/certs/aspnetcore.pfx
- ConnectionStrings__MesbahDb=${ConnectionStrings__MesbahDb}
- ConnectionStrings__TestDb=${ConnectionStrings__TestDb}
- MongoDb__ConnectionString=${MongoDb__ConnectionString}
- MongoDb__DatabaseName=${MongoDb__DatabaseName}
- Domain=${Domain}
- FileStorage__LocalPath=${FileStorage__LocalPath:-/app/Storage}
ports:
- "${HTTP_PORT:-5003}:80"
- "${HTTPS_PORT:-5004}:443"
volumes:
- ./ServiceHost/certs:/app/certs:ro
- app_storage:/app/Storage
- app_logs:/app/Logs
networks:
- gozareshgir-network
extra_hosts:
- "host.docker.internal:host-gateway"
healthcheck:
test: ["CMD", "curl", "-f", "-k", "https://localhost:443/health", "||", "exit", "1"]
interval: 30s
timeout: 10s
start_period: 40s
retries: 3
restart: unless-stopped
networks:
gozareshgir-network:
driver: bridge
volumes:
app_storage:
driver: local
app_logs:
driver: local