forked from sim0n00ps/OF-DL
Download chromium during runtime in docker (like windows)
This commit is contained in:
parent
a4d8676f2e
commit
0572844ca8
10
Dockerfile
10
Dockerfile
@ -32,7 +32,7 @@ RUN apt-get update \
|
||||
npm \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN npx playwright install --with-deps chromium
|
||||
RUN npx playwright install-deps
|
||||
|
||||
RUN apt-get remove --purge -y npm \
|
||||
&& apt-get autoremove -y
|
||||
@ -54,10 +54,12 @@ COPY docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
|
||||
COPY docker/entrypoint.sh /app/entrypoint.sh
|
||||
RUN chmod +x /app/entrypoint.sh
|
||||
|
||||
ENV DISPLAY=:0.0 \
|
||||
DISPLAY_WIDTH=1024 \
|
||||
ENV DEBIAN_FRONTEND="noninteractive" \
|
||||
DISPLAY=:0.0 \
|
||||
DISPLAY_WIDTH=1366 \
|
||||
DISPLAY_HEIGHT=768 \
|
||||
OFDL_DOCKER=true
|
||||
OFDL_DOCKER=true \
|
||||
PLAYWRIGHT_BROWSERS_PATH=/config/chromium
|
||||
|
||||
EXPOSE 8080
|
||||
WORKDIR /config
|
||||
|
||||
@ -26,21 +26,32 @@ public class AuthHelper
|
||||
private const float LoginTimeout = 600000f; // 10 minutes
|
||||
private const float FeedLoadTimeout = 60000f; // 1 minute
|
||||
|
||||
public async Task SetupBrowser(bool runningInDocker)
|
||||
public Task SetupBrowser(bool runningInDocker)
|
||||
{
|
||||
if (runningInDocker)
|
||||
{
|
||||
Log.Information("Running in Docker. Disabling sandbox and GPU.");
|
||||
_options.Args = ["--no-sandbox", "--disable-setuid-sandbox", "--disable-gpu", "--disable-blink-features=AutomationControlled", "--disable-infobars"];
|
||||
}
|
||||
else
|
||||
|
||||
// If chromium is already downloaded, skip installation
|
||||
string? playwrightBrowsersPath = Environment.GetEnvironmentVariable("PLAYWRIGHT_BROWSERS_PATH");
|
||||
IEnumerable<string> folders = Directory.GetDirectories(playwrightBrowsersPath ?? "/config/chromium")
|
||||
.Where(folder => folder.Contains("chromium-"));
|
||||
|
||||
if (folders.Any())
|
||||
{
|
||||
var exitCode = Microsoft.Playwright.Program.Main(new[] {"install", "--with-deps", "chromium"});
|
||||
Log.Information("chromium already downloaded. Skipping install step.");
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
var exitCode = Microsoft.Playwright.Program.Main(["install", "--with-deps", "chromium"]);
|
||||
if (exitCode != 0)
|
||||
{
|
||||
throw new Exception($"Playwright chromium download failed. Exited with code {exitCode}");
|
||||
}
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private async Task<string> GetBcToken(IPage page)
|
||||
@ -60,9 +71,12 @@ public class AuthHelper
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (e.Message.Contains("An error occurred trying to start process") && Directory.Exists(_userDataDir))
|
||||
if ((
|
||||
e.Message.Contains("An error occurred trying to start process") ||
|
||||
e.Message.Contains("The profile appears to be in use by another Chromium process")
|
||||
) && Directory.Exists(_userDataDir))
|
||||
{
|
||||
Log.Error("Failed to launch browser. Deleting chrome-data directory and trying again.");
|
||||
Log.Error("Failed to launch browser. Deleting chromium-data directory and trying again.");
|
||||
Directory.Delete(_userDataDir, true);
|
||||
IPlaywright playwright = await Playwright.CreateAsync();
|
||||
browser = await playwright.Chromium.LaunchPersistentContextAsync(_userDataDir, _options);
|
||||
|
||||
@ -18,7 +18,7 @@
|
||||
<PackageReference Include="BouncyCastle.NetCore" Version="2.2.1" />
|
||||
<PackageReference Include="HtmlAgilityPack" Version="1.12.0" />
|
||||
<PackageReference Include="Microsoft.Data.Sqlite" Version="9.0.3" />
|
||||
<PackageReference Include="Microsoft.Playwright" Version="1.54.0" />
|
||||
<PackageReference Include="Microsoft.Playwright" Version="1.55.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="protobuf-net" Version="3.2.46" />
|
||||
<PackageReference Include="Serilog" Version="4.2.0" />
|
||||
|
||||
@ -3142,10 +3142,10 @@ public class Program
|
||||
}
|
||||
break;
|
||||
case "[red]Logout and Exit[/]":
|
||||
if (Directory.Exists("chrome-data"))
|
||||
if (Directory.Exists("chromium-data"))
|
||||
{
|
||||
Log.Information("Deleting chrome-data folder");
|
||||
Directory.Delete("chrome-data", true);
|
||||
Log.Information("Deleting chromium-data folder");
|
||||
Directory.Delete("chromium-data", true);
|
||||
}
|
||||
if (File.Exists("auth.json"))
|
||||
{
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
mkdir -p /config/cdm/devices/chrome_1610
|
||||
mkdir -p /config/logs/
|
||||
mkdir -p /config/chromium
|
||||
|
||||
if [ ! -f /config/config.conf ] && [ ! -f /config/config.json ]; then
|
||||
cp /default-config/config.conf /config/config.conf
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user