From 6c7faff512d5df3c0f7d48459b3f7a016b002152 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Tue, 25 Aug 2020 19:18:36 +0000 Subject: [PATCH] --- devdocs/deploy.txt | 4 ---- .../docker/linux-x64/ayanovadocker/dockerfile | 9 ++++++++ server/AyaNova/AyaNova.csproj | 18 ++++++++++----- .../AyaNova/Controllers/ReportController.cs | 22 +++++++++++++++++-- 4 files changed, 41 insertions(+), 12 deletions(-) diff --git a/devdocs/deploy.txt b/devdocs/deploy.txt index f7f6169e..fbddca91 100644 --- a/devdocs/deploy.txt +++ b/devdocs/deploy.txt @@ -243,7 +243,3 @@ DOCKER / LINUX CHEAT SHEET - - --> \ No newline at end of file diff --git a/dist/docker/linux-x64/ayanovadocker/dockerfile b/dist/docker/linux-x64/ayanovadocker/dockerfile index 5d55921c..c309ecc3 100644 --- a/dist/docker/linux-x64/ayanovadocker/dockerfile +++ b/dist/docker/linux-x64/ayanovadocker/dockerfile @@ -2,4 +2,13 @@ FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-alpine WORKDIR /app COPY ./files . RUN apk add postgresql-client +RUN apk add --no-cache \ + chromium \ + nss \ + freetype \ + freetype-dev \ + harfbuzz \ + ca-certificates \ + ttf-freefont + ENTRYPOINT ["dotnet", "AyaNova.dll"] diff --git a/server/AyaNova/AyaNova.csproj b/server/AyaNova/AyaNova.csproj index 270a66c5..69a1696e 100644 --- a/server/AyaNova/AyaNova.csproj +++ b/server/AyaNova/AyaNova.csproj @@ -44,15 +44,21 @@ - - - - + - - + + Always + + + Always + + + + \ No newline at end of file diff --git a/server/AyaNova/Controllers/ReportController.cs b/server/AyaNova/Controllers/ReportController.cs index c4b6c1bc..b617d308 100644 --- a/server/AyaNova/Controllers/ReportController.cs +++ b/server/AyaNova/Controllers/ReportController.cs @@ -91,7 +91,7 @@ namespace AyaNova.Api.Controllers if (!Directory.Exists(ReportJSFolderPath)) throw new System.Exception($"E1012: \"reportjs\" folder not found where expected: \"{ReportJSFolderPath}\", installation damaged?"); - await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision); + //sample CSS var reportCSS = @" @@ -123,9 +123,26 @@ namespace AyaNova.Api.Controllers var aylogo = $"{{small:'{API_URL}logo/small',medium:'{API_URL}logo/medium',large:'{API_URL}logo/large'}}"; var reportData = "{ person: { firstname: 'Tyler', lastname: 'Mott' },aylogo:[AYLOGO], mdtest:'| CODE | MEANING |\\n| ----- | ------------------------------ |\\n| E1000 | Could not connect to the database specified in the [connection string](ops-config-db.md). |\\n| E1050 | XXXXXXXX |\\n| E1012 | Missing resource folder. AyaNova was started from the wrong location or was not installed properly. |\\n' }"; reportData = reportData.Replace("[AYLOGO]", aylogo); - using (var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = true })) + + log.LogInformation($"setting Chrome launchoptions for os:"); + var lo = new LaunchOptions { Headless = true }; + bool isWindows = System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows); + if (!isWindows) + { + log.LogInformation($"IS NOT WINDOWS: setting executable path for chrome"); + lo.ExecutablePath = "/usr/bin/chromium-browser"; + lo.Args = new string[] { "--no-sandbox" }; + } + else + { + log.LogInformation($"IS WINDOWS: Calling browserFetcher download async now:"); + await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision); + } + log.LogInformation($"Calling browser.launchAsync now:"); + using (var browser = await Puppeteer.LaunchAsync(lo)) using (var page = await browser.NewPageAsync()) { + log.LogInformation($"In using for page ops adding scripts and report now:"); //Add handlebars JS for compiling and presenting await page.AddScriptTagAsync(new AddTagOptions() { Path = Path.Combine(ReportJSFolderPath, "ay-hb.js") }); @@ -156,6 +173,7 @@ namespace AyaNova.Api.Controllers //render to pdf and return var pdfBuffer = await page.PdfDataAsync(); + log.LogInformation($"returning results now:"); return new FileContentResult(pdfBuffer, "application/pdf"); }