KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Laravel project on Docker #2393

Closed Clemens Reinhold opened this topic on on Oct 15, 2021 - 12 comments

Clemens Reinhold commented on Oct 15, 2021

Hey =) I try to run my Koolreport Laravel project on a Docker image.

Problem: Graphs are not show.

I use nginx, Laravel 8.4, PHP 7.4, Koolreport pro, CloudExport with ChromeHeadlessIo.

Ive tried varios assets combinations, ive found here on form like this:

                "assets"=>array(
                    "path"=>public_path(),
                    "url"=>""
                ),

But with non of them and without assets tag it does not show graph, tables,...

My Dockerfile:

FROM php:7.4-fpm

# Arguments defined in docker-compose.yml
ARG user
ARG uid

# Install system dependencies
RUN apt-get update && apt-get install -y \
    git \
    curl \
    libpng-dev \
    libonig-dev \
    libxml2-dev \
    libzip-dev \
    zip \
    mariadb-client \
    unzip \
    nodejs

RUN apt-get install chromium -y

RUN apt install -y npm

# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

# Install PHP extensions
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd zip

# Get latest Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

# Create system user to run Composer and Artisan Commands
RUN useradd -G www-data,root -u $uid -d /home/$user $user
RUN mkdir -p /home/$user/.composer && \
    chown -R $user:$user /home/$user

RUN chmod 777 -R /var/www

# Set working directory
WORKDIR /var/www

USER $user

My docker-compse-yml:

version: "3.7"
services:
    nginx:
      image: nginx:1.17-alpine
      container_name: reportserver-nginx
      restart: unless-stopped
      ports:
        - 8000:80
      volumes:
        - ./:/var/www
        - ./docker-compose/nginx:/etc/nginx/conf.d
      networks:
        - reportserver
    db:
      image: mysql:5.7
      command: mysqld --sql_mode=""
      container_name: reportserver-db
      restart: unless-stopped
      environment:
        MYSQL_DATABASE: ${DB_DATABASE}
        MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
        MYSQL_PASSWORD: ${DB_PASSWORD}
        MYSQL_USER: ${DB_USERNAME}
        SERVICE_TAGS: dev
        SERVICE_NAME: mysql
      networks:
        - reportserver
    app:
      build:
        args:
          user: toor
          uid: 1000
        context: ./
        dockerfile: Dockerfile
      image: reportserver
      container_name: reportserver
      restart: unless-stopped
      environment:
        DB_HOST: ${DB_HOST}
        MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
        MYSQL_DATABASE: ${DB_DATABASE}
      working_dir: /var/www/
      volumes:
        - ./:/var/www
      networks:
        - reportserver
networks:
  reportserver:
    driver: bridge

THANK YOU =)

Sebastian Morales commented on Oct 15, 2021

Hi, pls clarify whether your report's web view or cloud export pdf file doesn't show graph.

Clemens Reinhold commented on Oct 15, 2021

Ah sorry. On webview its okay and on temp folder (html file) its also okay. Only on pdf its not okay.

Update: Table work, Charts not See images: PDF and Browser.

I try to show:

\koolreport\widgets\google\ColumnChart::create(array(
    "title"=>"Color columns",
    "dataSource"=>array(
        array("category"=>"Books","sale"=>32000,"color"=>"#4F5060"),
        array("category"=>"Accessories","sale"=>43000,"color"=>"#67819D"),
        array("category"=>"Phones","sale"=>54000,"color"=>"#ADBD37"),
        array("category"=>"Movies","sale"=>23000,"color"=>"#588133",),
        array("category"=>"Others","sale"=>12000,"color"=>"#003B45"),
    ),
    "columns"=>array(
        "category",
        "sale"=>array(
            "label"=>"Sale",
            "type"=>"number",
            "prefix"=>"$",
            "style"=>function($row){
                return "color:".$row["color"];
            }
        ),
    ),
));
Sebastian Morales commented on Oct 18, 2021

Pls try to use a local temp dir like this:

$report->cloudExport("MyReportPDF")
    ->chromeHeadlessio($secretToken)
    ->settings([
        'useLocalTempFolder' => true,
    ])
    ->pdf($pdfOptions)
    ->toBrowser($filename)
    ; 

After export, look for the latest sub dir in your local temp dir and copy it to your web server's web root. Then open the inside file export.html on your browser to see if the graph is rendered. If it isn't pls open the browser's dev tool/console to see if there's any error message. Rgds,

