feat: add docker support
This commit is contained in:
parent
f94c6d5b2a
commit
ba51677d98
@ -10,7 +10,7 @@
|
|||||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.2" />
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.2" />
|
||||||
<PackageReference Include="Quartz" Version="3.13.1" />
|
<PackageReference Include="Quartz" Version="3.13.1" />
|
||||||
<PackageReference Include="Quartz.Extensions.DependencyInjection" 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>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -25,6 +25,11 @@ public class AutoScanApp
|
|||||||
|
|
||||||
public async Task Run(CancellationToken cancellationToken)
|
public async Task Run(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
|
if (!_options.Enabled)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("AutoScanApp is disabled!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
_logger.LogInformation("AutoScanApp is running...");
|
_logger.LogInformation("AutoScanApp is running...");
|
||||||
|
|
||||||
var at = DateTime.Now.AddSeconds(10);
|
var at = DateTime.Now.AddSeconds(10);
|
||||||
|
@ -16,13 +16,10 @@ public static class DependencyInjectionExtensions
|
|||||||
|
|
||||||
services.AddSingleton<FfmpegWrapper>();
|
services.AddSingleton<FfmpegWrapper>();
|
||||||
services.AddSingleton<AutoScanApp>();
|
services.AddSingleton<AutoScanApp>();
|
||||||
services.AddQuartz(q =>
|
services.AddQuartz();
|
||||||
{
|
|
||||||
q.UseMicrosoftDependencyInjectionJobFactory();
|
|
||||||
});
|
|
||||||
services.AddTransient<IChainerListenerFactory, ChainerListenerFactory>();
|
services.AddTransient<IChainerListenerFactory, ChainerListenerFactory>();
|
||||||
|
|
||||||
services.AddQuartzHostedService(q => q.WaitForJobsToComplete = true);
|
// services.AddQuartzHostedService(q => q.WaitForJobsToComplete = true);
|
||||||
|
|
||||||
services.AddSingleton<IScheduler>(sp =>
|
services.AddSingleton<IScheduler>(sp =>
|
||||||
{
|
{
|
||||||
|
@ -3,37 +3,37 @@ namespace AutoScan.Models;
|
|||||||
//Bulk converted from endpoint response. TODO: Cleanup later, format properties names
|
//Bulk converted from endpoint response. TODO: Cleanup later, format properties names
|
||||||
public class VideoStorageLocations
|
public class VideoStorageLocations
|
||||||
{
|
{
|
||||||
public string dir { get; set; }
|
public string dir { get; set; } = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public class VideoActionLink
|
public class VideoActionLink
|
||||||
{
|
{
|
||||||
public string changeToRead { get; set; }
|
public string changeToRead { get; set; } = "";
|
||||||
public string changeToUnread { get; set; }
|
public string changeToUnread { get; set; } = "";
|
||||||
public string deleteVideo { get; set; }
|
public string deleteVideo { get; set; } = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public class FetchVideoResponse
|
public class FetchVideoResponse
|
||||||
{
|
{
|
||||||
public bool endIsStartTo { get; set; }
|
public bool endIsStartTo { get; set; } = false;
|
||||||
public bool ok { get; set; }
|
public bool ok { get; set; } = true;
|
||||||
public List<VideoDetail> videos { get; set; }
|
public List<VideoDetail> videos { get; set; } = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public class VideoDetail
|
public class VideoDetail
|
||||||
{
|
{
|
||||||
public string actionUrl { get; set; }
|
public string actionUrl { get; set; } = "";
|
||||||
public int archive { get; set; }
|
public int archive { get; set; }
|
||||||
public VideoStorageLocations details { get; set; }
|
public VideoStorageLocations? details { get; set; }
|
||||||
public DateTime end { get; set; }
|
public DateTime end { get; set; }
|
||||||
public string ext { get; set; }
|
public string ext { get; set; } = "";
|
||||||
public string filename { get; set; }
|
public string filename { get; set; } = "";
|
||||||
public string href { get; set; }
|
public string href { get; set; } = "";
|
||||||
public string ke { get; set; }
|
public string ke { get; set; } = "";
|
||||||
public VideoActionLink links { get; set; }
|
public VideoActionLink? links { get; set; }
|
||||||
public string mid { get; set; }
|
public string mid { get; set; } = "";
|
||||||
public string objects { get; set; }
|
public string objects { get; set; } = "";
|
||||||
public object saveDir { get; set; }
|
public object? saveDir { get; set; }
|
||||||
public int size { get; set; }
|
public int size { get; set; }
|
||||||
public int status { get; set; }
|
public int status { get; set; }
|
||||||
public DateTime time { get; set; }
|
public DateTime time { get; set; }
|
||||||
|
@ -32,6 +32,11 @@ public class BotHandler
|
|||||||
public void Start(CancellationToken cancellationToken)
|
public void Start(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Starting bot...");
|
_logger.LogInformation("Starting bot...");
|
||||||
|
if (string.IsNullOrEmpty(_telegramOptions.BotToken))
|
||||||
|
{
|
||||||
|
_logger.LogError("Bot token is not provided");
|
||||||
|
return;
|
||||||
|
}
|
||||||
_bot = new TelegramBotClient(_telegramOptions.BotToken, cancellationToken: cancellationToken);
|
_bot = new TelegramBotClient(_telegramOptions.BotToken, cancellationToken: cancellationToken);
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||||
|
<EnableSdkContainerSupport>true</EnableSdkContainerSupport>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -1,21 +1,62 @@
|
|||||||
FROM mcr.microsoft.com/dotnet/runtime:9.0 AS base
|
#FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/runtime:9.0 AS base
|
||||||
USER $APP_UID
|
#ARG TARGETARCH
|
||||||
WORKDIR /app
|
#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/"]
|
COPY ["CasaBotApp/CasaBotApp.csproj", "CasaBotApp/"]
|
||||||
RUN dotnet restore "CasaBotApp/CasaBotApp.csproj"
|
COPY ["AutoScan/AutoScan.csproj", "AutoScan/"]
|
||||||
COPY . .
|
RUN dotnet restore "CasaBotApp/CasaBotApp.csproj" -a $TARGETARCH
|
||||||
WORKDIR "/src/CasaBotApp"
|
|
||||||
RUN dotnet build "CasaBotApp.csproj" -c $BUILD_CONFIGURATION -o /app/build
|
|
||||||
|
|
||||||
FROM build AS publish
|
# Copy source code and publish app
|
||||||
ARG BUILD_CONFIGURATION=Release
|
COPY --link . .
|
||||||
RUN dotnet publish "CasaBotApp.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
|
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
|
WORKDIR /app
|
||||||
COPY --from=publish /app/publish .
|
COPY --link --from=build /app .
|
||||||
|
USER $APP_UID
|
||||||
ENTRYPOINT ["dotnet", "CasaBotApp.dll"]
|
ENTRYPOINT ["dotnet", "CasaBotApp.dll"]
|
||||||
|
#CMD ["/bin/bash"]
|
@ -20,7 +20,6 @@ services.AddSingleton(configuration);
|
|||||||
services.AddLogging(builder =>
|
services.AddLogging(builder =>
|
||||||
{
|
{
|
||||||
builder.AddConfiguration(configuration.GetSection("Logging"));
|
builder.AddConfiguration(configuration.GetSection("Logging"));
|
||||||
// builder.AddConsole();
|
|
||||||
//add time to logs
|
//add time to logs
|
||||||
builder.AddSimpleConsole(options =>
|
builder.AddSimpleConsole(options =>
|
||||||
{
|
{
|
||||||
@ -48,8 +47,8 @@ var autoScanApp = serviceProvider.GetService<AutoScanApp>()!;
|
|||||||
|
|
||||||
using var cts = new CancellationTokenSource();
|
using var cts = new CancellationTokenSource();
|
||||||
|
|
||||||
autoScanApp.Run(cts.Token);
|
_ = autoScanApp.Run(cts.Token);
|
||||||
// botHandler.Start(cts.Token);
|
botHandler.Start(cts.Token);
|
||||||
|
|
||||||
_ = SendMessageToSubscribers(cts.Token);
|
_ = SendMessageToSubscribers(cts.Token);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user