sanidhya711 / text-on-gif

a simple package for writing text on animated gifs
17 stars 3 forks source link

Create a Docker File on request #21

Closed AndreZila01 closed 1 year ago

AndreZila01 commented 1 year ago

Hey everyone,

i try ran your code with requests on windows and works, try on docker of windows work too, but when i tried on linux i received a weird error of docker.

Code:

const express = require('express');
const app = express();
const TextOnGif = require('text-on-gif');

app.get('/', async (req, res) => {
  try {
    (async function () {

      //create a TextOnGif object
      var gif = new TextOnGif({
        file_path: "https://media0.giphy.com/media/Ju7l5y9osyymQ/giphy.gif"
        //path to local file, url or Buffer
      });

      //get as buffer
      var buffer = await gif.textOnGif({
        text: "text on gif sucks",
        get_as_buffer: true
      });

      console.log(buffer);

      //write as file
      await gif.textOnGif({
        text: "text on gif sucks",
        get_as_buffer: false, //set to false to save time
        write_path: "gif-with-text.gif"
      });

      res.setHeader('Content-Type', 'image/gif');
      res.send(buffer);
    })();

    // Send the GIF as a response
  } catch (error) {
    console.error('Error creating and sending GIF:', error.message);
    res.status(500).send('Error creating and sending GIF');
  }
});

const port = 3000;
app.listen(port, () => {
  console.log(`Server is running on port ${port}`);
});

Dockerfile:

# ...
FROM node:14

# ...
WORKDIR /app

# ...
COPY package*.json ./

# ...
RUN npm install

# ...
COPY . .

# ...
EXPOSE 3000

# ...
CMD ["node", "test.js"]

#...

Error message:

 => ERROR [4/5] RUN npm install                                                                                                                                          26.7s
------                                                                                                                                                                         
 > [4/5] RUN npm install:                                                                                                                                                      
#0 2.566 npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion@1, but package-lock.json was generated for lockfileVersion@3. I'll try to do my best with it!                                                                                                                                                                        
#0 7.393 npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142                                                   
#0 8.804 npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
#0 9.039 npm WARN deprecated har-validator@5.1.5: this library is no longer supported
#0 18.17 
#0 18.17 > canvas@2.11.2 install /app/node_modules/canvas
#0 18.17 > node-pre-gyp install --fallback-to-build --update-binary
#0 18.17 
#0 19.22 node-pre-gyp ERR! install response status 404 Not Found on https://github.com/Automattic/node-canvas/releases/download/v2.11.2/canvas-v2.11.2-node-v83-linux-glibc-arm.tar.gz 
#0 19.23 node-pre-gyp WARN Pre-built binaries not installable for canvas@2.11.2 and node@14.21.3 (node-v83 ABI, glibc) (falling back to source compile with node-gyp) 
#0 19.23 node-pre-gyp WARN Hit error response status 404 Not Found on https://github.com/Automattic/node-canvas/releases/download/v2.11.2/canvas-v2.11.2-node-v83-linux-glibc-arm.tar.gz 
#0 23.81 Package pangocairo was not found in the pkg-config search path.
#0 23.81 Perhaps you should add the directory containing `pangocairo.pc'
#0 23.81 to the PKG_CONFIG_PATH environment variable
#0 23.81 No package 'pangocairo' found
#0 23.81 gyp: Call to 'pkg-config pangocairo --libs' returned exit status 1 while in binding.gyp. while trying to load binding.gyp
#0 23.83 gyp ERR! configure error 
#0 23.83 gyp ERR! stack Error: `gyp` failed with exit code: 1
#0 23.83 gyp ERR! stack     at ChildProcess.onCpExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:351:16)
#0 23.83 gyp ERR! stack     at ChildProcess.emit (events.js:400:28)
#0 23.83 gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:285:12)
#0 23.83 gyp ERR! System Linux 6.1.21-v8+
#0 23.84 gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--update-binary" "--module=/app/node_modules/canvas/build/Release/canvas.node" "--module_name=canvas" "--module_path=/app/node_modules/canvas/build/Release" "--napi_version=8" "--node_abi_napi=napi" "--napi_build_version=0" "--node_napi_label=node-v83"
#0 23.84 gyp ERR! cwd /app/node_modules/canvas
#0 23.84 gyp ERR! node -v v14.21.3
#0 23.84 gyp ERR! node-gyp -v v5.1.1
#0 23.84 gyp ERR! not ok 
#0 23.85 node-pre-gyp ERR! build error 
#0 23.86 node-pre-gyp ERR! stackFailed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --update-binary --module=/app/node_modules/canvas/build/Release/canvas.node --module_name=canvas --module_path=/app/node_modules/canvas/build/Release --napi_version=8 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v83' (1)
#0 23.87  Error: Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --update-binary --module=/app/node_modules/canvas/build/Release/canvas.node --module_name=canvas --module_path=/app/node_modules/canvas/build/Release --napi_version=8 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v83' (1)
#0 23.87 node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (/app/node_modules/@mapbox/node-pre-gyp/lib/util/compile.js:89:23)
#0 23.87 node-pre-gyp ERR! stack     at ChildProcess.emit (events.js:400:28)
#0 23.87 node-pre-gyp ERR! stack     at maybeClose (internal/child_process.js:1088:16)
#0 23.87 node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:296:5)
#0 23.87 node-pre-gyp ERR! System Linux 6.1.21-v8+
#0 23.87 node-pre-gyp ERR! command "/usr/local/bin/node" "/app/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build" "--update-binary"
#0 23.87 node-pre-gyp ERR! cwd /app/node_modules/canvas
#0 23.87 node-pre-gyp ERR! node -v v14.21.3
#0 23.87 node-pre-gyp ERR! node-pre-gyp -v v1.0.11
#0 23.87 node-pre-gyp ERR! not ok 
#0 24.40 npm WARN app No description
#0 24.46 npm WARN app No repository field.
#0 24.51 npm WARN app No license field.
#0 24.51 
#0 24.62 npm ERR! code ELIFECYCLE
#0 24.62 npm ERR! errno 1
#0 24.65 npm ERR! canvas@2.11.2 install: `node-pre-gyp install --fallback-to-build --update-binary`
#0 24.65 npm ERR! Exit status 1
#0 24.65 npm ERR! 
#0 24.65 npm ERR! Failed at the canvas@2.11.2 install script.
#0 24.65 npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
#0 24.74 
#0 24.74 npm ERR! A complete log of this run can be found in:
#0 24.74 npm ERR!     /root/.npm/_logs/2023-08-14T23_17_27_062Z-debug.log
------
Dockerfile:11
--------------------
   9 |     
  10 |     # ...
  11 | >>> RUN npm install
  12 |     
  13 |     # ...
--------------------
ERROR: failed to solve: process "/bin/sh -c npm install" did not complete successfully: exit code: 1

i tried before with simple request and work, but when i insert the code of text-on-gif, he stop working ... at the moment i dont know what i need to do, to code run on docker of linux.

Thanks for support! <3

sanidhya711 commented 1 year ago

Hi, from what i can see in the logs, your system is having problems installing canvas(which is a dependency of text on gif) so i would suggest you to look at the issues of "installing canvas on linux" and instead of installing text on gif, first try installing canvas and see what the issue is. Tou probably need to do something to setup canvas installation

AndreZila01 commented 1 year ago

Ok ... Thanks @sanidhya711 ... i found the solution to install canvas. <3 Thanks https://github.com/Automattic/node-canvas/issues/1662#issuecomment-762566018