Fix Docker multi-stage build to include native dependencies for mediasoup runtime #33
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Context
The current
Dockerfileutilizes a two-stage build process where thebuilderstage installs all dependencies vianpm ci, includingmediasoup(v3.19.14), and generates the Nuxt output in.output/server/index.mjs. Therunnerstage copies only the.outputdirectory from the builder, excludingnode_modules.While standard JavaScript packages are bundled into the Nuxt server output,
mediasoupis a complex native module that relies on platform-specific binaries and pre-compiled addons located withinnode_modules. If the Nuxt build process does not statically bundle these native components or if the runtime environment requires access to the originalnode_modulesstructure for dynamic resolution, the production container will fail to start or crash when attempting to initialize WebRTC streaming capabilities. Additionally, differences in architecture or OS between the builder and runner stages could result in incompatible binaries if they are expected but missing.Proposed work
Modify the Dockerfile to ensure that necessary
node_modulesdependencies are available in therunnerstage alongside the Nuxt output. This involves copying thenode_modulesdirectory from thebuilderstage to the/app/node_modulespath in therunnerstage, ensuring that native modules likemediasoupare accessible at runtime.Acceptance criteria
ModuleNotFoundErroror similar runtime exceptions.runnerstage retains the non-root user execution (USER node) for security compliance.Implementation notes
Dockerfile.runnerstage copies only/app/.output. A newCOPY --from=builderinstruction is needed to transfernode_modules.nodeuser, as the builder runs as root.package.jsonlistsmediasoupas a production dependency, andREADME.mdconfirms its use for live streaming.Test plan
Dockerfile.README.md) to confirm successful connection and media handling.