feat(templateUpdater): основная логика + cicd

This commit is contained in:
Mikhail Trubnikov
2025-12-04 08:23:57 +10:00
parent 74419c0435
commit df9c29358c
20 changed files with 622 additions and 4 deletions

View File

@@ -0,0 +1,34 @@
# 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 10.99.253.167:8090/dotnet/runtime:7.0 AS base
WORKDIR /app
# This stage is used to build the service project
FROM 10.99.253.167:8090/dotnet/sdk:7.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["NuGet.config", "."]
COPY ["PARR.TemplateUpdaterWorker/PARR.TemplateUpdaterWorker.csproj", "PARR.TemplateUpdaterWorker/"]
COPY ["PARR.TemplateUpdater/PARR.TemplateUpdater.csproj", "PARR.TemplateUpdater/"]
COPY ["PARR.BLL/PARR.BLL.csproj", "PARR.BLL/"]
COPY ["PARR.Common/PARR.Common.csproj", "PARR.Common/"]
COPY ["PARR.Constants/PARR.Constants.csproj", "PARR.Constants/"]
COPY ["PARR.DAL/PARR.DAL.csproj", "PARR.DAL/"]
RUN dotnet restore "./PARR.TemplateUpdaterWorker/PARR.TemplateUpdaterWorker.csproj"
COPY . .
WORKDIR "/src/PARR.TemplateUpdaterWorker"
RUN dotnet build "./PARR.TemplateUpdaterWorker.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 app_version=0.0.0-default
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./PARR.TemplateUpdaterWorker.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false /p:Version=$app_version
# 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", "PARR.TemplateUpdaterWorker.dll"]

View File

@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk.Worker">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>dotnet-PARR.TemplateUpdaterWorker-413e055b-7f45-4b87-bbb3-28a3427d03f2</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Elastic.CommonSchema.Serilog" Version="8.6.1" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.23.0" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="7.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="7.0.1" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PARR.TemplateUpdater\PARR.TemplateUpdater.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,31 @@
using Elastic.CommonSchema.Serilog;
using PARR.TemplateUpdater;
using PARR.TemplateUpdaterWorker;
using Serilog;
var builder = Host.CreateApplicationBuilder();
builder.Services.AddLogging(config =>
{
config.ClearProviders();
var logger = new LoggerConfiguration();
if (builder.Environment.IsProduction())
logger.WriteTo.Console(new EcsTextFormatter());
else
logger.WriteTo.Console();
logger.ReadFrom.Configuration(builder.Configuration);
config.AddSerilog(logger.CreateLogger());
});
builder.Services.InstallTemplateUpdaterServices(builder.Configuration);
builder.Configuration.AddTemplateUpdaterConfigurations(builder.Services);
builder.Services.AddTemplateUpdaterSettings(builder.Configuration);
builder.Services.AddHostedService<Worker>();
var host = builder.Build();
host.Run();

View File

@@ -0,0 +1,14 @@
{
"profiles": {
"PARR.TemplateUpdaterWorker": {
"commandName": "Project",
"environmentVariables": {
"DOTNET_ENVIRONMENT": "Development"
},
"dotnetRunMessages": true
},
"Container (Dockerfile)": {
"commandName": "Docker"
}
}
}

View File

@@ -0,0 +1,29 @@
using PARR.TemplateUpdater;
namespace PARR.TemplateUpdaterWorker
{
public class Worker : BackgroundService
{
private readonly ILogger<Worker> _logger;
private readonly ITemplateUpdater templateUpdater;
public Worker(ILogger<Worker> logger, ITemplateUpdater templateUpdater)
{
_logger = logger;
this.templateUpdater = templateUpdater;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
await templateUpdater.StartAsync();
await Task.Delay(Timeout.Infinite, stoppingToken);
}
public override async Task StopAsync(CancellationToken cancellationToken)
{
await templateUpdater.StopAsync();
await base.StopAsync(cancellationToken);
}
}
}

View File

@@ -0,0 +1,31 @@
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"Microsoft.AspNetCore": "Debug"
}
},
"Serilog": {
"MinimumLevel": {
"Default": "Debug",
"Override": {
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "log/log-.txt",
"rollingInterval": "Day"
}
}
]
},
"MqSettings": {
"TemplatesUpdater": {
"HostName": "10.99.253.216"
}
}
}

View File

@@ -0,0 +1,28 @@
{
"ConnectionStrings": {
"DefaultConnection": "Server=10.99.253.184;Database=parr;User Id=app_parr; Password=PosdfkhT&)%sdfligL&%5546;"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"Serilog": {
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
}
},
"MqSettings": {
"TemplatesUpdater": {
"HostName": "parr-rabbitmq",
"QueueName": "parr-template-updater",
"User": "template_updater_reader",
"Password": "JfdsfUFJJh2255&*&F1"
}
}
}