Clemens Reinhold commented on Oct 18, 2021

Ive got this Error on dev-tool:

On Server i also get this error:

Illuminate\Foundation\Bootstrap\HandleExceptions->handleError($level = 2, $message = 'file_get_contents(http://localhost/koolreport_assets/3186757410/KoolReport.js): failed to open stream: HTTP request failed!', $file = 'C:\\Users\\usd\\Desktop\\Arthur\\reportserver\\vendor\\koolreport\\cloudexport\\vendor\\chromeheadlessio\\php-client\\src\\Exporter.php', $line = 12, $context = ['url' => 'http://localhost/koolreport_assets/3186757410/KoolReport.js', 'http_response_header' => []]) 
Sebastian Morales commented on Oct 18, 2021

Would you pls zip the temp sub dir and email to support@koolphp.net or support@koolreport.com for us to investigate it for you? Tks,

Sebastian Morales commented on Oct 18, 2021

Is this url correct on your server: http://localhost/koolreport_assets/3186757410/KoolReport.js ?

Clemens Reinhold commented on Oct 18, 2021

Yes i can open this js file without any problem on browser.

Sebastian Morales commented on Oct 19, 2021

Can you try to open a php file with this content in your system:

<?php
echo file_get_contents("http://localhost/koolreport_assets/3186757410/KoolReport.js");

Clemens Reinhold commented on Oct 19, 2021

file_get_contents(http://localhost/koolreport_assets/3186757410/KoolReport.js): failed to open stream:

Can't open this file. Via PHP. But when i try echo file_get_contents("http://127.0.0.1:8000/koolreport_assets/3186757410/KoolReport.js");

then he show "Maximum execution time of 60 seconds exceeded"

But this works: echo file_get_contents(public_path()."/koolreport_assets/3186757410/KoolReport.js");

I try to work on assets

Sebastian Morales commented on Oct 20, 2021

Would you pls confirm that "http://localhost/koolreport_assets/3186757410/KoolReport.js" can be opened in browser but at the same moment can not be retrieved with file_get_contents? Pls open your report's web view and compare the path to KoolReport.js with public_path()."/koolreport_assets/3186757410/KoolReport.js". Tks,

Clemens Reinhold commented on Oct 20, 2021

file_get_contents("http://localhost/koolreport_assets/3186757410/KoolReport.js") This works manually in browser. Not with export / render.

public_path() uses a windows path to the file. like this: C:\Users\Root\Desktop\reportserver\public

Another example:

asset('storage/koolreport_assets/3186757410/KoolReport.js')

This shows me:

http://127.0.0.1:8000/storage/koolreport_assets/3186757410/KoolReport.js

But when i try this with ->render() AND without (show on landing page):

file_get_contents(asset('storage/koolreport_assets/3186757410/KoolReport.js'))

then he show:

"Maximum execution time of 60 seconds exceeded"


Update: When i put the koolreport_assets folder in public/storage and then so assert like:

                "assets"=>array(
                    "path"=>asset('storage/koolreport_assets/'),
                    "url"=>""
                ),

Then on ->render() he show the Table and the Charts ! But on ->cloudExport(..)->chromeHeadlessio(..)->settings(..)->pdf(..)->toBrowser(..) He show "Maximum execution time of 60 seconds exceeded"

tmp folder is also empty

Sebastian Morales commented on Oct 21, 2021

There must be some mismatch between your web server setting and file_get_contents request. The server responses to a browser request but not file_get_contents' one. Pls open the KoolReport.js path in your browser then open browser dev tool (F12), navigate to tab Network, click All and refresh the page. Then right mouse click a loaded resource (KoolReport.js in this case) and choose Copy request header. Finally fill the browser request header data into this php page to see how it opens:

//Fill in your browser request header here
$requestHeader = "Accept-language: en\r\n" .
              "Cookie: foo=bar\r\n" . 
              "User-Agent: Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.102011-10-16 20:23:10\r\n"; 

$options = array(
  'http'=>array(
    'method'=>"GET",
    'header'=>$requestHeader
  )
);

$context = stream_context_create($options);
$url = "http://localhost/koolreport_assets/3186757410/KoolReport.js";
// $url = "http://127.0.0.1:8000/storage/koolreport_assets/3186757410/KoolReport.js"; can try this url path as well
$file = file_get_contents($url, false, $context); 

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
None yet

None