shelfio / libreoffice-lambda-base-image

MIT License
30 stars 19 forks source link

Command failed: Fatal Error: The application cannot be started #1

Closed scorobogaci closed 2 years ago

scorobogaci commented 2 years ago

Steps to reproduce : Dockerfile

FROM public.ecr.aws/shelf/lambda-libreoffice-base:7.3-node16-x86_64
COPY ./ ${LAMBDA_TASK_ROOT}/
CMD [ "index.handler" ]

index.js

const {execSync} = require('child_process');
exports.handler = async function (event, context) {
    execSync(`
  cd /tmp
  libreoffice7.3 --headless --invisible --nodefault --view --nolockcheck --nologo --norestore --convert-to pdf --outdir /tmp ./test.docx
  `);
};

Output of lambda after execution

{
  "errorType": "Error",
  "errorMessage": "Command failed: \n  cd /tmp\n  libreoffice7.3 --headless --invisible --nodefault --view --nolockcheck --nologo --norestore --convert-to pdf --outdir /tmp ./test.docx\n  \njavaldx failed!\nWarning: failed to read path from javaldx\nLibreOffice 7.3 - Fatal Error: The application cannot be started. \nUser installation could not be completed. \n",
  "trace": [
    "Error: Command failed: ",
    "  cd /tmp",
    "  libreoffice7.3 --headless --invisible --nodefault --view --nolockcheck --nologo --norestore --convert-to pdf --outdir /tmp ./test.docx",
    "  ",
    "javaldx failed!",
    "Warning: failed to read path from javaldx",
    "LibreOffice 7.3 - Fatal Error: The application cannot be started. ",
    "User installation could not be completed. ",
    "",
    "    at checkExecSyncError (node:child_process:828:11)",
    "    at execSync (node:child_process:899:15)",
    "    at Runtime.exports.handler (/var/task/index.js:10:5)",
    "    at Runtime.handleOnce (file:///var/runtime/index.mjs:548:29)"
  ]
}

Expected behaviour

Lambda created built based on this docker image should not fail and be able to do the conversion

scorobogaci commented 2 years ago

might be important or not, the docker image was built on MacBook Pro M1, with the following command docker buildx build --platform linux/amd64 -f ./Dockerfile -t pdf-conversion-service .

scorobogaci commented 2 years ago

building the docker image with the following command, fails inside lambda as well after invoke docker build -t test-lambda-base-image .

scorobogaci commented 2 years ago

starting container on host , and invoking command fails as well Screenshot 2022-06-21 at 11 18 21

scorobogaci commented 2 years ago

Wanted to create a pull request, but was not able to, cannot push to the repository. However, here is the version of docker image which works ok, added java-1.8.0-openjdk

Dockerfile

FROM public.ecr.aws/lambda/nodejs:16-x86_64

# binutils is needed for "strip" command
RUN yum install \
    java-1.8.0-openjdk \
    tar \
    gzip \
    libdbusmenu.x86_64 \
    libdbusmenu-gtk2.x86_64 \
    libSM.x86_64 \
    xorg-x11-fonts-* \
    google-noto-sans-cjk-fonts.noarch \
    binutils.x86_64 \
    -y && \
    yum clean all

RUN set -xo pipefail && \
    curl "https://ftp.halifax.rwth-aachen.de/tdf/libreoffice/stable/7.3.4/rpm/x86_64/LibreOffice_7.3.4_Linux_x86-64_rpm.tar.gz" | tar -xz

RUN cd LibreOffice_7.3.4.2_Linux_x86-64_rpm/RPMS && \
    yum install *.rpm -y && \
    rm -rf /var/task/LibreOffice_7.3.4* && \
    cd /opt/libreoffice7.3/ && \
    strip ./**/* || true
vladholubiev commented 2 years ago

@scorobogaci it worked for me when I set the env var HOME=/tmp without installing Java

Could you please try does it work w/o Java?

I added this to the troubleshooting section: https://github.com/shelfio/libreoffice-lambda-base-image#troubleshooting

scorobogaci commented 2 years ago

@scorobogaci it worked for me when I set the env var HOME=/tmp without installing Java

Could you please try does it work w/o Java?

sure, let me give it a try this option as well

scorobogaci commented 2 years ago

@vladgolubev , you mean setting environment for lambda, not inside Dockerfile ? Thanks

vladholubiev commented 2 years ago

@scorobogaci I tried in Lambda, but probably setting this in Dockerfile will yield the same effect?

scorobogaci commented 2 years ago

@vladgolubev , tried with both options, setting ENV HOME=/tmp inside Dockerfile as well as setting lambda environment variable, getting this error in both cases

{
  "errorMessage": "RequestId: 3fd15b21-394d-4feb-97e8-dffffe7b9b2c Error: Runtime exited with error: exit status 142",
  "errorType": "Runtime.ExitError"
}
vladholubiev commented 2 years ago

@scorobogaci could you please try a full handler file like this?

The handler sample in README was previously stripped down to show only the handle content. Here is a full handler

const {execSync} = require('child_process');
const {writeFileSync} = require('fs');

module.exports.handler = () => {
  writeFileSync('/tmp/hello.txt', Buffer.from('Hello World!'));

  execSync(`
  cd /tmp
  libreoffice7.3 --headless --invisible --nodefault --view --nolockcheck --nologo --norestore --convert-to pdf --outdir /tmp ./hello.txt
  `);
};
scorobogaci commented 2 years ago

@vladgolubev , ignore previous comment, it was because i did not set the correct entrypoint for lambda, let me do another test

scorobogaci commented 2 years ago

your sample worked

this worked, having HOME=/tmp set as lambda environment variable . However, Billed Duration: 33073 ms , this is crazy... how come on cold start there is such enormous delay ?

scorobogaci commented 2 years ago

@vladgolubev , performs really well when lambda is in WARM state, however on COLD state, is taking 30 seconds, how come? Why this would be the case ?

vladholubiev commented 2 years ago

@scorobogaci libreoffice when first booted, writes some files to disk. Maybe it's worth exploring adding a "smoke startup" for LibreOffice during docker image build so those files will be bundled in the docker image. You can try that and see does it help with a cold start

scorobogaci commented 2 years ago

@vladgolubev , alright thanks for suggestion ! this is crucial i think, otherwise the solution cannot be used in a serverless model, cause on COLD starts 30 seconds is not acceptable at all :( Feel free to close the issue, adding HOME=/tmp as lambda environment variable solves the issue.

Would be nice to check if adding ENV HOME=/tmp in Dockerfile solves also the issue, having this config in Dockerfile removes the need for developers to take care of setting lambda environment variable

Thanks a lot !

vladholubiev commented 2 years ago

@scorobogaci thanks for noticing it! When I get to touch my code using this docker image next time, I'll check does it work with env var in Dockerfile. Feel free to update if you got success with reducing a cold start as well!