eilvelia / tdl

Node.js bindings to TDLib 🥒
MIT License
411 stars 53 forks source link

Can't build Docker container with tdl included #142

Closed vorant94 closed 1 year ago

vorant94 commented 1 year ago

Hi, there

I'm trying to make a small app in node and I need to use tdlib. I added it, locally everything works fine. Now I wanted to build a Docker container out of this app, but got an error during yarn install step. I'm not sure where to dig to fix a problem, can you please help me with it?

Here is the .Dockerfile

FROM node:18-alpine

WORKDIR /usr/local/app
ENV YARN_VERSION 3.6.1
RUN yarn policies set-version $YARN_VERSION

COPY . .
RUN yarn
RUN yarn build

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

Here is the error I receive during the build

 > [5/6] RUN yarn:
1.132 ➤ YN0000: ┌ Resolution step
1.487 ➤ YN0000: └ Completed in 0s 355ms
1.492 ➤ YN0000: ┌ Fetch step
1.565 ➤ YN0013: │ @msgpackr-extract/msgpackr-extract-linux-x64@npm:3.0.2 can't be found in the cache and will be fetched from the remote registry
2.483 ➤ YN0000: └ Completed in 0s 992ms
2.545 ➤ YN0000: ┌ Link step
18.48 ➤ YN0007: │ sofash@workspace:. must be built because it never has been before or the last one failed
18.48 ➤ YN0007: │ tdl@npm:7.3.1 must be built because it never has been before or the last one failed
18.48 ➤ YN0007: │ msgpackr-extract@npm:3.0.2 must be built because it never has been before or the last one failed
18.89 ➤ YN0009: │ tdl@npm:7.3.1 couldn't be built successfully (exit code 1, logs can be found here: /tmp/xfs-51811beb/build.log)
18.89 ➤ YN0000: └ Completed in 16s 342ms
18.95 ➤ YN0000: Failed with errors in 17s 822ms

All the source code in case you need it can be found here

eilvelia commented 1 year ago

Hi! The /tmp/xfs-51811beb/build.log log file should describe what is missing. I think the most likely cause is: tdl includes a node addon that is pre-built for glibc-based linux distributions (as noted in the README), but needs to be built from source on musl-based distributions like alpine, requiring a C++ toolchain (and python) to be installed on the system, which the image probably doesn't contain out of the box.

So, you can fix it either by moving to e.g. debian or ubuntu, for example by replacing FROM node:18-alpine with FROM node:18-bookworm (just in case, prebuit-tdlib also doesn't support alpine) or installing the build tools on alpine, something like RUN apk update && apk add gcc g++ python make should work (the dockerfile can be split into two steps to reduce the size of the final image).

Note that to run the app in the container, you also need TDLib built for the system you use there, so brew install tdlib on the host machine wouldn't be sufficient.

vorant94 commented 1 year ago

Hi! The /tmp/xfs-51811beb/build.log log file should describe what is missing. I think the most likely cause is: tdl includes a node addon that is pre-built for glibc-based linux distributions (as noted in the README), but needs to be built from source on musl-based distributions like alpine, requiring a C++ toolchain (and python) to be installed on the system, which the image probably doesn't contain out of the box.

So, you can fix it either by moving to e.g. debian or ubuntu, for example by replacing FROM node:18-alpine with FROM node:18-bookworm (just in case, prebuit-tdlib also doesn't support alpine) or installing the build tools on alpine, something like RUN apk update && apk add gcc g++ python make should work (the dockerfile can be split into two steps to reduce the size of the final image).

Note that to run the app in the container, you also need TDLib built for the system you use there, so brew install tdlib on the host machine wouldn't be sufficient.

thanks, changing base image to node:18-bookworm worked!

regarding that tdlib on host machine is not enough i am aware of it. i plan to pack it separately from the app in a container on its own, connect tdl to it and then clean up host machine, so it will be always both locally and in prod deployed via docker. but in order to move forward with actual app code I postponed this stuff. the whole docker build issue raised now only because i wanted to setup github actions to be sure i don't push broken code

thank you once more for the help, have a nice day