Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crashes inside Alpine docker #170

Closed
AyushG3112 opened this issue Feb 18, 2020 · 13 comments
Closed

Crashes inside Alpine docker #170

AyushG3112 opened this issue Feb 18, 2020 · 13 comments
Labels

Comments

@AyushG3112
Copy link

AyushG3112 commented Feb 18, 2020

Node.js Version: 10.15.0
hummus-recipe: V1.9.2

Hi,

I am trying to add image to an existing PDF using .image . It works working on my local machine (Ubuntu 16.04), however it crashes inside the Alpine container on calling endPDF(thus creating a corrupted PDF).

Tried downgrading to v1.7.4, didn't help.

Any help is appreciated.

@chunyenHuang
Copy link
Owner

Can you share your Dockerfile for alpine?

@AyushG3112
Copy link
Author

My Dockerfile looks like:

FROM node:10.13.0-alpine

RUN mkdir -p /var/app/
WORKDIR /var/app/
ENV NODE_ENV=development

RUN wget -qO- "https://github.com/dustinblackman/phantomized/releases/dow
nload/2.1.1a/dockerized-phantomjs.tar.gz" | tar xz -C /
RUN mkdir -p /var/app/templates/tmp
RUN apk add pdftk
RUN npm config set strict-ssl false
RUN npm install -g nodemon
RUN npm install -g nyc
RUN npm install -g mocha

EXPOSE 3000

CMD ["./dev-start.sh"]

dev-start.sh runs npm install and starts my service using nodemon

Here's my hummus-recipe integration:

    const pdfDoc = new HummusRecipe(input, output);
    pdfDoc
      .editPage(2)
      .image('/path/to/image1.png'), 350, 660, {
        width: 200,
        keepAspectRatio: true,
      })
      .image('/path/to/image2.png'), 125, 740, {
        width: 50,
        keepAspectRatio: true,
      })
      .endPage()
      .endPDF(console.log);

@AyushG3112
Copy link
Author

AyushG3112 commented Feb 18, 2020

Might be worth noting that I also ran

apk --no-cache add g++ gcc libgcc libstdc++ linux-headers make python

Inside the container, then restared my app, but to no avail.

@chunyenHuang
Copy link
Owner

Thanks for sharing. Would you like to give this a try?

galkahana/HummusJS#320 (comment)

We were able to solve this problem by including make, gcc, g++, and python in our Alpine container and running npm rebuild hummus --build-from-source.

@AyushG3112
Copy link
Author

@chunyenHuang Thanks that works!

For posterity, we had to add the following things to our Dockerfile:

RUN apk add  g++ gcc libgcc libstdc++ linux-headers make python
RUN npm install -g node-gyp 
RUN npm install
RUN npm rebuild hummus --build-from-source

@AndreHermanto
Copy link

I come across this issue, but the solution given doesn't work for me. This is my Dockerfile

FROM node:10.13.0-alpine

# Create app directory
WORKDIR /usr/src/app

COPY package*.json ./

RUN apk add  g++ gcc libgcc libstdc++ linux-headers make python
RUN npm install -g node-gyp 
RUN npm install

RUN npm rebuild hummus --build-from-source

COPY . .

EXPOSE 3000
CMD [ "npm", "start" ]

I have used "hummus-recipe": "^1.9.2" and node:10.13.0-alpine, but still got this following error in the container

internal/modules/cjs/loader.js:717
  return process.dlopen(module, path.toNamespacedPath(filename));
                 ^
Error: Error loading shared library /usr/src/app/node_modules/hummus/binding/hummus.node: Exec format error
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:717:18)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)
    at Module.require (internal/modules/cjs/loader.js:636:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (/usr/src/app/node_modules/hummus/hummus.js:5:31)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at Module.load (internal/modules/cjs/loader.js:598:32)

@AyushG3112
Copy link
Author

@AndreHermanto can you sh inside the container and verify that the node_modules/hummus directory exists in your WORKDIR?

@AndreHermanto
Copy link

@AyushG3112 I can't ssh into container as the container exited immediately. Is my Dockerfile correct?

@AyushG3112
Copy link
Author

@AndreHermanto seems fine but I've seen issues when npm install is ran from a Dockerfile. Not exactly sure what causes it though. Also, to sh into the container, replace

CMD [ "npm", "start" ]

with

CMD ["sh"]

I think that should work

@AndreHermanto
Copy link

@AyushG3112 Its the same, the container still exited immediately.

@Suroor-Ahmmad
Copy link

Any resolution for this issue? I tried all above mentioned methods and still no help

@hdiaz-nectia
Copy link

hdiaz-nectia commented Nov 23, 2020

Hi @chunyenHuang @AyushG3112
I've a similar problem, and the above solution doesn't work for me.

Dockerfile
node:12.19-alpine

console.log('New');
const pdfDoc = new HummusRecipe(filenameSrc, filenameEnc);
console.log('Encrypt');

pdfDoc
    .encrypt({
        userPassword: key,
        ownerPassword: key,
        userProtectionFlag: 4
    })
    .endPDF();

console.log('End');

The last step executed is log Encrypt an then simply it exit from docker run. Last log never is printed (and any other error) and when I go inside container with docker exec i saw that the destination file has 0 size.

@hdiaz-nectia
Copy link

Hi @chunyenHuang @AyushG3112
I've a similar problem, and the above solution doesn't work for me.

Dockerfile
node:12.19-alpine

console.log('New');
const pdfDoc = new HummusRecipe(filenameSrc, filenameEnc);
console.log('Encrypt');

pdfDoc
    .encrypt({
        userPassword: key,
        ownerPassword: key,
        userProtectionFlag: 4
    })
    .endPDF();

console.log('End');

The last step executed is log Encrypt an then simply it exit from docker run. Last log never is printed (and any other error) and when I go inside container with docker exec i saw that the destination file has 0 size.

My mistake, the correct is:

RUN npm rebuild muhammara --build-from-source

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants