Asset path error on Azure Unix App Service



  • Hi all I'm using local report in a asp.net core 3 application.
    Locally I'm working on a windows machine and everything works fine, but when I deploy on azure app service unix jsreport try to find an asset in the wrong path "/home/site/wwwroot/home/site/wwwroot/jsreport/logo.png" please note the duplicate /home/site/wwwroot.
    I'm using handlebar.js engine and Chrome recipe to generate pdf.

    The asset is in the header.html

    <div class="header"><img src='{#asset logo.png @encoding=dataURI}' /> [...]
    

    this is the startup configuration:

    private static IReportingBinary ReportingBinaryForEnvironment
            {
                get
                {
                    if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                    {
                        return jsreport.Binary.JsReportBinary.GetBinary();
                    }
    
                    return jsreport.Binary.Linux.JsReportBinary.GetBinary();
                }
            }
    
    [...]
                services.AddJsReport(new LocalReporting().UseBinary(ReportingBinaryForEnvironment)
                                                         .KillRunningJsReportProcesses()
                                                         .Configure(cfg =>
                                                         {
                                                             cfg.HttpPort = 8085;
                                                             cfg.FileSystemStore();
                                                             cfg.AllowedLocalFilesAccess();
                                                             cfg.Discover = true;
                                                             cfg.BaseUrlAsWorkingDirectory();
                                                             return cfg;
                                                         })
                                                         .AsUtility()
                                                         .KeepAlive(false)
                                                         .Create());
    

    And this is how invoke render:

    JsReportRenderService.RenderAsync(new RenderRequest()
                {
                    Data = data.Serialize(),
                    Template = new Template
                    {
                        Engine = templateEngine,
                        Recipe = recipe,
                        Content = template.Content,
                        Helpers = template.Helpers,
                        Chrome = new Chrome()
                        {
                            HeaderTemplate = template.Header,
                            FooterTemplate = template.Footer
                        }
                    }
                });
    
    

    To Finish this is the full error I got from the server:

     "message": "Error rendering report: starting rendering process..rendering has finished with errors:A critical error occurred while trying to execute the render command (2). Asset logo.png not found in the store and also not on the disk: Unable to find or read file /home/site/wwwroot/home/site/wwwroot/jsreport/logo.png. ENOENT: no such file or directory, open '/home/site/wwwroot/home/site/wwwroot/jsreport/logo.png' (1). caused by error (2):-> stackError:    at onCriticalError (/snapshot/jsreport/node_modules/jsreport-cli/lib/commands/render.js:302:19)    at /snapshot/jsreport/node_modules/jsreport-cli/lib/commands/render.js:298:12caused by error (1):-> meta = {\"cause\":{},\"isOperational\":true,\"logged\":true}-> stackError:    at readAsset (/snapshot/jsreport/node_modules/jsreport-assets/lib/assets.js:241:15)",
      "exceptionType": "jsreport.Local.JsReportBinaryException",
      "stackTrace": "   at jsreport.Local.Internal.LocalUtilityReportingService.RenderAsync(String requestString, CancellationToken ct)\n   at
    


  • It seems our code calculating the working dir doesn't work properly in the azure app service.
    Please set it explicitly like this:

     public class Startup
        {
            private IWebHostEnvironment _env;
            public Startup(IConfiguration configuration, IWebHostEnvironment env)
            {
                Configuration = configuration;
                _env = env;
            }      
        
            public void ConfigureServices(IServiceCollection services)
            {            
                services.AddJsReport(new LocalReporting()
                    .UseBinary(JsReportBinary.GetBinary())
                    // explicit set of working directory
                    .RunInDirectory(_env.WebRootPath)
                    .KillRunningJsReportProcesses()        
            }
    


  • Hi @jan_blaha thank you for the quick reply I tried to adopt your solution, but I got a new error.
    I applied this root path: /home/site/wwwroot/jsreport that seems to be correct.

    "message": "Error rendering report: starting rendering process..rendering has finished with errors:A critical error occurred while trying to execute the render command (2). Failed to launch chrome!/tmp/jsreport/compile/jsreport-2.7.1-Hy6PlIREU/chrome/chrome: error while loading shared libraries: libX11.so.6: cannot open shared object file: No such file or directoryTROUBLESHOOTING: https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md (1). caused by error (2):-> stackError:    at onCriticalError (/snapshot/jsreport/node_modules/jsreport-cli/lib/commands/render.js:302:19)    at /snapshot/jsreport/node_modules/jsreport-cli/lib/commands/render.js:298:12caused by error (1):-> meta = {\"logged\":true}-> stackError: Failed to launch chrome!/tmp/jsreport/compile/jsreport-2.7.1-Hy6PlIREU/chrome/chrome: error while loading shared libraries: libX11.so.6: cannot open shared object file: No such file or directoryTROUBLESHOOTING: https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md    at onClose (/snapshot/jsreport/node_modules/puppeteer/lib/Launcher.js:348:14)    at Interface.<anonymous> (/snapshot/jsreport/node_modules/puppeteer/lib/Launcher.js:337:50)    at Interface.emit (events.js:215:7)    at Interface.close (readline.js:403:8)    at Socket.onend (readline.js:180:10)    at Socket.emit (events.js:215:7)    at endReadableNT (_stream_readable.js:1184:12)    at processTicksAndRejections (internal/process/task_queues.js:80:21)",
      "exceptionType": "jsreport.Local.JsReportBinaryException",
      "stackTrace": "   at jsreport.Local.Internal.LocalUtilityReportingService.RenderAsync(String requestString, CancellationToken ct)\n
    


  • This is because the default azure web app Linux container for the .net core is missing some required shared libraries required for chrome to run.
    I'm not sure if there is some kind of way to extend this container. Maybe there is, but I don't see the documentation for it.
    However, you should be able to deploy using your own docker image.
    You should be able to find the required information in our documentation for docker and azure web apps here
    https://jsreport.net/learn/dotnet-local#docker


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.