feat: add docker support

This commit is contained in:
Guillermo Marcel 2025-02-17 22:20:51 -03:00
parent f94c6d5b2a
commit ba51677d98
8 changed files with 89 additions and 41 deletions

View File

@ -10,7 +10,7 @@
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.2" />
<PackageReference Include="Quartz" Version="3.13.1" />
<PackageReference Include="Quartz.Extensions.DependencyInjection" Version="3.13.1" />
<PackageReference Include="Quartz.Extensions.Hosting" Version="3.13.1" />
<!-- <PackageReference Include="Quartz.Extensions.Hosting" Version="3.13.1" />-->
</ItemGroup>
</Project>

View File

@ -25,6 +25,11 @@ public class AutoScanApp
public async Task Run(CancellationToken cancellationToken)
{
if (!_options.Enabled)
{
_logger.LogWarning("AutoScanApp is disabled!");
return;
}
_logger.LogInformation("AutoScanApp is running...");
var at = DateTime.Now.AddSeconds(10);

View File

@ -16,13 +16,10 @@ public static class DependencyInjectionExtensions
services.AddSingleton<FfmpegWrapper>();
services.AddSingleton<AutoScanApp>();
services.AddQuartz(q =>
{
q.UseMicrosoftDependencyInjectionJobFactory();
});
services.AddQuartz();
services.AddTransient<IChainerListenerFactory, ChainerListenerFactory>();
services.AddQuartzHostedService(q => q.WaitForJobsToComplete = true);
// services.AddQuartzHostedService(q => q.WaitForJobsToComplete = true);
services.AddSingleton<IScheduler>(sp =>
{

View File

@ -3,37 +3,37 @@ namespace AutoScan.Models;
//Bulk converted from endpoint response. TODO: Cleanup later, format properties names
public class VideoStorageLocations
{
public string dir { get; set; }
public string dir { get; set; } = "";
}
public class VideoActionLink
{
public string changeToRead { get; set; }
public string changeToUnread { get; set; }
public string deleteVideo { get; set; }
public string changeToRead { get; set; } = "";
public string changeToUnread { get; set; } = "";
public string deleteVideo { get; set; } = "";
}
public class FetchVideoResponse
{
public bool endIsStartTo { get; set; }
public bool ok { get; set; }
public List<VideoDetail> videos { get; set; }
public bool endIsStartTo { get; set; } = false;
public bool ok { get; set; } = true;
public List<VideoDetail> videos { get; set; } = [];
}
public class VideoDetail
{
public string actionUrl { get; set; }
public string actionUrl { get; set; } = "";
public int archive { get; set; }
public VideoStorageLocations details { get; set; }
public VideoStorageLocations? details { get; set; }
public DateTime end { get; set; }
public string ext { get; set; }
public string filename { get; set; }
public string href { get; set; }
public string ke { get; set; }
public VideoActionLink links { get; set; }
public string mid { get; set; }
public string objects { get; set; }
public object saveDir { get; set; }
public string ext { get; set; } = "";
public string filename { get; set; } = "";
public string href { get; set; } = "";
public string ke { get; set; } = "";
public VideoActionLink? links { get; set; }
public string mid { get; set; } = "";
public string objects { get; set; } = "";
public object? saveDir { get; set; }
public int size { get; set; }
public int status { get; set; }
public DateTime time { get; set; }

View File

@ -32,6 +32,11 @@ public class BotHandler
public void Start(CancellationToken cancellationToken)
{
_logger.LogInformation("Starting bot...");
if (string.IsNullOrEmpty(_telegramOptions.BotToken))
{
_logger.LogError("Bot token is not provided");
return;
}
_bot = new TelegramBotClient(_telegramOptions.BotToken, cancellationToken: cancellationToken);

View File

@ -6,6 +6,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<EnableSdkContainerSupport>true</EnableSdkContainerSupport>
</PropertyGroup>
<ItemGroup>

View File

@ -1,21 +1,62 @@
FROM mcr.microsoft.com/dotnet/runtime:9.0 AS base
USER $APP_UID
WORKDIR /app
#FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/runtime:9.0 AS base
#ARG TARGETARCH
#USER root
#WORKDIR /app
#
#FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
#ARG BUILD_CONFIGURATION=Release
#WORKDIR /src
#COPY ["CasaBotApp/CasaBotApp.csproj", "CasaBotApp/"]
#COPY ["AutoScan/AutoScan.csproj", "AutoScan/"]
#RUN dotnet restore "CasaBotApp/CasaBotApp.csproj" -a $TARGETARCH
#COPY . .
#WORKDIR "/src/CasaBotApp"
#RUN dotnet build "CasaBotApp.csproj" -c $BUILD_CONFIGURATION -o /app/build
#
#FROM build AS publish
#ARG BUILD_CONFIGURATION=Release
#RUN dotnet publish "CasaBotApp.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
#
#FROM base AS final
#
## Install pyhon and run "pipx install dvr-scan[opencv]" to install dependency
##RUN apt-get update && apt-get install -y python3 python3-pip python3-venv
##RUN python3 -m pip install dvr-scan[opencv] --break-system-packages
##RUN pip3 install pipx --break-system-packages
##RUN pipx install dvr-scan[opencv-headless]
#
#WORKDIR /app
#COPY --from=publish /app/publish .
##ENTRYPOINT ["dotnet", "CasaBotApp.dll"]
#
## interactive shell
#CMD ["/bin/bash"]
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
# Learn about building .NET container images:
# https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:9.0-noble AS build
ARG TARGETARCH
WORKDIR /source
# Copy project file and restore as distinct layers
#COPY --link *.csproj .
COPY ["CasaBotApp/CasaBotApp.csproj", "CasaBotApp/"]
RUN dotnet restore "CasaBotApp/CasaBotApp.csproj"
COPY . .
WORKDIR "/src/CasaBotApp"
RUN dotnet build "CasaBotApp.csproj" -c $BUILD_CONFIGURATION -o /app/build
COPY ["AutoScan/AutoScan.csproj", "AutoScan/"]
RUN dotnet restore "CasaBotApp/CasaBotApp.csproj" -a $TARGETARCH
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "CasaBotApp.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
# Copy source code and publish app
COPY --link . .
RUN dotnet publish "CasaBotApp/CasaBotApp.csproj" -a $TARGETARCH --no-restore -o /app
FROM base AS final
# Runtime stage
#FROM mcr.microsoft.com/dotnet/runtime:9.0-noble
FROM mcr.microsoft.com/dotnet/aspnet:9.0-noble
WORKDIR /app
COPY --from=publish /app/publish .
COPY --link --from=build /app .
USER $APP_UID
ENTRYPOINT ["dotnet", "CasaBotApp.dll"]
#CMD ["/bin/bash"]

View File

@ -20,7 +20,6 @@ services.AddSingleton(configuration);
services.AddLogging(builder =>
{
builder.AddConfiguration(configuration.GetSection("Logging"));
// builder.AddConsole();
//add time to logs
builder.AddSimpleConsole(options =>
{
@ -48,8 +47,8 @@ var autoScanApp = serviceProvider.GetService<AutoScanApp>()!;
using var cts = new CancellationTokenSource();
autoScanApp.Run(cts.Token);
// botHandler.Start(cts.Token);
_ = autoScanApp.Run(cts.Token);
botHandler.Start(cts.Token);
_ = SendMessageToSubscribers(cts.Token);