WonderInventions / node-webrtc

node-webrtc is a Node.js Native Addon that provides bindings to WebRTC M98
Other
130 stars 10 forks source link

Cannot run/not properly installed in docker image #16

Open medemi68 opened 6 months ago

medemi68 commented 6 months ago

Hi Guys,

I am creating a docker image for a project that I am working on, and the docker file gets built correctly. However, when it goes to run, it spits out an error saying that it can't find the binary. Something is not working correctly

Dockerfile:

FROM --platform=linux/amd64 node:20-bullseye

WORKDIR /root
COPY package.json /root/package.json
COPY package-lock.json /root/package-lock.json

RUN apt-get update
RUN apt install -y cmake build-essential python-is-python3 pkg-config clang gn ninja-build
RUN apt-get install ffmpeg -y

RUN npm install --location=global @nestjs/cli
RUN npm install --location=global patch-package
RUN npm install

COPY . /root/

CMD nest start

Output when run:

nestjs-1    | 
nestjs-1    | /root/node_modules/@roamhq/wrtc/lib/binding.js:24
nestjs-1    |   throw new Error(`Could not find wrtc binary on any of the paths: ${paths_to_try}`);
nestjs-1    |         ^
nestjs-1    | Error: Could not find wrtc binary on any of the paths: ../build-linux-x64/wrtc.node,../build-linux-x64/Debug/wrtc.node,../build-linux-x64/Release/wrtc.node,@roamhq/wrtc-linux-x64
nestjs-1    |     at Object.<anonymous> (/root/node_modules/@roamhq/wrtc/lib/binding.js:24:9)
nestjs-1    |     at Module._compile (node:internal/modules/cjs/loader:1358:14)
nestjs-1    |     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1416:10)
nestjs-1    |     at Module.load (node:internal/modules/cjs/loader:1208:32)
nestjs-1    |     at Function.Module._load (node:internal/modules/cjs/loader:1024:12)
nestjs-1    |     at Module.require (node:internal/modules/cjs/loader:1233:19)
nestjs-1    |     at require (node:internal/modules/helpers:179:18)
nestjs-1    |     at Object.<anonymous> (/root/node_modules/@roamhq/wrtc/lib/index.js:23:5)
nestjs-1    |     at Module._compile (node:internal/modules/cjs/loader:1358:14)
nestjs-1    |     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1416:10)

Any help would be much appreciated. I would also like to note that I have it working outside of Docker.

duvallj commented 6 months ago

What do your package.json and package-lock.json files look like? This is a known issue that I think should be fixed in the next release (sorry about that taking so long oops), just making sure nothing is out-of-the-ordinary there

kkingsbe commented 2 months ago

I am also experiencing this. Here is my package.json:

{
  "name": "test-peer",
  "version": "1.0.0",
  "description": "",
  "main": "jest.config.js",
  "scripts": {
    "build": "tsc",
    "start": "node dist/index.js",
    "dev": "ts-node src/index.ts",
    "test": "jest"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
  },
  "dependencies": {
    "@roamhq/wrtc": "^0.8.0",
    "@types/node": "^22.5.1",
    "@types/webrtc": "^0.0.43",
    "socket.io-client": "^4.7.5",
    "ts-results-es": "^4.2.0",
    "@types/jest": "^29.5.12",
    "jest": "^29.7.0",
    "ts-jest": "^29.2.5",
    "ts-node": "^10.9.2",
    "typescript": "^5.5.4"
  }
}
duvallj commented 2 months ago

@kkingsbe it looks like you have the version that includes the docker search path fix I thought would work, darn...

I'm guessing you might be building this docker image on an ARM64 host? What happens if you add an explicit dependency on @roamhq/wrtc-linux-x64. Not too experienced in figuring out why docker isn't picking up the right binary sorry

kkingsbe commented 2 months ago

I ended up finding a workaround to just not use docker for now (was trying to debug an issue relating to ICE connection discovery and wanted to see if it was due to being on the same NAT, hence the need for Docker :). Ended up just finding another way to resolve it)

DavidGOrtega commented 1 month ago

Hi, I suffered the same but the error is a bit misleading. I made the error more realistic adding a console.log in @roamhq/wrtc/lib/binding.js

