プログラムの設置先変更

This commit is contained in:
armonica committed 2026-09-05 13:08:17 +09:00
1 parent 63188d87f4
commit ef730787dd
7 files changed
+158 -56

No files matched your search

+19
View File
@@ -0,0 +1,19 @@
# .NET 10.0 ランタイムベースイメージ
FROM mcr.microsoft.com/dotnet/runtime:10.0 AS runtime
WORKDIR /app
# タイムゾーン設定 (JST) および必要なツールのインストール
RUN apt-get update && apt-get install -y --no-install-recommends \
tzdata \
ca-certificates \
curl \
&& rm -rf /var/lib/apt/lists/*
# 日本時間に設定
ENV TZ=Asia/Tokyo
# 発行済みバイナリをコンテナ内へ配置
COPY ./app .
# アプリケーション実行
ENTRYPOINT ["dotnet", "rss-generator.dll"]
+26
View File
@@ -0,0 +1,26 @@
services:
rss-generator:
build: .
image: local-rss-generator:latest
container_name: rss-generator
restart: always
mem_limit: 512m
memswap_limit: 512m
deploy:
resources:
limits:
memory: 512M
environment:
- TZ=Asia/Tokyo
# .NET GC設定: Workstation GC強制、ヒープ制限70%
- DOTNET_gcServer=0
- DOTNET_GCHeapHardLimitPercent=70
volumes:
# 生成されたXMLフィードをホストの C:\feeds に出力
- C:\feeds:/app/output
networks:
- common-network
networks:
common-network:
external: true
+8 -4
View File
@@ -252,8 +252,8 @@ public class CmnUtil
return null;
}
// 15MB 以上の巨大画像は安全のためスキップ
if (response.Content.Headers.ContentLength.HasValue && response.Content.Headers.ContentLength.Value > 15 * 1024 * 1024)
// 2MB 以上の画像はメモリ保護のためスキップ(元のURLを参照させる)
if (response.Content.Headers.ContentLength.HasValue && response.Content.Headers.ContentLength.Value > 2 * 1024 * 1024)
{
return null;
}
@@ -281,7 +281,7 @@ public class CmnUtil
/// SyndicationFeed に含まれる全記事(24時間フィルタ適用後)の HTML 本文から画像 URL を抽出し、
/// 並列ダウンロードして Base64 形式(Data URI)に置換します。
/// </summary>
public static async Task EmbedImagesAsBase64InFeedAsync(SyndicationFeed feed, HttpClient client, int maxParallel = 8)
public static async Task EmbedImagesAsBase64InFeedAsync(SyndicationFeed feed, HttpClient client, int maxParallel = 2)
{
if (feed.Items == null) return;
@@ -321,7 +321,7 @@ public class CmnUtil
if (targetUrls.Count == 0) return;
// 2. 並列ダウンロードして Base64 辞書を構築
// 2. 並列ダウンロードして Base64 辞書を構築(メモリ節約のため同時並行数は2に制御)
var cacheMap = new ConcurrentDictionary<string, string>(StringComparer.OrdinalIgnoreCase);
using var semaphore = new SemaphoreSlim(maxParallel);
@@ -377,6 +377,10 @@ public class CmnUtil
int distinctSuccess = targetUrls.Keys.Count(k => cacheMap.ContainsKey(k));
LogManager.AddLog($"[情報] [CmnUtil] 画像の Base64 変換完了: {distinctSuccess}/{targetUrls.Count} 件成功 (記事数: {itemsList.Count})");
// 使用済みメモリの即時解放
cacheMap.Clear();
targetUrls.Clear();
}
/// <summary>
+21 -10
View File
@@ -9,19 +9,30 @@ internal class x_list
private const string QUERY2 = "showEmojiForRetweetAndReply=1?filter_title=%5E%28🔁%7CRT%29";
public static async Task CreateRSSAsync(HttpClient client)
{
var tasks = new List<Task>()
// メモリ消費を最小化するため、各リストを1つずつ順次処理
var targets = new (string ListId, string FileName)[]
{
CreateSub1(client, "2076742238231818243", "granbluefantasy")
, CreateSub1(client, "1695011723005280535", "AI")
, CreateSub1(client, "1573473287333560321", "R18")
, CreateSub1(client, "2070669317667217577", "VR")
, CreateSub1(client, "1573916143969976320", "VTuber")
, CreateSub1(client, "2070673943057539507", "AnimeReal")
, CreateSub1(client, "1599409403743961088", "AnimeOther")
, CreateSub1(client, "2070670309846655252", "NormalIllust")
("2076742238231818243", "granbluefantasy"),
("1695011723005280535", "AI"),
("1573473287333560321", "R18"),
("2070669317667217577", "VR"),
("1573916143969976320", "VTuber"),
("2070673943057539507", "AnimeReal"),
("1599409403743961088", "AnimeOther"),
("2070670309846655252", "NormalIllust")
};
await Task.WhenAll(tasks);
foreach (var (listId, fileName) in targets)
{
try
{
await CreateSub1(client, listId, fileName);
}
catch (Exception ex)
{
LogManager.AddLog($"[エラー] Xリスト生成失敗 ({fileName}): {ex.Message}");
}
}
}
public static async Task CreateSub1(HttpClient client, string listId, string fileName)
@@ -29,8 +29,8 @@ public static class YouTubeFeedManager
var allVideoItems = new List<YouTubeVideoItem>();
var allShortsItems = new List<YouTubeVideoItem>();
// YouTubeからのレート制限を防ぐため、同時並行数を安全な値(6)に制御
using var semaphore = new System.Threading.SemaphoreSlim(6);
// メモリ消費とレート制限を抑えるため、同時並行数を2に制御
using var semaphore = new System.Threading.SemaphoreSlim(2);
var channelTasks = YouTubeConfig.Channels.Select(async channel =>
{
+65 -34
View File
@@ -79,51 +79,72 @@ while (true)
// サイトによってはAcceptヘッダーがないと弾く場合もあるため、念のため追加
client.DefaultRequestHeaders.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
List<Task> tasks = new List<Task>();
// メモリ消費を最小化(512MB制限内)するため、各フィードを並行ではなく順次実行し、タスクごとにGCを実行
var feedActions = new List<(string Name, Func<Task> Action)>();
DateTime from = new DateTime(nowDate.Year, nowDate.Month, nowDate.Day, 5, 0, 0);
DateTime to = new DateTime(nowDate.Year, nowDate.Month, nowDate.Day, 7, 15, 0);
if (from < nowDate && nowDate < to)
{
tasks.Add(momonga_fanzine.CreateRSSAsync(client));
tasks.Add(momonga_magazine.CreateRSSAsync(client));
feedActions.Add(("momonga_fanzine", () => momonga_fanzine.CreateRSSAsync(client)));
feedActions.Add(("momonga_magazine", () => momonga_magazine.CreateRSSAsync(client)));
}
#if DEBUG
tasks.Add(momonga_fanzine.CreateRSSAsync(client));
tasks.Add(momonga_magazine.CreateRSSAsync(client));
tasks.Add(YouTubeFeedManager.CreateRSSAsync(client));
tasks.Add(rss_generator.Class.RSS.X.x_list.CreateRSSAsync(client));
tasks.Add(kimochiinfo.CreateRSSAsync(client));
tasks.Add(ci_en.CreateRSSAsync(client));
tasks.Add(javtwi.CreateRSSAsync(client));
tasks.Add(mangalear.CreateRSSAsync(client));
tasks.Add(e_hentai_ai.CreateRSSAsync(client));
tasks.Add(e_hentai_non_ai.CreateRSSAsync(client));
tasks.Add(pixiv_non_r18_non_ai.CreateRSSAsync(client));
tasks.Add(pixiv_non_r18_ai.CreateRSSAsync(client));
tasks.Add(pixiv_r18_non_ai.CreateRSSAsync(client));
tasks.Add(pixiv_r18_ai.CreateRSSAsync(client));
tasks.Add(FlareSolverrFeedManager.CreateAllRSSAsync(client));
feedActions.Add(("momonga_fanzine", () => momonga_fanzine.CreateRSSAsync(client)));
feedActions.Add(("momonga_magazine", () => momonga_magazine.CreateRSSAsync(client)));
feedActions.Add(("YouTube", () => YouTubeFeedManager.CreateRSSAsync(client)));
feedActions.Add(("X (Twitter)", () => rss_generator.Class.RSS.X.x_list.CreateRSSAsync(client)));
feedActions.Add(("kimochiinfo", () => kimochiinfo.CreateRSSAsync(client)));
feedActions.Add(("ci_en", () => ci_en.CreateRSSAsync(client)));
feedActions.Add(("javtwi", () => javtwi.CreateRSSAsync(client)));
feedActions.Add(("mangalear", () => mangalear.CreateRSSAsync(client)));
feedActions.Add(("e_hentai_ai", () => e_hentai_ai.CreateRSSAsync(client)));
feedActions.Add(("e_hentai_non_ai", () => e_hentai_non_ai.CreateRSSAsync(client)));
feedActions.Add(("pixiv_non_r18_non_ai", () => pixiv_non_r18_non_ai.CreateRSSAsync(client)));
feedActions.Add(("pixiv_non_r18_ai", () => pixiv_non_r18_ai.CreateRSSAsync(client)));
feedActions.Add(("pixiv_r18_non_ai", () => pixiv_r18_non_ai.CreateRSSAsync(client)));
feedActions.Add(("pixiv_r18_ai", () => pixiv_r18_ai.CreateRSSAsync(client)));
feedActions.Add(("FlareSolverr", () => FlareSolverrFeedManager.CreateAllRSSAsync(client)));
#else
tasks.Add(YouTubeFeedManager.CreateRSSAsync(client));
tasks.Add(rss_generator.Class.RSS.X.x_list.CreateRSSAsync(client));
tasks.Add(kimochiinfo.CreateRSSAsync(client));
tasks.Add(ci_en.CreateRSSAsync(client));
tasks.Add(javtwi.CreateRSSAsync(client));
tasks.Add(mangalear.CreateRSSAsync(client));
tasks.Add(e_hentai_ai.CreateRSSAsync(client));
tasks.Add(e_hentai_non_ai.CreateRSSAsync(client));
tasks.Add(pixiv_non_r18_non_ai.CreateRSSAsync(client));
tasks.Add(pixiv_non_r18_ai.CreateRSSAsync(client));
tasks.Add(pixiv_r18_non_ai.CreateRSSAsync(client));
tasks.Add(pixiv_r18_ai.CreateRSSAsync(client));
feedActions.Add(("YouTube", () => YouTubeFeedManager.CreateRSSAsync(client)));
feedActions.Add(("X (Twitter)", () => rss_generator.Class.RSS.X.x_list.CreateRSSAsync(client)));
feedActions.Add(("kimochiinfo", () => kimochiinfo.CreateRSSAsync(client)));
feedActions.Add(("ci_en", () => ci_en.CreateRSSAsync(client)));
feedActions.Add(("javtwi", () => javtwi.CreateRSSAsync(client)));
feedActions.Add(("mangalear", () => mangalear.CreateRSSAsync(client)));
feedActions.Add(("e_hentai_ai", () => e_hentai_ai.CreateRSSAsync(client)));
feedActions.Add(("e_hentai_non_ai", () => e_hentai_non_ai.CreateRSSAsync(client)));
feedActions.Add(("pixiv_non_r18_non_ai", () => pixiv_non_r18_non_ai.CreateRSSAsync(client)));
feedActions.Add(("pixiv_non_r18_ai", () => pixiv_non_r18_ai.CreateRSSAsync(client)));
feedActions.Add(("pixiv_r18_non_ai", () => pixiv_r18_non_ai.CreateRSSAsync(client)));
feedActions.Add(("pixiv_r18_ai", () => pixiv_r18_ai.CreateRSSAsync(client)));
// FlareSolverr 利用タスク群(単一セッションで順次実行し、完了後に破棄してメモリ最小化)
tasks.Add(FlareSolverrFeedManager.CreateAllRSSAsync(client));
feedActions.Add(("FlareSolverr", () => FlareSolverrFeedManager.CreateAllRSSAsync(client)));
#endif
await Task.WhenAll(tasks);
foreach (var (name, action) in feedActions)
{
try
{
var taskSw = Stopwatch.StartNew();
LogManager.AddLog($"[情報] 【{name}】 取得開始");
await action();
taskSw.Stop();
LogManager.AddLog($"[情報] 【{name}】 完了 ({taskSw.Elapsed.TotalSeconds:0.##}秒)");
}
catch (Exception ex)
{
LogManager.AddLog($"[エラー] 【{name}】 実行時エラー: {ex.Message}");
}
finally
{
// 各タスク完了後にメモリを積極回収してOSに返却
GC.Collect(2, GCCollectionMode.Aggressive, true, true);
GC.WaitForPendingFinalizers();
GC.Collect(2, GCCollectionMode.Aggressive, true, true);
}
}
sw.Stop();
LogManager.AddLog($"[情報] RSS生成完了 実行時間:{sw.Elapsed.TotalSeconds:0.##}秒");
@@ -139,11 +160,21 @@ while (true)
await LogManager.FlushAndCloseAsync();
break;
#else
// FreshRSS更新スクリプトが存在する場合のみ実行(ローカル実行時は安全にスキップ)
const string updateScriptPath = "/usr/local/bin/update_rss.sh";
if (File.Exists(updateScriptPath))
{
LogManager.AddLog($"[情報] FreshRSS 更新開始");
await CmnUtil.RunCommandAsync("/bin/bash", "/usr/local/bin/update_rss.sh", "");
await CmnUtil.RunCommandAsync("/bin/bash", updateScriptPath, "");
sw.Stop();
LogManager.AddLog($"[情報] FreshRSS 更新完了 実行時間:{sw.Elapsed.TotalSeconds:0.##}秒");
}
else
{
sw.Stop();
LogManager.AddLog($"[情報] FreshRSS 更新スクリプトが存在しないためスキップしました");
}
totalSw.Stop();
LogManager.AddLog($"[情報] 全処理完了 トータル実行時間:{totalSw.Elapsed.TotalSeconds:0.##}秒");
+17 -6
View File
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
@@ -6,6 +6,11 @@
<RootNamespace>rss_generator</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<!-- サーバーGCを無効化し、省メモリなワークステーションGCを使用 -->
<ServerGarbageCollection>false</ServerGarbageCollection>
<ConcurrentGarbageCollection>true</ConcurrentGarbageCollection>
<!-- 使用済み仮想メモリをOSに速やかに返却 -->
<RetainVMGarbageCollection>false</RetainVMGarbageCollection>
</PropertyGroup>
<ItemGroup>
@@ -24,11 +29,17 @@
<Folder Include="Class\RSS\Pixiv\" />
</ItemGroup>
<!-- 発行後にローカルPCのDocker Desktopへ自動デプロイ -->
<Target Name="PostPublishDeploy" AfterTargets="Publish">
<Message Text="=== [VPS Deploy] Starting Deploy via MSBuild ===" Importance="high" />
<Exec Command="ssh -p 22321 armonica@162.43.79.113 &quot;mkdir -p /home/armonica/docker/rss-generator/app&quot;" />
<Exec Command="scp -P 22321 -r &quot;$(ProjectDir)bin\publish\*&quot; armonica@162.43.79.113:/home/armonica/docker/rss-generator/app/" />
<Exec Command="ssh -p 22321 armonica@162.43.79.113 &quot;cd /home/armonica/docker/rss-generator &amp;&amp; docker compose up -d --build rss-generator&quot;" />
<Message Text="=== [VPS Deploy] All processes completed successfully! ===" Importance="high" />
<Message Text="=== [Local Docker Deploy] Starting Deploy via MSBuild ===" Importance="high" />
<!-- 配置先ディレクトリ C:\docker\rss-generator\app の存在確認と作成 -->
<Exec Command="powershell -Command &quot;if (!(Test-Path 'C:\docker\rss-generator\app')) { New-Item -ItemType Directory -Force -Path 'C:\docker\rss-generator\app' }&quot;" />
<!-- 発行済みファイルを C:\docker\rss-generator\app に同期(Visual Studio発行プロファイル・CLI共通対応) -->
<Exec Command="robocopy &quot;$(PublishDir).&quot; &quot;C:\docker\rss-generator\app&quot; /MIR /NP /NFL /NDL" IgnoreExitCode="true" />
<!-- Dockerfile と compose.yaml を最新同期 -->
<Exec Command="powershell -Command &quot;Copy-Item -Path '$(SolutionDir)Dockerfile', '$(SolutionDir)compose.yaml' -Destination 'C:\docker\rss-generator\' -Force&quot;" />
<!-- ローカルDocker Desktopでコンテナをビルド・起動(常駐) -->
<Exec Command="docker compose -f C:\docker\rss-generator\compose.yaml up -d --build" />
<Message Text="=== [Local Docker Deploy] All processes completed successfully! ===" Importance="high" />
</Target>
</Project>