let succeeded = false;
for (const path of paths_to_try) {
  try {
    console.log(path)   
    module.exports = require(path);
    console.log(module.exports, 'here')
    succeeded = true;
    break;
  } catch (error) {
    console.log(error)
  }
}

after that I saw that I had an error with a library

Error: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by /workspace/node_modules/@roamhq/wrtc-linux-x64/wrtc.node)
duvallj commented 1 month ago

Ah! Thanks for debugging that @DavidGOrtega.

As explained in https://github.com/WonderInventions/node-webrtc/issues/21#issuecomment-2334871875, I've been having trouble getting libwebrtc to use a lower GLIBC version, due to its use of a bundled compiler toolchain. For now I would recommend using a different Docker base image as the simplest path forward for anyone having trouble with this.

DavidGOrtega commented 1 month ago

as a reference node:18-bookworm-slim is apparently compatible. I need to do some tests but at least the code runs.

DavidGOrtega commented 1 month ago

Effectively node:18-bookworm-slim is working perfectly.

Moe03 commented 3 days ago

node:18-bookworm-slim

This doesn't work for me unfortunately running on apple silicon (arm) mac machine and there the package works fine but on linux/docker container also on the same machine doesn't work, any recommendations would be great

duvallj commented 3 days ago

Hi @Moe03; what's the error you're seeing? Does the patch in https://github.com/WonderInventions/node-webrtc/issues/16#issuecomment-2408188136 help clarify things any?

Moe03 commented 1 day ago

Hey @duvallj ty for your help, No I think the issue im facing is a bit different where on my dev env everything is working fine, but when I deploy to a docker container it seems to always output this error whenever it tries to connect to ice servers:

ICE Candidate Error: RTCPeerConnectionIceErrorEvent {
  type: 'icecandidateerror',
  address: '127.0.0.x',
  port: '',
  url: 'turn:relay7.expressturn.com:3478?transport=udp',
  errorCode: 701,
  errorText: 'TURN allocate request timed out.',
  target: RTCPeerConnection {
    _listeners: {},
    canTrickleIceCandidates: [Getter],
    connectionState: [Getter],
    currentLocalDescription: [Getter],
    localDescription: [Getter],
    pendingLocalDescription: [Getter],
    currentRemoteDescription: [Getter],
    remoteDescription: [Getter],
    pendingRemoteDescription: [Getter],
    signalingState: [Getter],
    sctp: [Getter],
    iceGatheringState: [Getter],
    iceConnectionState: [Getter],
    onconnectionstatechange: [Function (anonymous)],
    ondatachannel: null,
    oniceconnectionstatechange: null,
    onicegatheringstatechange: null,
AudioStreamwebrtcHandler disconnected
connection state changed: [object Object]
STOPPED WEBRTC STREAMING
    onnegotiationneeded: null,
    onsignalingstatechange: null,
    onicecandidate: [Function (anonymous)],
    onicecandidateerror: [Function (anonymous)],
    ontrack: [Function: bound handleOnTrack]
  }
}
Address: 127.0.0.x
Port: 
Error Code: 701
Error Text: TURN allocate request timed out.

While in the dev environment it's working perfectly fine without issues, I also remember deploying it before and it was working perfectly but then neither that version works now or any other docker based container.

That said I've made it work on my mac's docker by enabling these options and I tried doing the same with linux but without luck unfortunately

Screenshot 2024-11-24 at 7 43 42 PM

I think this may be related to the fact im using a proxy on top of the docker container, specfically coolify: https://coolify.io/ but i've also added in the traefic config labels to allow UDP traffic but also it seems to always output that error, have debugged a lot without success except when changing transport to tcp but that will make the transmission slower since our app is very latency intensive

DavidGOrtega commented 19 hours ago

@Moe03 my dockerfile

FROM node:18-bookworm-slim as base
RUN apt-get update && \
    apt-get install -y python3 build-essential && \
    rm -rf /var/lib/apt/lists/*

ENV MEMORY=4096
WORKDIR /workspace
COPY "./" "./"
RUN npm install
CMD node --max-old-space-size=${MEMORY} index.js

build it with

docker buildx build --platform linux/x86_64 -t whatever:v1 -f Dockerfile .